using Contracts.BindingModels; using Contracts.ViewModels; using DataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DatabaseImplement.Models { public class MediaFile : IMediaFile { [Required] public Guid Id { get; set; } [Required] public string Name { get; set; } = string.Empty; [Required] public string Location { get; set; } = string.Empty; [Required] public Guid ProductId { get; set; } public virtual Product Product { get; set; } public static MediaFile? Create(MediaFileBindingModel? model) { if (model == null) { return null; } return new MediaFile { Id = model.Id, Name = model.Name, Location = model.Location, ProductId = model.ProductId, }; } public void Update(MediaFileBindingModel? model) { if (model == null) { return; } Location = model.Location; Name = model.Name; } public MediaFileViewModel GetViewModel { get { var context = new Database(); return new() { Id = Id, Name = Name, Location = Location, ProductId = ProductId, ProductName = context.Products.FirstOrDefault(x => x.Id == ProductId)?.Name ?? string.Empty, }; } } } }