fixed 0.5
This commit is contained in:
parent
15f995b6ce
commit
02d78da38f
@ -1,9 +1,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ElectronicsShopDataBaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ElectronicsShopDataBaseImplement
|
||||
{
|
||||
public class DataBase
|
||||
{
|
||||
public class Database : DbContext
|
||||
{
|
||||
@ -24,4 +23,3 @@ namespace ElectronicsShopDataBaseImplement
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,27 +8,17 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static ElectronicsShopDataBaseImplement.DataBase;
|
||||
|
||||
namespace ElectronicsShopDataBaseImplement.Implements
|
||||
{
|
||||
public class CategoryProductStorage : ICategoryProductStorage
|
||||
{
|
||||
List<CategoryProductViewModel> ICategoryProductStorage.GetFullList()
|
||||
public CategoryProductViewModel? Delete(CategoryProductBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
return context.CategoryProducts.Select(x => x.GetViewModel).ToList();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
List<CategoryProductViewModel> ICategoryProductStorage.GetFilteredList(CategoryProductSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new Database();
|
||||
return context.CategoryProducts.Where(x => x.CategoryProducts.Contains(model.Name)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
CategoryProductViewModel? ICategoryProductStorage.GetElement(CategoryProductSearchModel model)
|
||||
|
||||
public CategoryProductViewModel? GetElement(CategoryProductSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) && !model.ID.HasValue)
|
||||
{
|
||||
@ -36,9 +26,26 @@ namespace ElectronicsShopDataBaseImplement.Implements
|
||||
}
|
||||
using var context = new Database();
|
||||
return context.CategoryProducts.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.Name) && x.Name == model.Name && (model.ID.HasValue && x.Id == model.ID)) ) ?.GetViewModel;
|
||||
(!string.IsNullOrEmpty(model.Name) && x.Name == model.Name && (model.ID.HasValue && x.ID == model.ID)))?.GetViewModel;
|
||||
}
|
||||
CategoryProductViewModel? ICategoryProductStorage.Insert(CategoryProductBindingModel model)
|
||||
|
||||
public List<CategoryProductViewModel> GetFilteredList(CategoryProductSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new Database();
|
||||
return context.CategoryProducts.Where(x => x.Name.Contains(model.Name)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<CategoryProductViewModel> GetFullList()
|
||||
{
|
||||
using var context = new Database();
|
||||
return context.CategoryProducts.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public CategoryProductViewModel? Insert(CategoryProductBindingModel model)
|
||||
{
|
||||
var newComponent = CategoryProduct.Create(model);
|
||||
if (newComponent == null)
|
||||
@ -51,13 +58,10 @@ namespace ElectronicsShopDataBaseImplement.Implements
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
CategoryProductViewModel? ICategoryProductStorage.Update(CategoryProductBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
CategoryProductViewModel? ICategoryProductStorage.Delete(CategoryProductBindingModel model)
|
||||
public CategoryProductViewModel? Update(CategoryProductBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,12 +13,12 @@ namespace ElectronicsShopDataBaseImplement.Models
|
||||
{
|
||||
public class CategoryProduct : ICategoryProductModel
|
||||
{
|
||||
public int ID { get; private set; }
|
||||
public int ID { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public static CategoryProduct? Create(CategoryProductBindingModel model)
|
||||
public static CategoryProduct? Create(CategoryProductBindingModel? model)
|
||||
{
|
||||
if(model == null)
|
||||
{
|
||||
@ -30,7 +30,7 @@ namespace ElectronicsShopDataBaseImplement.Models
|
||||
Name = model.Name
|
||||
};
|
||||
}
|
||||
public static CategoryProduct Create(CategoryProductViewModel model)
|
||||
public static CategoryProduct? Create(CategoryProductViewModel model)
|
||||
{
|
||||
return new CategoryProduct
|
||||
{
|
||||
@ -48,7 +48,7 @@ namespace ElectronicsShopDataBaseImplement.Models
|
||||
model.Name = Name;
|
||||
}
|
||||
|
||||
public CategoryProduct GetViewModel => new()
|
||||
public CategoryProductViewModel GetViewModel => new()
|
||||
{
|
||||
ID = ID,
|
||||
Name = Name
|
||||
|
Loading…
Reference in New Issue
Block a user