roadie/Roadie.Api.Library/Models/EntityModelBase.cs

105 lines
2.7 KiB
C#
Raw Normal View History

2018-11-02 21:04:49 +00:00
using Mapster;
using Newtonsoft.Json;
2018-12-12 23:23:50 +00:00
using Roadie.Library.Enums;
using Roadie.Library.Utility;
2018-11-02 21:04:49 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
2019-06-23 15:45:45 +00:00
using System.Linq;
2018-11-02 21:04:49 +00:00
using System.Runtime.Serialization;
2018-11-06 02:41:51 +00:00
namespace Roadie.Library.Models
2018-11-02 21:04:49 +00:00
{
public abstract class EntityModelBase
{
2019-07-03 16:21:29 +00:00
private IEnumerable<string> _alternateNamesList;
private IEnumerable<string> _tagsList;
private IEnumerable<string> _urlsList;
2018-11-02 21:04:49 +00:00
[MaxLength(65535)]
[JsonIgnore]
[IgnoreDataMember]
public string AlternateNames { get; set; }
public IEnumerable<string> AlternateNamesList
{
get
{
2019-07-03 16:21:29 +00:00
if (_alternateNamesList == null)
if (!string.IsNullOrEmpty(AlternateNames))
_alternateNamesList = AlternateNames.Split('|');
return _alternateNamesList ?? Enumerable.Empty<string>();
2018-11-02 21:04:49 +00:00
}
2019-07-03 16:21:29 +00:00
set => _alternateNamesList = value;
2018-11-02 21:04:49 +00:00
}
public DateTime? BeginDate { get; set; }
2019-07-03 16:21:29 +00:00
[Required] public virtual DateTime? CreatedDate { get; set; }
2018-11-02 21:04:49 +00:00
public DateTime? EndDate { get; set; }
2019-07-03 16:21:29 +00:00
[AdaptMember("RoadieId")] public virtual Guid? Id { get; set; }
2018-11-02 21:04:49 +00:00
public bool? IsLocked { get; set; }
2019-07-03 16:21:29 +00:00
2018-11-06 02:41:51 +00:00
public DateTime? LastUpdated { get; set; }
2018-11-02 21:04:49 +00:00
2019-07-03 16:21:29 +00:00
[MaxLength(250)] public string SortName { get; set; }
2018-11-02 21:04:49 +00:00
public int? Status { get; set; }
2019-07-03 16:21:29 +00:00
public string StatusVerbose => SafeParser.ToEnum<Statuses>(Status).ToString();
2018-12-12 23:23:50 +00:00
2018-11-02 21:04:49 +00:00
[MaxLength(65535)]
[JsonIgnore]
[IgnoreDataMember]
public string Tags { get; set; }
public IEnumerable<string> TagsList
{
get
{
2019-07-03 16:21:29 +00:00
if (_tagsList == null)
2018-11-02 21:04:49 +00:00
{
2019-07-03 16:21:29 +00:00
if (string.IsNullOrEmpty(Tags)) return null;
return Tags.Split('|');
2018-11-02 21:04:49 +00:00
}
2019-07-03 16:21:29 +00:00
return _tagsList;
2018-11-02 21:04:49 +00:00
}
2019-07-03 16:21:29 +00:00
set => _tagsList = value;
2018-11-02 21:04:49 +00:00
}
[MaxLength(65535)]
[JsonIgnore]
[IgnoreDataMember]
public string URLs { get; set; }
public IEnumerable<string> URLsList
{
get
{
2019-07-03 16:21:29 +00:00
if (_urlsList == null)
2018-11-02 21:04:49 +00:00
{
2019-07-03 16:21:29 +00:00
if (string.IsNullOrEmpty(URLs)) return null;
return URLs.Split('|');
2018-11-02 21:04:49 +00:00
}
2019-07-03 16:21:29 +00:00
return _urlsList;
2018-11-02 21:04:49 +00:00
}
2019-07-03 16:21:29 +00:00
set => _urlsList = value;
2018-11-02 21:04:49 +00:00
}
2019-08-02 20:59:24 +00:00
public bool? UserBookmarked { get; set; }
2018-11-14 03:19:28 +00:00
2018-11-02 21:04:49 +00:00
public EntityModelBase()
{
2019-07-03 16:21:29 +00:00
Id = Guid.NewGuid();
CreatedDate = DateTime.UtcNow;
Status = 0;
2018-11-02 21:04:49 +00:00
}
}
}