это честная работа

This commit is contained in:
Allllen4a 2024-05-29 16:22:22 +04:00
parent 640a16ed08
commit ceaa8c652b
4 changed files with 80 additions and 50 deletions

View File

@ -50,7 +50,15 @@ namespace BeautySalonDatabaseImplement.Implements
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
throw new NotImplementedException();
using var context = new BeautySalonDatabase();
if (model.Id.HasValue)
{
return context.Clients
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public List<ClientViewModel> GetFullList()

View File

@ -16,6 +16,8 @@ namespace BeautySalonDatabaseImplement.Implements
{
using var context = new BeautySalonDatabase();
return context.Cosmetics
.Include(x => x.Procedures)
.ThenInclude(x => x.Procedure)
.Select(x => x.GetViewModel)
.ToList();
}
@ -29,14 +31,7 @@ namespace BeautySalonDatabaseImplement.Implements
.Select(x => x.GetViewModel)
.ToList();
}
if (model.LaborCostId.HasValue)
{
return context.Cosmetics
.Where(x => x.LaborCostId == model.LaborCostId)
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
@ -48,9 +43,11 @@ namespace BeautySalonDatabaseImplement.Implements
}
using var context = new BeautySalonDatabase();
return context.Cosmetics
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.CosmeticName) && x.CosmeticName == model.CosmeticName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
.Include(x => x.Procedures)
.ThenInclude(x => x.Procedure)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.CosmeticName) && x.CosmeticName == model.CosmeticName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public CosmeticViewModel? Insert(CosmeticBindingModel model)
@ -69,20 +66,33 @@ namespace BeautySalonDatabaseImplement.Implements
public CosmeticViewModel? Update(CosmeticBindingModel model)
{
using var context = new BeautySalonDatabase();
var сosmetic = context.Cosmetics.FirstOrDefault(x => x.Id == model.Id);
if (сosmetic == null)
using var transaction = context.Database.BeginTransaction();
try
{
return null;
var cosmetic = context.Cosmetics.FirstOrDefault(rec => rec.Id == model.Id);
if (cosmetic == null)
{
return null;
}
cosmetic.Update(model);
context.SaveChanges();
cosmetic.UpdateProcedure(context, model);
transaction.Commit();
return cosmetic.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
сosmetic.Update(model);
context.SaveChanges();
return сosmetic.GetViewModel;
}
public CosmeticViewModel? Delete(CosmeticBindingModel model)
{
using var context = new BeautySalonDatabase();
var element = context.Cosmetics.FirstOrDefault(rec => rec.Id == model.Id);
var element = context.Cosmetics
.Include(x => x.Procedures)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Cosmetics.Remove(element);

View File

@ -17,12 +17,16 @@ namespace BeautySalonDatabaseImplement.Implements
public LaborCostsViewModel? Delete(LaborCostsBindingModel model)
{
using var context = new BeautySalonDatabase();
var element = context.LaborCosts.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
var deletedElement = context.LaborCosts
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
context.LaborCosts.Remove(element);
context.SaveChanges();
return element.GetViewModel;
return deletedElement;
}
return null;
}
@ -69,28 +73,32 @@ namespace BeautySalonDatabaseImplement.Implements
public LaborCostsViewModel? Insert(LaborCostsBindingModel model)
{
var newLaborCosts = LaborCosts.Create(model);
if (newLaborCosts == null)
var newLaborCost = LaborCosts.Create(model);
if (newLaborCost == null)
{
return null;
}
using var context = new BeautySalonDatabase();
context.LaborCosts.Add(newLaborCosts);
context.LaborCosts.Add(newLaborCost);
context.SaveChanges();
return newLaborCosts.GetViewModel;
return context.LaborCosts
.FirstOrDefault(x => x.Id == newLaborCost.Id)
?.GetViewModel;
}
public LaborCostsViewModel? Update(LaborCostsBindingModel model)
{
using var context = new BeautySalonDatabase();
var laborCosts = context.LaborCosts.FirstOrDefault(x => x.Id == model.Id);
if (laborCosts == null)
var order = context.LaborCosts.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
}
laborCosts.Update(model);
order.Update(model);
context.SaveChanges();
return laborCosts.GetViewModel;
return context.LaborCosts
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
}
}

View File

@ -16,15 +16,15 @@ namespace BeautySalonDatabaseImplement.Implements
using var context = new BeautySalonDatabase();
var element = context.StaffMembers.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
var deletedElement = context.StaffMembers
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
context.StaffMembers.Remove(element);
context.SaveChanges();
return element.GetViewModel;
return deletedElement;
}
return null;
}
@ -49,7 +49,15 @@ namespace BeautySalonDatabaseImplement.Implements
public List<StaffMemberViewModel> GetFilteredList(StaffMemberSearchModel model)
{
throw new NotImplementedException();
using var context = new BeautySalonDatabase();
if (model.Id.HasValue)
{
return context.StaffMembers
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public List<StaffMemberViewModel> GetFullList()
@ -62,36 +70,32 @@ namespace BeautySalonDatabaseImplement.Implements
public StaffMemberViewModel? Insert(StaffMemberBindingModel model)
{
using var context = new BeautySalonDatabase();
var newStaffMembers = StaffMember.Create(model);
if (newStaffMembers == null)
var newStaffMember = StaffMember.Create(model);
if (newStaffMember == null)
{
return null;
}
context.StaffMembers.Add(newStaffMembers);
using var context = new BeautySalonDatabase();
context.StaffMembers.Add(newStaffMember);
context.SaveChanges();
return newStaffMembers.GetViewModel;
return context.StaffMembers
.FirstOrDefault(x => x.Id == newStaffMember.Id)
?.GetViewModel;
}
public StaffMemberViewModel? Update(StaffMemberBindingModel model)
{
using var context = new BeautySalonDatabase();
var StaffMembers = context.StaffMembers.FirstOrDefault(x => x.Id == model.Id);
if (StaffMembers == null)
var order = context.StaffMembers.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
}
StaffMembers.Update(model);
order.Update(model);
context.SaveChanges();
return StaffMembers.GetViewModel;
return context.StaffMembers
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
}
}