fixed 0.5
This commit is contained in:
parent
15f995b6ce
commit
02d78da38f
@ -1,27 +1,25 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using ElectronicsShopDataBaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace ElectronicsShopDataBaseImplement
|
namespace ElectronicsShopDataBaseImplement
|
||||||
{
|
{
|
||||||
public class DataBase
|
public class Database : DbContext
|
||||||
{
|
{
|
||||||
public class Database : DbContext
|
protected override void OnConfiguring(DbContextOptionsBuilder
|
||||||
|
optionsBuilder)
|
||||||
{
|
{
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder
|
if (optionsBuilder.IsConfigured == false)
|
||||||
optionsBuilder)
|
|
||||||
{
|
{
|
||||||
if (optionsBuilder.IsConfigured == false)
|
optionsBuilder.UseSqlServer(@"Data Source=.\SQLEXPRESS;Initial Catalog=ZooDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||||
{
|
|
||||||
optionsBuilder.UseSqlServer(@"Data Source=.\SQLEXPRESS;Initial Catalog=ZooDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
|
||||||
}
|
|
||||||
base.OnConfiguring(optionsBuilder);
|
|
||||||
}
|
}
|
||||||
public virtual DbSet<CategoryProduct> CategoryProducts { set; get; }
|
base.OnConfiguring(optionsBuilder);
|
||||||
public virtual DbSet<User> Users { set; get; }
|
|
||||||
public virtual DbSet<Route> Routes { set; get; }
|
|
||||||
public virtual DbSet<RoutePreserve> RoutePreserves { set; get; }
|
|
||||||
public virtual DbSet<Preserve> Preserves { set; get; }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public virtual DbSet<CategoryProduct> CategoryProducts { set; get; }
|
||||||
|
public virtual DbSet<User> Users { set; get; }
|
||||||
|
public virtual DbSet<Route> Routes { set; get; }
|
||||||
|
public virtual DbSet<RoutePreserve> RoutePreserves { set; get; }
|
||||||
|
public virtual DbSet<Preserve> Preserves { set; get; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,27 +8,17 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using static ElectronicsShopDataBaseImplement.DataBase;
|
|
||||||
|
|
||||||
namespace ElectronicsShopDataBaseImplement.Implements
|
namespace ElectronicsShopDataBaseImplement.Implements
|
||||||
{
|
{
|
||||||
public class CategoryProductStorage : ICategoryProductStorage
|
public class CategoryProductStorage : ICategoryProductStorage
|
||||||
{
|
{
|
||||||
List<CategoryProductViewModel> ICategoryProductStorage.GetFullList()
|
public CategoryProductViewModel? Delete(CategoryProductBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new Database();
|
throw new NotImplementedException();
|
||||||
return context.CategoryProducts.Select(x => x.GetViewModel).ToList();
|
|
||||||
}
|
}
|
||||||
List<CategoryProductViewModel> ICategoryProductStorage.GetFilteredList(CategoryProductSearchModel model)
|
|
||||||
{
|
public CategoryProductViewModel? GetElement(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)
|
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(model.Name) && !model.ID.HasValue)
|
if (string.IsNullOrEmpty(model.Name) && !model.ID.HasValue)
|
||||||
{
|
{
|
||||||
@ -36,9 +26,26 @@ namespace ElectronicsShopDataBaseImplement.Implements
|
|||||||
}
|
}
|
||||||
using var context = new Database();
|
using var context = new Database();
|
||||||
return context.CategoryProducts.FirstOrDefault(x =>
|
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);
|
var newComponent = CategoryProduct.Create(model);
|
||||||
if (newComponent == null)
|
if (newComponent == null)
|
||||||
@ -51,13 +58,10 @@ namespace ElectronicsShopDataBaseImplement.Implements
|
|||||||
return newComponent.GetViewModel;
|
return newComponent.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
CategoryProductViewModel? ICategoryProductStorage.Update(CategoryProductBindingModel model)
|
public CategoryProductViewModel? Update(CategoryProductBindingModel model)
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
CategoryProductViewModel? ICategoryProductStorage.Delete(CategoryProductBindingModel model)
|
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,12 +13,12 @@ namespace ElectronicsShopDataBaseImplement.Models
|
|||||||
{
|
{
|
||||||
public class CategoryProduct : ICategoryProductModel
|
public class CategoryProduct : ICategoryProductModel
|
||||||
{
|
{
|
||||||
public int ID { get; private set; }
|
public int ID { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public string Name { get; set; }=string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
public static CategoryProduct? Create(CategoryProductBindingModel model)
|
public static CategoryProduct? Create(CategoryProductBindingModel? model)
|
||||||
{
|
{
|
||||||
if(model == null)
|
if(model == null)
|
||||||
{
|
{
|
||||||
@ -30,7 +30,7 @@ namespace ElectronicsShopDataBaseImplement.Models
|
|||||||
Name = model.Name
|
Name = model.Name
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public static CategoryProduct Create(CategoryProductViewModel model)
|
public static CategoryProduct? Create(CategoryProductViewModel model)
|
||||||
{
|
{
|
||||||
return new CategoryProduct
|
return new CategoryProduct
|
||||||
{
|
{
|
||||||
@ -48,7 +48,7 @@ namespace ElectronicsShopDataBaseImplement.Models
|
|||||||
model.Name = Name;
|
model.Name = Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CategoryProduct GetViewModel => new()
|
public CategoryProductViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
ID = ID,
|
ID = ID,
|
||||||
Name = Name
|
Name = Name
|
||||||
|
Loading…
Reference in New Issue
Block a user