Исправление пространства имен + реализация хранилища пользователя
This commit is contained in:
parent
7eb1515a4d
commit
726011d7a5
@ -1,39 +0,0 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
|
||||
namespace HardwareShopContracts.StoragesContracts
|
||||
{
|
||||
public class UserStorage : IUserStorage
|
||||
{
|
||||
public UserViewModel? Delete(UserBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public UserViewModel? GetElement(UserSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<UserViewModel> GetFilteredList(UserSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<UserViewModel> GetFullList()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public UserViewModel? Insert(UserBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public UserViewModel? Update(UserBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.StoragesContracts;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDatabaseImplement.Models;
|
||||
|
||||
namespace HardwareShopDatabaseImplement.Implements
|
||||
{
|
||||
public class UserStorage : IUserStorage
|
||||
{
|
||||
public UserViewModel? Delete(UserBindingModel model)
|
||||
{
|
||||
using var context = new HardwareShopDatabase();
|
||||
var element = context.Users
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Users.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public UserViewModel? GetElement(UserSearchModel model)
|
||||
{
|
||||
using var context = new HardwareShopDatabase();
|
||||
if (model.Id.HasValue)
|
||||
return context.Users
|
||||
.FirstOrDefault(x => x.Id == model.Id)?
|
||||
.GetViewModel;
|
||||
if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
|
||||
return context.Users
|
||||
.FirstOrDefault(x => x.Email
|
||||
.Equals(model.Email) && x.Password
|
||||
.Equals(model.Password))?
|
||||
.GetViewModel;
|
||||
if (!string.IsNullOrEmpty(model.Email))
|
||||
return context.Users
|
||||
.FirstOrDefault(x => x.Email.Equals(model.Email))?.GetViewModel;
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<UserViewModel> GetFilteredList(UserSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Login))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new HardwareShopDatabase();
|
||||
return context.Users
|
||||
.Where(x => x.Login.Contains(model.Login))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<UserViewModel> GetFullList()
|
||||
{
|
||||
using var context = new HardwareShopDatabase();
|
||||
return context.Users
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public UserViewModel? Insert(UserBindingModel model)
|
||||
{
|
||||
var newUser = User.Create(model);
|
||||
if (newUser == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new HardwareShopDatabase();
|
||||
context.Users.Add(newUser);
|
||||
context.SaveChanges();
|
||||
return newUser.GetViewModel;
|
||||
}
|
||||
|
||||
public UserViewModel? Update(UserBindingModel model)
|
||||
{
|
||||
using var context = new HardwareShopDatabase();
|
||||
var user = context.Users
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (user == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
user.Update(model);
|
||||
context.SaveChanges();
|
||||
return user.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.StoragesContracts;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDatabaseImplement;
|
||||
using HardwareShopDatabaseImplement.Models.Worker;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HardwareShopContracts.StoragesContracts
|
||||
namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
{
|
||||
public class BuildStorage : IBuildStorage
|
||||
{
|
||||
|
@ -1,11 +1,11 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.StoragesContracts;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDatabaseImplement;
|
||||
using HardwareShopDatabaseImplement.Models.Worker;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HardwareShopContracts.StoragesContracts
|
||||
namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
{
|
||||
public class CommentStorage : ICommentStorage
|
||||
{
|
||||
|
@ -1,12 +1,11 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.StoragesContracts;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDatabaseImplement;
|
||||
using HardwareShopDatabaseImplement.Models.Storekeeper;
|
||||
using HardwareShopDatabaseImplement.Models.Worker;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HardwareShopContracts.StoragesContracts
|
||||
namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
{
|
||||
public class PurchaseStorage : IPurchaseStorage
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user