using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson; using SushiBarDataModels.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; namespace SushiBarMongoDB.Models { public class Task : ITaskModel { [BsonId] [BsonElement("_id")] public int Id { get; set; } [BsonRequired] public DateTime TaskDate { get; set; } [BsonRequired] public SushiBarDataModels.Enum.TaskStatus Status { get; set; } [BsonRequired] public double FullPrice { get; set; } [BsonRequired] [BsonElement("place_id")] public int PlaceId { get; set; } [BsonRequired] [BsonElement("cook_id")] public int CookId { get; set; } [BsonRequired] [BsonElement("buyer_id")] public int BuyerId { get; set; } [BsonRequired] [BsonElement("menu_ids")] public List MenuIds { get; set; } = new List(); [BsonIgnoreIfNull] [BsonIgnoreIfDefault] public virtual Place Place { get; set; } [BsonIgnoreIfNull] [BsonIgnoreIfDefault] public virtual Cook Cook { get; set; } [BsonIgnoreIfNull] [BsonIgnoreIfDefault] public virtual Buyer Buyer { get; set; } [BsonIgnoreIfNull] [BsonIgnoreIfDefault] public virtual List Menus { get; set; } [BsonIgnore] public Dictionary TaskMenus { get; set; } = new Dictionary(); public static Task? Create(TaskBindingModel model) { if (model == null) return null; return new Task() { Id = model.Id, TaskDate = model.TaskDate, Status = model.Status, FullPrice = model.FullPrice, PlaceId = model.PlaceId, CookId = model.CookId, BuyerId = model.BuyerId, MenuIds = model.MenuIds, }; } public void Update(TaskBindingModel model) { if (model == null) return; Status = model.Status; } public TaskViewModel GetViewModel => new() { Id = Id, TaskDate = TaskDate, Status = Status, FullPrice = FullPrice, PlaceId = PlaceId, CookId = CookId, BuyerId = BuyerId, }; } }