This commit is contained in:
Zeeshaun
2026-03-17 09:53:09 -05:00
parent cdcba54aa4
commit 1a0702a79a
590 changed files with 62058 additions and 0 deletions
@@ -0,0 +1,42 @@
#nullable enable
using System;
using System.Collections.Generic;
using LCU.Library.Internal.IncentiveApiModels.Enums;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace LCU.Library.Internal.IncentiveApiModels.Common
{
public class ActivityFilter: PageFilter
{
[FromQuery(Name = "state")]
public List<ActivityState>? State { get; set; }
[FromQuery(Name = "query")]
public string? Query { get; set; }
[FromQuery(Name = "product")]
public List<Product>? Product { get; set; }
[FromQuery(Name = "type")]
public List<ActivityType>? Type { get; set; }
[FromQuery(Name = "dateLow")]
public DateTime? DateLow { get; set; }
[FromQuery(Name = "dateHigh")]
public DateTime? DateHigh { get; set; }
[FromQuery(Name = "departmentId")]
public int DepartmentId { get; set; }
[FromQuery(Name = "employeeId")]
public string? EmployeeId { get; set; }
public override object Clone()
{
var jsonString = JsonConvert.SerializeObject(this);
return JsonConvert.DeserializeObject(jsonString, this.GetType());
}
}
}
@@ -0,0 +1,16 @@
using System;
using LCU.Library.Internal.IncentiveApiModels.Enums;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace LCU.Library.Internal.IncentiveApiModels.Common
{
public abstract class AuditCreate
{
public string CreatedBy { get; set; }
public Guid CreatedByAppUserId { get; set; }
public DateTime Created { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public UserType CreatedByType { get; set; }
}
}
@@ -0,0 +1,17 @@
using System;
using LCU.Library.Internal.IncentiveApiModels.Enums;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace LCU.Library.Internal.IncentiveApiModels.Common
{
public abstract class Auditable : AuditCreate
{
public string LastUpdatedBy { get; set; }
public Guid LastUpdatedByAppUserId { get; set; }
public DateTime LastUpdated { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public UserType LastUpdatedByType { get; set; }
}
}
@@ -0,0 +1,6 @@
namespace LCU.Library.Internal.IncentiveApiModels.Common
{
public class DeadActivityFilter: ActivityFilter
{
}
}
@@ -0,0 +1,7 @@
namespace LCU.Library.Internal.IncentiveApiModels.Common
{
public interface IViewTransformable<T>
{
public T TransformForView();
}
}
@@ -0,0 +1,68 @@
using System;
namespace LCU.Library.Internal.IncentiveApiModels.Common
{
public sealed class MonthRange
{
public int FromMonth { get; }
public int FromYear { get; }
public int ToMonth { get; }
public int ToYear { get; }
public MonthRange()
{
var today = DateTime.Today;
FromMonth = today.Month;
ToMonth = today.Month;
FromYear = today.Year;
ToYear = today.Year;
}
public MonthRange(DateTime period)
{
FromMonth = period.Month;
ToMonth = period.Month;
FromYear = period.Year;
ToYear = period.Year;
}
public MonthRange(DateTime fromPeriod, DateTime toPeriod)
{
FromMonth = fromPeriod.Month;
ToMonth = toPeriod.Month;
FromYear = fromPeriod.Year;
ToYear = toPeriod.Year;
}
public MonthRange(int year, int month)
{
if (year < 1900 || month > 12)
{
throw new Exception("First Argument is Year, not month");
}
FromMonth = month;
ToMonth = month;
FromYear = year;
ToYear = year;
}
public MonthRange(int fromYear, int fromMonth, int toYear, int toMonth)
{
if (fromYear < 1900 || fromMonth > 12 || toYear < 1900 || toMonth > 12)
{
throw new Exception("Year arguments are first, they are likely swapped.");
}
FromMonth = fromMonth;
ToMonth = toMonth;
FromYear = fromYear;
ToYear = toYear;
}
public bool IsSingleMonth => FromMonth == ToMonth && FromYear == ToYear;
public DateTime StartTime => new DateTime(FromYear, FromMonth, 1);
public DateTime EndTime => new DateTime(ToYear, ToMonth, 1).AddMonths(1).AddSeconds(-1);
public bool ValidFromRange => FromMonth != 0 && FromYear != 0;
public bool ValidToRange => ToMonth != 0 && ToYear != 0;
}
}
@@ -0,0 +1,32 @@
using System;
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;
namespace LCU.Library.Internal.IncentiveApiModels.Common
{
public class PageFilter : ICloneable
{
[Range(1, 1000)]
public int Page { get; set; }
[Range(1, 1000)]
public int Limit { get; set; }
public string? SortBy { get; set; }
public bool? SortDescending { get; set; }
public PageFilter()
{
this.Page = 1;
this.Limit = 100;
this.SortDescending = false;
}
public virtual object Clone()
{
var jsonString = JsonConvert.SerializeObject(this);
return JsonConvert.DeserializeObject(jsonString, this.GetType());
}
}
}
@@ -0,0 +1,41 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
namespace LCU.Library.Internal.IncentiveApiModels.Common
{
public class PagedResponse<T> where T : class
{
public PagedResponse() { }
public PagedResponse(PagedResult<T> pagedResult, PageFilter filter, IUrlHelper url, HttpRequest request, string uriAction = "Get")
{
TotalItems = pagedResult.Total;
Items = pagedResult.Items;
CurrentPage = filter.Page;
TotalPages = pagedResult.Total == 0 ? 1 : (int) Math.Ceiling((decimal) pagedResult.Total / filter.Limit);
PageFilter newFilter = filter.Clone() as PageFilter;
if (pagedResult.Total > (filter.Page * filter.Limit))
{
newFilter.Page = filter.Page + 1;
NextPage = new Uri(url.Action(uriAction, null, newFilter, request.Scheme));
}
if (filter.Page > 1)
{
newFilter.Page = filter.Page - 1;
PreviousPage = new Uri(url.Action(uriAction, null, newFilter, request.Scheme));
}
}
public IEnumerable<T> Items { get; set; }
public Uri NextPage { get; set; }
public Uri PreviousPage { get; set; }
public int TotalItems { get; set; }
public int CurrentPage { get; set; }
public int TotalPages { get; set; }
}
}
@@ -0,0 +1,10 @@
using System.Collections.Generic;
namespace LCU.Library.Internal.IncentiveApiModels.Common
{
public class PagedResult<T> where T : class
{
public IEnumerable<T> Items { get; set; }
public int Total { get; set; }
}
}
@@ -0,0 +1,9 @@
namespace LCU.Library.Internal.IncentiveApiModels.Common
{
public class PropertyValueVariance
{
public string ComparedProperty { get; set; }
public string PropertyValueOne { get; set; }
public string PropertyValueTwo { get; set; }
}
}
@@ -0,0 +1,32 @@
using LCU.Library.Internal.IncentiveApiModels.Entities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Linq;
namespace LCU.Library.Internal.IncentiveApiModels.Common
{
public class RoleConverter : JsonConverter
{
public override bool CanWrite => false;
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
public override bool CanRead => base.CanRead;
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var roleName = (string)JObject.Load(reader)["name"];
var role = Role.GetRolesList().FirstOrDefault(role => role.Name.Equals(roleName));
return role;
}
public override bool CanConvert(Type objectType)
{
return objectType == typeof(Role);
}
}
}
@@ -0,0 +1,9 @@
using System;
namespace LCU.Library.Internal.IncentiveApiModels.Common
{
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public sealed class UpdateAllowed : Attribute
{
}
}