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]
|
2024-05-24 14:23:37 +04:00
|
|
|
|
public int UsersId { get; private set; }
|
2024-05-24 12:23:50 +04:00
|
|
|
|
|
2024-05-24 14:23:37 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public int CategoryId { get; private set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public int RegionId { get; private set; }
|
2024-05-24 12:23:50 +04:00
|
|
|
|
[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 14:23:37 +04:00
|
|
|
|
public virtual Users Users { 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,
|
2024-05-24 14:23:37 +04:00
|
|
|
|
UsersId = model.UsersId,
|
|
|
|
|
RegionId = model.RegionId,
|
|
|
|
|
CategoryId = model.CategoryId,
|
2024-05-24 12:23:50 +04:00
|
|
|
|
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,
|
2024-05-24 14:23:37 +04:00
|
|
|
|
UsersId = UsersId,
|
|
|
|
|
RegionId = RegionId,
|
|
|
|
|
CategoryId = CategoryId,
|
2024-05-24 12:23:50 +04:00
|
|
|
|
Count = Count,
|
|
|
|
|
Sum = Sum,
|
|
|
|
|
Status = Status,
|
|
|
|
|
DateCreate = DateCreate,
|
|
|
|
|
DateImplement = DateImplement,
|
2024-05-24 14:23:37 +04:00
|
|
|
|
UsersName = Users.UsersName
|
2024-05-24 12:23:50 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|