Добавила implements, но нужны большие правки
This commit is contained in:
parent
4dab4e5705
commit
b9867c3c70
@ -0,0 +1,97 @@
|
||||
using BeautySalonContracts.BindingModels;
|
||||
using BeautySalonContracts.SearchModels;
|
||||
using BeautySalonContracts.StoragesContracts;
|
||||
using BeautySalonContracts.ViewModels;
|
||||
using BeautySalonDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace BeautySalonDatabaseImplement.Implements
|
||||
{
|
||||
public class ClientStorage : IClientStorage
|
||||
{
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
|
||||
var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
context.Clients.Remove(element);
|
||||
context.SaveChanges();
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
if (model.Id.HasValue)
|
||||
return context.Clients
|
||||
.FirstOrDefault(x => x.Id == model.Id)?
|
||||
.GetViewModel;
|
||||
|
||||
if (!string.IsNullOrEmpty(model.ClientLogin) &&
|
||||
!string.IsNullOrEmpty(model.ClientPassword))
|
||||
return context.Clients
|
||||
.FirstOrDefault(x =>
|
||||
x.ClientLogin.Equals(model.ClientLogin) &&
|
||||
x.ClientPassword.Equals(model.ClientPassword))?
|
||||
.GetViewModel;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
return context.Clients
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ClientViewModel? Insert(ClientBindingModel model)
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
|
||||
var newClient = Client.Create(model);
|
||||
|
||||
if (newClient == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Clients.Add(newClient);
|
||||
context.SaveChanges();
|
||||
|
||||
return newClient.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Update(ClientBindingModel model)
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
|
||||
var client = context.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (client == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
client.Update(model);
|
||||
context.SaveChanges();
|
||||
|
||||
return client.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
using BeautySalonContracts.BindingModels;
|
||||
using BeautySalonContracts.SearchModels;
|
||||
using BeautySalonContracts.StoragesContracts;
|
||||
using BeautySalonContracts.ViewModels;
|
||||
using BeautySalonDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeautySalonDatabaseImplement.Implements
|
||||
{
|
||||
public class EvaluationStorage : IEvaluationStorage
|
||||
{
|
||||
public List<EvaluationViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
return context.Evaluations
|
||||
.Include(x => x.Procedure)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public int GetNumberOfPages(int userId, int pageSize)
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
int carsCount = context.LaborsCosts.Where(c => c.StaffMemberId == userId).Count();
|
||||
int numberOfpages = (int)Math.Ceiling((double)carsCount / pageSize);
|
||||
return numberOfpages != 0 ? numberOfpages : 1;
|
||||
}
|
||||
|
||||
public List<EvaluationViewModel> GetFilteredList(EvaluationSearchModel model)
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Ratings
|
||||
.Include(x => x.Procedure)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (model.ClientId.HasValue && model.PageNumber.HasValue && model.PageSize.HasValue)
|
||||
{
|
||||
return context.Ratings
|
||||
.Include(x => x.Procedure)
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Skip(model.PageSize.Value * (model.PageNumber.Value - 1))
|
||||
.Take(model.PageSize.Value)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return new();
|
||||
}
|
||||
|
||||
public EvaluationViewModel? GetElement(EvaluationSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new BeautySalonDatabase();
|
||||
return context.Ratings
|
||||
.Include(x => x.Procedure)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public EvaluationViewModel? Insert(EvaluationBindingModel model)
|
||||
{
|
||||
var newRating = Evaluation.Create(model);
|
||||
if (newRating == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new BeautySalonDatabase();
|
||||
context.Ratings.Add(newRating);
|
||||
context.SaveChanges();
|
||||
return context.Ratings
|
||||
.Include(x => x.Procedure)
|
||||
.FirstOrDefault(x => x.Id == newRating.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public EvaluationViewModel? Update(EvaluationBindingModel model)
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
var сosmetic = context.Evaluations
|
||||
.Include(x => x.Procedure)
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (сosmetic == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
сosmetic.Update(model);
|
||||
context.SaveChanges();
|
||||
return сosmetic.GetViewModel;
|
||||
}
|
||||
|
||||
public EvaluationViewModel? Delete(EvaluationBindingModel model)
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
var element = context.Evaluations
|
||||
.Include(x => x.Procedure)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Evaluations.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,149 @@
|
||||
using BeautySalonContracts.BindingModels;
|
||||
using BeautySalonContracts.SearchModels;
|
||||
using BeautySalonContracts.StoragesContracts;
|
||||
using BeautySalonContracts.ViewModels;
|
||||
using BeautySalonDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeautySalonDatabaseImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
var element = context.Orders
|
||||
.Include(x => x.Services)
|
||||
.Include(x => x.Procedures)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Orders.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new BeautySalonDatabase();
|
||||
return context.Orders
|
||||
.Include(x => x.Services)
|
||||
.ThenInclude(x => x.Service)
|
||||
.Include(x => x.Procedures)
|
||||
.ThenInclude(x => x.Procedure)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
public int GetNumberOfPages(int userId, int pageSize)
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
int carsCount = context.Orders.Where(c => c.ClientId == userId).Count();
|
||||
int numberOfpages = (int)Math.Ceiling((double)carsCount / pageSize);
|
||||
return numberOfpages != 0 ? numberOfpages : 1;
|
||||
}
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new BeautySalonDatabase();
|
||||
if (model.ClientId.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Include(x => x.Services)
|
||||
.ThenInclude(x => x.Service)
|
||||
.Include(x => x.Procedures)
|
||||
.ThenInclude(x => x.Procedure)
|
||||
.ThenInclude(x => x.Ratings)
|
||||
.Where(x => x.ClientId == model.ClientId &&
|
||||
x.OrderDate >= model.DateFrom && x.OrderDate <= model.DateTo).ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (model.ClientId.HasValue && model.PageNumber.HasValue && model.PageSize.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Include(x => x.Services)
|
||||
.ThenInclude(x => x.Service)
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Skip(model.PageSize.Value * (model.PageNumber.Value - 1))
|
||||
.Take(model.PageSize.Value)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (model.ClientId.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Include(x => x.Services)
|
||||
.ThenInclude(x => x.Service)
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return new();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
return context.Orders
|
||||
.Include(x => x.Services)
|
||||
.ThenInclude(x => x.Service)
|
||||
.Include(x => x.Procedures)
|
||||
.ThenInclude(x => x.Procedure)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
var newOrder = Order.Create(context, model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
return newOrder.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
order.UpdateServices(context, model);
|
||||
order.UpdateProcedures(context, model);
|
||||
transaction.Commit();
|
||||
return order.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
using BeautySalonContracts.BindingModels;
|
||||
using BeautySalonContracts.SearchModels;
|
||||
using BeautySalonContracts.StoragesContracts;
|
||||
using BeautySalonContracts.ViewModels;
|
||||
using BeautySalonDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeautySalonDatabaseImplement.Implements
|
||||
{
|
||||
public class ProcedureStorage : IProcedureStorage
|
||||
{
|
||||
public ProcedureViewModel? Delete(ProcedureBindingModel model)
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
var element = context.Procedures
|
||||
.Include(x => x.Cosmetics)
|
||||
.Include(x => x.Orders)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Procedures.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ProcedureViewModel? GetElement(ProcedureSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ProcedureName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new BeautySalonDatabase();
|
||||
return context.Procedures
|
||||
.Include(x => x.Cosmetics)
|
||||
.ThenInclude(x => x.Cosmetic)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ProcedureName) && x.ProcedureName == model.ProcedureName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
public int GetNumberOfPages(int userId, int pageSize)
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
int carsCount = context.Procedures.Where(c => c.ClientId == userId).Count();
|
||||
int numberOfpages = (int)Math.Ceiling((double)carsCount / pageSize);
|
||||
return numberOfpages != 0 ? numberOfpages : 1;
|
||||
}
|
||||
|
||||
public List<ProcedureViewModel> GetFilteredList(ProcedureSearchModel model)
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Procedures
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (model.ClientId.HasValue && model.PageNumber.HasValue && model.PageSize.HasValue)
|
||||
{
|
||||
return context.Procedures
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Skip(model.PageSize.Value * (model.PageNumber.Value - 1))
|
||||
.Take(model.PageSize.Value)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (model.ClientId.HasValue)
|
||||
{
|
||||
return context.Procedures
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return new();
|
||||
}
|
||||
|
||||
public List<ProcedureViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
return context.Procedures
|
||||
.Include(x => x.Cosmetics)
|
||||
.ThenInclude(x => x.Cosmetic)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ProcedureViewModel? Insert(ProcedureBindingModel model)
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
var newProcedure = Procedure.Create(context, model);
|
||||
if (newProcedure == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Procedures.Add(newProcedure);
|
||||
context.SaveChanges();
|
||||
return newProcedure.GetViewModel;
|
||||
}
|
||||
|
||||
public ProcedureViewModel? Update(ProcedureBindingModel model)
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var procedure = context.Procedures.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (procedure == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
procedure.Update(model);
|
||||
context.SaveChanges();
|
||||
procedure.UpdateCosmetics(context, model);
|
||||
transaction.Commit();
|
||||
return procedure.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user