237 lines
8.3 KiB
C#
237 lines
8.3 KiB
C#
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using NPOI.SS.Formula.Functions;
|
|
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 Saxonite.Base.App;
|
|
using Saxonite.Net.Core.Web.Base.App;
|
|
using Saxonite.Net.Core.Web.Base.Controllers;
|
|
using Saxonite.Net.Standard.Base.Bus;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Saxonite.Net.Core.Web.Online.Models
|
|
{
|
|
//=======================================================================
|
|
public class Model_Organisation_Events : SaxModel_Online
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Definitions.
|
|
public enum PeriodType
|
|
{
|
|
FromThisWeek,
|
|
FromThisMonth,
|
|
FromLastMonth,
|
|
FromNextMonth,
|
|
Past,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public Model_Organisation_Events(SaxLocaliser localiser) :
|
|
base(localiser)
|
|
{
|
|
AdditionalFiles_CSS.Add("css/sax-org-evt.css");
|
|
AdditionalFiles_JS.Add("js/sax-org-evt.js");
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// List configuration.
|
|
public class EventFilterData
|
|
{
|
|
public String OrganisationId { get; set; }
|
|
public String OrganisationCaption { get; set; }
|
|
public class PeriodData
|
|
{
|
|
public String Type { get; set; }
|
|
public PeriodType PeriodType { get { return EnumUtil.ParseEnum(Type, PeriodType.FromThisWeek); } }
|
|
public String FromDate { get; set; }
|
|
public String ToDate { get; set; }
|
|
}
|
|
public PeriodData Period { get; } = new PeriodData();
|
|
public String Event { get; set; }
|
|
}
|
|
public EventFilterData Filter { get; } = new EventFilterData();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Event properties.
|
|
public String EventId { get; set; }
|
|
public String EventExists { get; set; }
|
|
// Event properties.
|
|
public String EventOrganisationId { get; set; }
|
|
// Sport.
|
|
public String EventSportIdPrimary { get; set; }
|
|
// Region.
|
|
public String EventRegionIdCountry { get; set; }
|
|
// Event Content.
|
|
public String EventAtDate { get; set; }
|
|
public bool EventAtTimeSet { get; set; }
|
|
public String EventAtTime { get; set; }
|
|
public String EventDuration { get; set; }
|
|
public String EventDurationType { get; set; }
|
|
public String EventToDate { get; set; }
|
|
public bool EventToDateSet { get; set; }
|
|
public String EventToTime { get; set; }
|
|
public bool EventToTimeSet { get; set; }
|
|
public String EventTypeCode { get; set; }
|
|
public String EventSummary { get; set; }
|
|
public String EventDetails { get; set; }
|
|
public String EventStatusCode { get; set; }
|
|
public SaStatus EventStatus { get { return SacsSystem.GetStatusForCode(EventStatusCode); } }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Period types.
|
|
public IEnumerable<SelectListItem> EventPeriodTypesForDropdown
|
|
{
|
|
get
|
|
{
|
|
List<SelectListItem> values = new List<SelectListItem>();
|
|
values.Add(new SelectListItem("From this week", PeriodType.FromThisWeek.ToString(), true));
|
|
values.Add(new SelectListItem("From this month", PeriodType.FromThisMonth.ToString()));
|
|
values.Add(new SelectListItem("From last month", PeriodType.FromLastMonth.ToString()));
|
|
values.Add(new SelectListItem("From next month", PeriodType.FromNextMonth.ToString()));
|
|
return values;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validation.
|
|
//-------------------------------------------------------------------
|
|
// Event.
|
|
public bool ValidateEventData(SaxController_Base.AjaxResponse_Data responseData)
|
|
{
|
|
// Event type.
|
|
if (EventTypeCode != null)
|
|
{
|
|
String controlName = nameof(EventTypeCode);
|
|
if (StringUtil.IsEmpty(EventTypeCode))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
|
}
|
|
|
|
// Event At date.
|
|
if (EventAtDate != null)
|
|
{
|
|
String controlName = nameof(EventAtDate);
|
|
DateTime eventOn = ParseDateFromForm(EventAtDate);
|
|
if (!DateUtil.IsValid(eventOn))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
|
}
|
|
|
|
// Event At Time Set flag.
|
|
if (EventAtTimeSet)
|
|
{
|
|
String controlName = nameof(EventAtTime);
|
|
if (StringUtil.IsBlank(EventAtTime))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
|
}
|
|
|
|
// Event At time.
|
|
if (EventAtTime != null && EventAtTimeSet)
|
|
{
|
|
String controlName = nameof(EventAtTime);
|
|
DateTime eventAt = DateUtil.ParseExact(EventAtTime, "HH:mm");
|
|
if (StringUtil.IsBlank(EventAtTime))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
|
else if (!DateUtil.IsValid(eventAt))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
|
}
|
|
|
|
// Event duration.
|
|
if (EventDuration != null)
|
|
{
|
|
String controlName = nameof(EventDuration);
|
|
}
|
|
|
|
// Event duration type.
|
|
if (EventDurationType != null)
|
|
{
|
|
String controlName = nameof(EventDurationType);
|
|
}
|
|
|
|
// Event To date.
|
|
if (EventToDate != null && EventToDateSet)
|
|
{
|
|
String controlName = nameof(EventToDate);
|
|
DateTime eventOn = ParseDateFromForm(EventToDate);
|
|
if (!DateUtil.IsValid(eventOn))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
|
}
|
|
|
|
// Event To Time Set flag.
|
|
if (EventToTimeSet)
|
|
{
|
|
String controlName = nameof(EventToTime);
|
|
if (StringUtil.IsBlank(EventToTime))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
|
}
|
|
|
|
// Event To time.
|
|
if (EventToTime != null && EventToTimeSet)
|
|
{
|
|
String controlName = nameof(EventToTime);
|
|
DateTime eventTo = DateUtil.ParseExact(EventToTime, "HH:mm");
|
|
if (StringUtil.IsBlank(EventToTime))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
|
else if (!DateUtil.IsValid(eventTo))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
|
}
|
|
|
|
// Event summary.
|
|
if (EventSummary != null)
|
|
{
|
|
String controlName = nameof(EventSummary);
|
|
responseData.SetControlValue(controlName, EventSummary);
|
|
if (StringUtil.IsEmpty(EventSummary))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
|
else if (StringUtil.GetLength(EventSummary) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Summary))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Summary)]);
|
|
}
|
|
|
|
// Event details.
|
|
if (EventDetails != null)
|
|
{
|
|
String controlName = nameof(EventDetails);
|
|
responseData.SetControlValue(controlName, EventDetails);
|
|
if (StringUtil.GetLength(EventDetails) > GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Details))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.maximum.length", GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Details)]);
|
|
}
|
|
|
|
// Event sport.
|
|
if (EventSportIdPrimary != null)
|
|
{
|
|
String controlName = "EventSportPrimary";
|
|
SysId articleSportId = ExtractSysId(EventSportIdPrimary);
|
|
if (!SysId.IsValid(articleSportId))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
|
}
|
|
|
|
// Event region.
|
|
if (EventRegionIdCountry != null)
|
|
{
|
|
String controlName = "EventRegionCountry";
|
|
SysId articleRegionId = ExtractSysId(EventRegionIdCountry);
|
|
if (!SysId.IsValid(articleRegionId))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
|
}
|
|
|
|
// Event status.
|
|
if (EventStatusCode != null)
|
|
{
|
|
String controlName = nameof(EventStatus);
|
|
if (StringUtil.IsEmpty(EventStatusCode))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.mandatory.value"]);
|
|
else if (!SaxOrganisationEvent.ValidStatuses.Contains(EventStatus))
|
|
responseData.SetControlError(controlName, Localiser["msg.validation.invalid.value"]);
|
|
}
|
|
|
|
return !responseData.HasControlErrors();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|