78 lines
2.4 KiB
C#
78 lines
2.4 KiB
C#
using FacebookService.Domain.SeedWork;
|
|
|
|
namespace FacebookService.Domain.AggregatesModel.SampleAggregate;
|
|
|
|
/// <summary>
|
|
/// EN: Sample status enumeration following type-safe enum pattern.
|
|
/// VI: Enumeration trạng thái Sample theo pattern enum an toàn kiểu.
|
|
/// </summary>
|
|
public class SampleStatus : Enumeration
|
|
{
|
|
/// <summary>
|
|
/// EN: Draft status - initial state
|
|
/// VI: Trạng thái nháp - trạng thái ban đầu
|
|
/// </summary>
|
|
public static SampleStatus Draft = new(1, nameof(Draft));
|
|
|
|
/// <summary>
|
|
/// EN: Active status - ready for use
|
|
/// VI: Trạng thái hoạt động - sẵn sàng sử dụng
|
|
/// </summary>
|
|
public static SampleStatus Active = new(2, nameof(Active));
|
|
|
|
/// <summary>
|
|
/// EN: Completed status - finished processing
|
|
/// VI: Trạng thái hoàn thành - đã xử lý xong
|
|
/// </summary>
|
|
public static SampleStatus Completed = new(3, nameof(Completed));
|
|
|
|
/// <summary>
|
|
/// EN: Cancelled status - cancelled by user
|
|
/// VI: Trạng thái đã hủy - bị hủy bởi người dùng
|
|
/// </summary>
|
|
public static SampleStatus Cancelled = new(4, nameof(Cancelled));
|
|
|
|
public SampleStatus(int id, string name) : base(id, name)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// EN: Get all available statuses.
|
|
/// VI: Lấy tất cả các trạng thái có sẵn.
|
|
/// </summary>
|
|
public static IEnumerable<SampleStatus> List() => GetAll<SampleStatus>();
|
|
|
|
/// <summary>
|
|
/// EN: Parse status from name.
|
|
/// VI: Parse trạng thái từ tên.
|
|
/// </summary>
|
|
public static SampleStatus FromName(string name)
|
|
{
|
|
var status = List().SingleOrDefault(s =>
|
|
string.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase));
|
|
|
|
if (status is null)
|
|
{
|
|
throw new ArgumentException($"Possible values for SampleStatus: {string.Join(",", List().Select(s => s.Name))}");
|
|
}
|
|
|
|
return status;
|
|
}
|
|
|
|
/// <summary>
|
|
/// EN: Parse status from ID.
|
|
/// VI: Parse trạng thái từ ID.
|
|
/// </summary>
|
|
public static SampleStatus From(int id)
|
|
{
|
|
var status = List().SingleOrDefault(s => s.Id == id);
|
|
|
|
if (status is null)
|
|
{
|
|
throw new ArgumentException($"Possible values for SampleStatus: {string.Join(",", List().Select(s => s.Name))}");
|
|
}
|
|
|
|
return status;
|
|
}
|
|
}
|