исправил сотрудника

This commit is contained in:
Milana Ievlewa 2024-04-30 14:29:52 +03:00
parent 095d7d173f
commit 8b40fd8b02

View File

@ -9,17 +9,17 @@ using System.Linq;
namespace BeautySalonDatabaseImplement.Implements
{
public class LaborCostStorage : ILaborCostsStorage
public class StaffMemberStorage : IStaffMemberStorage
{
public LaborCostsViewModel? Delete(LaborCostsBindingModel model)
public StaffMemberViewModel? Delete(StaffMemberBindingModel model)
{
using var context = new BeautySalonDatabase();
var element = context.LaborCosts.FirstOrDefault(rec => rec.Id == model.Id);
var element = context.StaffMembers.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.LaborCosts.Remove(element);
context.StaffMembers.Remove(element);
context.SaveChanges();
return element.GetViewModel;
@ -28,70 +28,70 @@ namespace BeautySalonDatabaseImplement.Implements
return null;
}
public LaborCostsViewModel? GetElement(LaborCostsSearchModel model)
public StaffMemberViewModel? GetElement(StaffMemberSearchModel model)
{
using var context = new BeautySalonDatabase();
if (model.Id.HasValue)
return context.LaborCosts
return context.StaffMembers
.FirstOrDefault(x => x.Id == model.Id)?
.GetViewModel;
if (!string.IsNullOrEmpty(model.LaborCostsPassword) &&
!string.IsNullOrEmpty(model.LaborCostsLogin))
return context.LaborCostss
if (!string.IsNullOrEmpty(model.StaffMemberPassword) &&
!string.IsNullOrEmpty(model.StaffMemberLogin))
return context.StaffMembers
.FirstOrDefault(x =>
x.LaborCostsPassword.Equals(model.LaborCostsPassword) &&
x.LaborCostsLogin.Equals(model.LaborCostsLogin))?
x.StaffMemberPassword.Equals(model.StaffMemberPassword) &&
x.StaffMemberLogin.Equals(model.StaffMemberLogin))?
.GetViewModel;
return null;
}
public List<LaborCostsViewModel> GetFilteredList(LaborCostsSearchModel model)
public List<StaffMemberViewModel> GetFilteredList(StaffMemberSearchModel model)
{
throw new NotImplementedException();
}
public List<LaborCostsViewModel> GetFullList()
public List<StaffMemberViewModel> GetFullList()
{
using var context = new BeautySalonDatabase();
return context.LaborCosts
return context.StaffMembers
.Select(x => x.GetViewModel)
.ToList();
}
public LaborCostsViewModel? Insert(LaborCostsBindingModel model)
public StaffMemberViewModel? Insert(StaffMemberBindingModel model)
{
using var context = new BeautySalonDatabase();
var newLaborCosts = LaborCosts.Create(model);
var newStaffMembers = StaffMember.Create(model);
if (newLaborCosts == null)
if (newStaffMembers == null)
{
return null;
}
context.LaborCosts.Add(newLaborCosts);
context.StaffMembers.Add(newStaffMembers);
context.SaveChanges();
return newLaborCosts.GetViewModel;
return newStaffMembers.GetViewModel;
}
public LaborCostsViewModel? Update(LaborCostsBindingModel model)
public StaffMemberViewModel? Update(StaffMemberBindingModel model)
{
using var context = new BeautySalonDatabase();
var LaborCosts = context.LaborCosts.FirstOrDefault(x => x.Id == model.Id);
var StaffMembers = context.StaffMembers.FirstOrDefault(x => x.Id == model.Id);
if (LaborCosts == null)
if (StaffMembers == null)
{
return null;
}
LaborCosts.Update(model);
StaffMembers.Update(model);
context.SaveChanges();
return LaborCosts.GetViewModel;
return StaffMembers.GetViewModel;
}
}
}