2024-06-20 22:32:22 +04:00
|
|
|
|
using Contracts.BindingModels;
|
|
|
|
|
using Contracts.ViewModels;
|
|
|
|
|
using DataModels.Models;
|
2024-06-11 12:18:10 +04:00
|
|
|
|
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
|
|
|
|
|
{
|
2024-06-17 14:04:22 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public Guid Id { get; set; }
|
2024-06-11 12:18:10 +04:00
|
|
|
|
[Required]
|
2024-06-17 14:04:22 +04:00
|
|
|
|
public Guid ProductId { get; set; }
|
2024-06-25 20:26:34 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public byte[] Image { get; set; }
|
2024-06-24 15:08:29 +04:00
|
|
|
|
public virtual Product Product { get; set; }
|
2024-06-20 22:32:22 +04:00
|
|
|
|
|
2024-06-24 15:08:29 +04:00
|
|
|
|
public static MediaFile? Create(MediaFileBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new MediaFile
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
2024-06-25 20:26:34 +04:00
|
|
|
|
Image = model.Image,
|
2024-06-24 15:08:29 +04:00
|
|
|
|
ProductId = model.ProductId,
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-06-20 22:32:22 +04:00
|
|
|
|
|
2024-06-24 15:08:29 +04:00
|
|
|
|
public void Update(MediaFileBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-06-25 20:26:34 +04:00
|
|
|
|
Image = model.Image;
|
2024-06-24 15:08:29 +04:00
|
|
|
|
}
|
2024-06-20 22:32:22 +04:00
|
|
|
|
|
2024-06-24 15:08:29 +04:00
|
|
|
|
public MediaFileViewModel GetViewModel
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var context = new Database();
|
|
|
|
|
return new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
2024-06-25 20:26:34 +04:00
|
|
|
|
Image = Image,
|
2024-06-24 15:08:29 +04:00
|
|
|
|
ProductId = ProductId,
|
|
|
|
|
ProductName = context.Products.FirstOrDefault(x => x.Id == ProductId)?.Name ?? string.Empty,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-11 12:18:10 +04:00
|
|
|
|
}
|