PIAPS_CW/DatabaseImplement/Models/MediaFile.cs

71 lines
1.5 KiB
C#
Raw Permalink Normal View History

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
{
[Required]
public Guid Id { get; set; }
2024-06-11 12:18:10 +04:00
[Required]
2024-06-20 22:32:22 +04:00
public string Name { get; set; } = string.Empty;
2024-06-11 12:18:10 +04:00
[Required]
2024-06-20 22:32:22 +04:00
public string Location { get; set; } = string.Empty;
[Required]
public Guid ProductId { get; set; }
2024-06-20 22:32:22 +04:00
public MediaFileBindingModel GetBindingModel()
{
return new MediaFileBindingModel
{
Id = Id,
Name = Name,
Location = Location,
ProductId = ProductId
};
}
public static MediaFile ToMediaFileFromView(MediaFileViewModel model, MediaFile mediaFile)
{
return new MediaFile
{
Id = model.Id,
Name = model.Name,
Location = model.Location,
ProductId = model.ProductId
};
}
public static MediaFile ToMediaFileFromBinding(MediaFileBindingModel model, MediaFile mediaFile)
{
return new MediaFile
{
Id = model.Id,
Name = model.Name,
Location = model.Location,
ProductId = model.ProductId
};
}
public void Update(MediaFileBindingModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
// Обновление свойств на основе модели привязки
Name = model.Name;
Location = model.Location;
ProductId = model.ProductId;
}
2024-06-11 12:18:10 +04:00
}
}