SUBD_Gerimovich_Ilya_PIbd-22/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Ad.cs

80 lines
2.0 KiB
C#
Raw Normal View History

2024-05-24 12:23:50 +04:00
using FurnitureAssemblyContracts.BindingModels;
using FurnitureAssemblyContracts.ViewModels;
using FurnitureAssemblyDataModels.Enums;
using FurnitureAssemblyDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureAssemblyDatabaseImplement.Models
{
2024-05-24 13:05:47 +04:00
public class Ad : IAdModel
2024-05-24 12:23:50 +04:00
{
public int Id { get; private set; }
[Required]
public int FurnitureId { get; private set; }
[Required]
public int Count { get; private set; }
[Required]
public double Sum { get; private set; }
[Required]
2024-05-24 13:05:47 +04:00
public AdStatus Status { get; private set; } = AdStatus.Неизвестен;
2024-05-24 12:23:50 +04:00
[Required]
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
2024-05-24 13:05:47 +04:00
public virtual Users Furniture { get; set; }
2024-05-24 12:23:50 +04:00
2024-05-24 13:05:47 +04:00
public static Ad? Create(AdBindingModel model)
2024-05-24 12:23:50 +04:00
{
if (model == null)
{
return null;
}
2024-05-24 13:05:47 +04:00
return new Ad()
2024-05-24 12:23:50 +04:00
{
Id = model.Id,
FurnitureId = model.FurnitureId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
};
}
2024-05-24 13:05:47 +04:00
public void Update(AdBindingModel model)
2024-05-24 12:23:50 +04:00
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
2024-05-24 13:05:47 +04:00
public AdViewModel GetViewModel => new()
2024-05-24 12:23:50 +04:00
{
Id = Id,
FurnitureId = FurnitureId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
2024-05-24 13:05:47 +04:00
UsersName = Furniture.UsersName
2024-05-24 12:23:50 +04:00
};
}
}