124 lines
3.6 KiB
C#
124 lines
3.6 KiB
C#
using Contracts.BindingModels;
|
|
using Contracts.ViewModels;
|
|
using DataModels.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
using System.Xml.Linq;
|
|
|
|
namespace DatabaseImplement.Models
|
|
{
|
|
public class Sale : ISale
|
|
{
|
|
[Required]
|
|
public Guid Id { get; set; }
|
|
[Required]
|
|
public string Name { get; set; }
|
|
public string? Category { get; set; }
|
|
[Required]
|
|
public string Description { get; set; } = string.Empty;
|
|
[Required]
|
|
public string FullDescription { get; set; } = string.Empty;
|
|
[Required]
|
|
public int Value { get; set; }
|
|
[Required]
|
|
public DateTime Start { get; set; }
|
|
[Required]
|
|
public DateTime End { get; set; }
|
|
|
|
[ForeignKey("SaleId")]
|
|
public ICollection<Product> Products { get; set; } = new List<Product>();
|
|
public SaleBindingModel GetBindingModel() => new()
|
|
{
|
|
Id = Id,
|
|
Category = Category,
|
|
Description = Description,
|
|
FullDescription = FullDescription,
|
|
Name = Name,
|
|
Value = Value,
|
|
Start = Start,
|
|
End = End
|
|
};
|
|
|
|
public static Sale ToSaleFromView(SaleBindingModel model, Sale sale) => new()
|
|
{
|
|
Id = model.Id,
|
|
Category = model.Category,
|
|
Description = model.Description,
|
|
FullDescription = model.FullDescription,
|
|
Name = model.Name,
|
|
Value = model.Value,
|
|
Start = model.Start,
|
|
End = model.End
|
|
};
|
|
|
|
public static Sale ToProductFromBinding(SaleBindingModel model, Sale sale) => new()
|
|
{
|
|
Id = model.Id,
|
|
Category = model.Category,
|
|
Description = model.Description,
|
|
FullDescription = model.FullDescription,
|
|
Name = model.Name,
|
|
Value = model.Value,
|
|
Start = model.Start,
|
|
End = model.End
|
|
};
|
|
|
|
public static Sale Create(Database context, SaleBindingModel model)
|
|
{
|
|
return new Sale()
|
|
{
|
|
Id = model.Id,
|
|
Category = model.Category,
|
|
Description = model.Description,
|
|
FullDescription = model.FullDescription,
|
|
Name = model.Name,
|
|
Value = model.Value,
|
|
Start = model.Start,
|
|
End = model.End
|
|
};
|
|
}
|
|
|
|
|
|
public void Update(SaleBindingModel model)
|
|
{
|
|
if (model is null)
|
|
{
|
|
throw new ArgumentNullException("Update product: binding model is null");
|
|
}
|
|
|
|
Category = model.Category;
|
|
Description = model.Description;
|
|
FullDescription = model.FullDescription;
|
|
Name = model.Name;
|
|
Value = model.Value;
|
|
Start = model.Start;
|
|
End = model.End;
|
|
}
|
|
public SaleViewModel GetViewModel
|
|
{
|
|
get
|
|
{
|
|
var context = new Database();
|
|
return new()
|
|
{
|
|
Id = Id,
|
|
Category = Category,
|
|
Description = Description,
|
|
FullDescription = FullDescription,
|
|
Name = Name,
|
|
Value = Value,
|
|
Start = Start,
|
|
End = End
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|