93 lines
3.4 KiB
C#
93 lines
3.4 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using Sarand.Net.Standard.Proc.Excel;
|
|
using Saxonite.Base.App;
|
|
using Saxonite.Net.Core.Web.Base.App;
|
|
using Saxonite.Net.Core.Web.Base.Controllers;
|
|
using Saxonite.Net.Core.Web.Base.Models;
|
|
using Saxonite.Net.Standard.Base.App;
|
|
using Saxonite.Net.Standard.Base.Bus;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Saxonite.Net.Core.Web.Admin.Models
|
|
{
|
|
//=======================================================================
|
|
/// <summary>
|
|
/// Model for Organisation Upload.
|
|
/// </summary>
|
|
public class Model_OrganisationUpload : SaxModel_Admin
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public Model_OrganisationUpload(SaxLocaliser localiser) :
|
|
base(localiser)
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Organisation data files - only one allowed per request.
|
|
public List<IFormFile> OrganisationDataFile { get; set; }
|
|
// Data file properties.
|
|
public String SheetNameOrNumber { get; set; } = "1";
|
|
public String HeaderRow { get; set; } = "1";
|
|
public String FirstDataRow { get; set; } = "2";
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validation.
|
|
//-------------------------------------------------------------------
|
|
public bool ValidateProperties(SaxController_Base.AjaxResponse_Data responseData)
|
|
{
|
|
|
|
// Data file.
|
|
{
|
|
String controlName = nameof(OrganisationDataFile);
|
|
// A single data file must be supplied.
|
|
if (OrganisationDataFile == null || !OrganisationDataFile.Any())
|
|
responseData.SetControlError(controlName, Localiser["msg.error.data.file.missing"]);
|
|
else if (OrganisationDataFile != null && OrganisationDataFile.Count() > 1)
|
|
responseData.SetControlError(controlName, Localiser["msg.error.data.file.multiple"]);
|
|
}
|
|
|
|
// Sheet name or number.
|
|
{
|
|
String controlName = nameof(SheetNameOrNumber);
|
|
if (StringUtil.IsBlank(SheetNameOrNumber))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
|
else if (!ExcelHelper.IsValidSheetName(SheetNameOrNumber))
|
|
responseData.SetControlError(controlName, Localiser["msg.error.sheet.name.invalid"]);
|
|
}
|
|
|
|
// Header row position (from 1).
|
|
{
|
|
String controlName = nameof(HeaderRow);
|
|
if (StringUtil.IsBlank(HeaderRow))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
|
else if (!StringUtil.IsNumeric(HeaderRow) || StringUtil.ToInt(HeaderRow) < 1)
|
|
responseData.SetControlError(controlName, Localiser["msg.error.spreadsheet.row.invalid"]);
|
|
}
|
|
|
|
// First data row position (from 1).
|
|
{
|
|
String controlName = nameof(FirstDataRow);
|
|
if (StringUtil.IsBlank(FirstDataRow))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
|
else if (!StringUtil.IsNumeric(FirstDataRow) || StringUtil.ToInt(FirstDataRow) < 1)
|
|
responseData.SetControlError(controlName, Localiser["msg.error.spreadsheet.row.invalid"]);
|
|
}
|
|
|
|
return !responseData.HasControlErrors();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|