обновки до дев #16

Merged
mfnefd merged 23 commits from registration into dev 2024-06-22 19:03:01 +04:00
10 changed files with 188 additions and 11 deletions
Showing only changes of commit 9ffb97cbd0 - Show all commits

View File

@ -8,6 +8,7 @@ namespace Contracts.BindingModels
{
public class SellBindingModel
{
public Guid Id { get; set; }
public DateTime DateSell { get; set; }
}
}

View File

@ -1,4 +1,6 @@
using System;
using Contracts.BindingModels;
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -10,5 +12,18 @@ namespace Contracts.ViewModels
{
public Guid Id { get; set; }
public string Location { get; set; } = string.Empty;
}
public string Name { get; set; } = string.Empty;
public Guid ProductId { get; set; }
public MediaFileBindingModel GetBindingModel()
{
return new MediaFileBindingModel
{
Id = Id,
Name = Name,
Location = Location,
ProductId = ProductId
};
}
}
}

View File

@ -12,6 +12,9 @@ namespace Contracts.ViewModels
public Guid Id { get; set; }
public string Name { get; set; } = string.Empty;
public int Price { get; set; }
public double Rating { get; set; }
public bool IsBeingSold { get; set; }
public int Amount { get; set; }
public List<MediaFileViewModel> MediaFiles { get; set; } = new();
}
}

View File

@ -11,7 +11,7 @@ namespace Contracts.ViewModels
public class PurchaseViewModel
{
public Guid Id { get; set; }
public DateTime PurchaseDate { get; set; }
public DateTime DatePurchase { get; set; }
public required IUser User { get; set; }
public required List<IProduct> Products { get; set; }
public PurchaseStatus Status { get; set; }

View File

@ -10,7 +10,7 @@ namespace Contracts.ViewModels
public class SellViewModel
{
public Guid Id { get; set; }
public DateTime SellDate { get; set; }
public DateTime DateSell { get; set; }
public ISupplyDoc? SupplyDoc { get; set; }
}
}

View File

@ -21,5 +21,9 @@ namespace DatabaseImplement
public virtual DbSet<Role> Roles { get; set; } = null!;
public virtual DbSet<User> Users { get; set; } = null!;
public virtual DbSet<Sell> Sells { get; set; } = null!;
public virtual DbSet<Purchase> Purchases { get; set; } = null!;
public virtual DbSet<Product> Products { get; set; } = null!;
public virtual DbSet<MediaFile> MediaFiles { get; set; } = null!;
}
}

View File

@ -1,4 +1,6 @@
using DataModels.Models;
using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
@ -13,10 +15,56 @@ namespace DatabaseImplement.Models
[Required]
public Guid Id { get; set; }
[Required]
public string Name { get; set; }
public string Name { get; set; } = string.Empty;
[Required]
public string Location { get; set; }
public string Location { get; set; } = string.Empty;
[Required]
public Guid ProductId { get; set; }
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;
}
}
}

View File

@ -1,4 +1,6 @@
using DataModels.Models;
using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
@ -22,5 +24,49 @@ namespace DatabaseImplement.Models
public bool IsBeingSold { get; set; }
[Required]
public int Amount { get; set; }
public ProductBindingModel GetBindingModel() => new()
{
Id = Id,
Name = Name,
Price = Price,
Rate = Rate,
IsBeingSold = IsBeingSold,
Amount = Amount
};
public static Product ToProductFromView(ProductViewModel model, Product product) => new()
{
Id = model.Id,
Name = model.Name,
Price = model.Price,
Rate = model.Rating,
IsBeingSold = model.IsBeingSold,
Amount = model.Amount
};
public static Product ToProductFromBinding(ProductBindingModel model, Product product) => new()
{
Id = model.Id,
Name = model.Name,
Price = model.Price,
Rate = model.Rate,
IsBeingSold = model.IsBeingSold,
Amount = model.Amount
};
public void Update(ProductBindingModel model, Product product)
{
if (model is null)
{
throw new ArgumentNullException("Update product: binding model is null");
}
Name = model.Name;
Price = model.Price;
Rate = model.Rate;
IsBeingSold = model.IsBeingSold;
Amount = model.Amount;
}
}
}

View File

@ -1,4 +1,6 @@
using DataModels.Enums;
using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Enums;
using DataModels.Models;
using System;
using System.Collections.Generic;
@ -16,6 +18,32 @@ namespace DatabaseImplement.Models
public DateTime DatePurchase { get; set; }
[Required]
public PurchaseStatus Status { get; private set; } = PurchaseStatus.Unknown;
public PurchaseBindingModel GetBindingModel() => new()
{
Id = Id,
DatePurchase = DatePurchase
};
public static Purchase ToPurchaseFromView(PurchaseViewModel model, Purchase purchase) => new()
{
Id = model.Id,
DatePurchase = model.DatePurchase
};
public static Purchase ToPurchaseFromBinding(PurchaseBindingModel model, Purchase purchase) => new()
{
Id = model.Id,
DatePurchase = model.DatePurchase,
};
public void Update(PurchaseBindingModel model, Purchase purchase)
{
if (model is null)
{
throw new ArgumentNullException("Update purchase: binding model is null");
}
DatePurchase = purchase.DatePurchase;
}
}
}

View File

@ -1,4 +1,7 @@
using System;
using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -6,7 +9,36 @@ using System.Threading.Tasks;
namespace DatabaseImplement.Models
{
internal class Sell
public class Sell : ISell
{
public Guid Id { get; set; }
public DateTime DateSell { get; set; }
public SellBindingModel GetBindingModel() => new()
{
Id = Id,
DateSell = DateSell
};
public static Sell ToSellFromView(SellViewModel model, Sell sell) => new()
{
Id = model.Id,
DateSell = model.DateSell
};
public static Sell ToSellFromBinding(SellBindingModel model, Sell sell) => new()
{
Id = model.Id,
DateSell = model.DateSell,
};
public void Update(SellBindingModel model, Sell sell)
{
if (model is null)
{
throw new ArgumentNullException("Update user: binding model is null");
}
DateSell = sell.DateSell;
}
}
}