using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Sacs.Web.Components; using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Utils; using Saxonite.Net.Core.Web.Base.Controllers; using Saxonite.Net.Standard.Base.App; namespace Saxonite.Web.Api.Controllers { //======================================================================= public class SwapiControllerBase : SaxController_Base { //------------------------------------------------------------------- // Definitions. //------------------------------------------------------------------- // Response data. // Null values are ignored by JSON serialisation. // - See Saxonite.Net.Core.Web.Base.App.SaxStartup.ConfigureServices() // - Ref. config.services.AddMvc(...).AddJsonOptions(options => { options.JsonSerializerOptions.IgnoreNullValues = true; }); //------------------------------------------------------------------- // Base response data - for simple responses. public class ApiResponse_Base { // Response status. public bool? Success { get; set; } = null; public bool? Error { get; set; } = null; public bool? SessionExpired { get; protected set; } = null; public ApiResponse_Base SetSessionExpired(String title, String text) { SessionExpired = true; return SetMessage(title, text); } // Message - displays alert popup. public class MessageData { public MessageData(String title, String text) { this.Title = title; this.Text = text; } public String Title { get; } public String Text { get; } } public MessageData? Message { get; private set; } public ApiResponse_Base SetMessage(String title, String text) { if (!StringUtil.IsBlank(text)) Message = new MessageData(title, text); return this; } } //------------------------------------------------------------------- public class ApiResponse_Data : ApiResponse_Base { //--------------------------------------------------------------- // Construction. protected ApiResponse_Data() { } //--------------------------------------------------------------- /// Item data - Common properties for data items. public class ItemData_Base { // Common item properties. public String? Id { get; set; } public String? Notes { get; set; } public String? StatusCode { get; set; } public String? StatusDesc { get; set; } // Flags for common status values. // Return true or null so that property is not serialised when false. public bool? Awaiting { get { return StatusCode.EqualsCI(SacsSystem.GetStatusCode(SaStatus.Awaiting)) ? true : (bool?)null; } } public bool? Active { get { return StatusCode.EqualsCI(SacsSystem.GetStatusCode(SaStatus.Active)) ? true : (bool?)null; } } public bool? Inactive { get { return StatusCode.EqualsCI(SacsSystem.GetStatusCode(SaStatus.Inactive)) ? true : (bool?)null; } } public bool? Deleted { get { return StatusCode.EqualsCI(SacsSystem.GetStatusCode(SaStatus.Deleted)) ? true : (bool?)null; } } /// Created on date - YYYYMMDD public String? CreatedOn { get; set; } /// Created on date - formatted per locale public String? CreatedOnFmt { get; set; } /// Updated on date - YYYYMMDD public String? UpdatedOn { get; set; } /// Updated on date - formatted per locale public String? UpdatedOnFmt { get; set; } } /// Contact Method properties. public class ContactMethodData { public String? Method { get; set; } public String? MethodCaption { get; set; } public String? Value { get; set; } } /// Address properties. public class AddressData : ItemData_Base { public String? Line1 { get; set; } public String? Line2 { get; set; } public String? Line3 { get; set; } public String? Town { get; set; } public String? RegionIdProvince { get; set; } public String? RegionNameProvince { get; set; } public String? RegionIdCountry { get; set; } public String? RegionNameCountry { get; set; } public String? PostalCode { get; set; } } /// /// Item data with label and value. /// public class ItemLabelValue { public String? Label { get; set; } public String? Value { get; set; } } /// /// Item data with just Id and name. /// - Id is String to allow for obfuscated values. /// public class ItemIdName { public String? Id { get; set; } public String? Name { get; set; } } /// Item code and desc values. public class ItemCodeDesc { public String? Code { get; set; } public String? Desc { get; set; } } } //------------------------------------------------------------------- // Construction. protected SwapiControllerBase() : base(null) { } //------------------------------------------------------------------- } //======================================================================= }