Ejemplo n.º 1
0
 public void Update(VisitBindingModel model)
 {
     using (var context = new BeautySaloonDatabase())
     {
         using (var transaction = context.Database.BeginTransaction())
         {
             try
             {
                 var element = context.Visits.FirstOrDefault(rec => rec.Id == model.Id);
                 if (element == null)
                 {
                     throw new Exception("Элемент не найден");
                 }
                 CreateModel(model, element, context);
                 context.SaveChanges();
                 transaction.Commit();
             }
             catch
             {
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }
 public ClientViewModel GetElement(ClientBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new BeautySaloonDatabase())
     {
         var client = context.Clients
                      //.Include(x => x.Procedure).Include(x => x.Purchase).Include(x => x.Visit)
                      .FirstOrDefault(rec => rec.Login == model.Login ||
                                      rec.Id == model.Id);
         return(client != null ?
                new ClientViewModel
         {
             Id = client.Id,
             ClientName = client.ClientName,
             ClientSurame = client.ClientSurame,
             Login = client.Login,
             Password = client.Password,
             Mail = client.Mail,
             Tel = client.Tel
         } :
                null);
     }
 }
Ejemplo n.º 3
0
 public List <VisitViewModel> GetFilteredList(VisitBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new BeautySaloonDatabase())
     {
         return(context.Visits
                .Include(rec => rec.Client)
                .Include(rec => rec.ProcedureVisit)
                .ThenInclude(rec => rec.Procedure)
                .Where(rec => (!model.DateFrom.HasValue && !model.DateTo.HasValue && rec.ClientId == model.ClientId || rec.Date == model.Date) ||
                       (model.DateFrom.HasValue && model.DateTo.HasValue && (rec.ClientId == model.ClientId &&
                                                                             rec.Date.Date >= model.DateFrom.Value.Date && rec.Date.Date <= model.DateTo.Value.Date)))
                .ToList()
                .Select(rec => new VisitViewModel
         {
             Id = rec.Id,
             ClientId = rec.ClientId,
             Date = rec.Date,
             VisitProcedures = rec.ProcedureVisit.ToDictionary(recPP => recPP.ProcedureId, recPP => (recPP.Procedure?.ProcedureName))
         }).ToList());
     }
 }
 public void Insert(ClientBindingModel model)
 {
     using (var context = new BeautySaloonDatabase())
     {
         context.Clients.Add(CreateModel(model, new Client(), context));
         context.SaveChanges();
     }
 }
Ejemplo n.º 5
0
 public void Insert(ProcedureBindingModel model)
 {
     using (var context = new BeautySaloonDatabase())
     {
         context.Procedures.Add(CreateModel(model, new Procedure()));
         context.SaveChanges();
     }
 }
Ejemplo n.º 6
0
 public void Insert(CosmeticBindingModel model)
 {
     using (var context = new BeautySaloonDatabase())
     {
         context.Cosmetics.Add(CreateModel(model, new Cosmetic()));
         context.SaveChanges();
     }
 }
 public void Insert(EmployeeBindingModel model)
 {
     using (var context = new BeautySaloonDatabase())
     {
         context.Employees.Add(CreateModel(model, new Employee()));
         context.SaveChanges();
     }
 }
Ejemplo n.º 8
0
 public List <ProcedureViewModel> GetFullList()
 {
     using (var context = new BeautySaloonDatabase())
     {
         return(context.Procedures
                .Select(CreateModel)
                .ToList());
     }
 }
 private Client CreateModel(ClientBindingModel model, Client client, BeautySaloonDatabase database)
 {
     client.ClientName   = model.ClientName;
     client.ClientSurame = model.ClientSurname;
     client.Login        = model.Login;
     client.Password     = model.Password;
     client.Mail         = model.Login;
     client.Tel          = model.Tel;
     return(client);
 }
Ejemplo n.º 10
0
 public void Update(CosmeticBindingModel model)
 {
     using (var context = new BeautySaloonDatabase())
     {
         var element = context.Cosmetics.FirstOrDefault(rec => rec.Id == model.Id);
         if (element == null)
         {
             throw new Exception("Элемент не найден");
         }
         CreateModel(model, element);
         context.SaveChanges();
     }
 }
Ejemplo n.º 11
0
 public List <ProcedureViewModel> GetFilteredList(ProcedureBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new BeautySaloonDatabase())
     {
         return(context.Procedures
                .Where(rec => rec.ClientId == model.ClientId || rec.ProcedureName.Contains(model.ProcedureName))
                .Select(CreateModel)
                .ToList());
     }
 }
Ejemplo n.º 12
0
 public ProcedureViewModel GetElement(ProcedureBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new BeautySaloonDatabase())
     {
         var procedure = context.Procedures
                         .FirstOrDefault(rec => rec.ProcedureName == model.ProcedureName || rec.Id == model.Id);
         return(procedure != null?
                CreateModel(procedure) :
                    null);
     }
 }
Ejemplo n.º 13
0
 public List <CosmeticViewModel> GetFullList()
 {
     using (var context = new BeautySaloonDatabase())
     {
         return(context.Cosmetics
                .Include(rec => rec.Employee)
                .Select(rec => new CosmeticViewModel
         {
             Id = rec.Id,
             CosmeticName = rec.CosmeticName,
             Price = rec.Price,
             EmployeeId = rec.EmployeeId
         })
                .ToList());
     }
 }
Ejemplo n.º 14
0
 public void Delete(CosmeticBindingModel model)
 {
     using (var context = new BeautySaloonDatabase())
     {
         Cosmetic element = context.Cosmetics.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Cosmetics.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Элемент не найден");
         }
     }
 }
 public List <ClientViewModel> GetFullList()
 {
     using (var context = new BeautySaloonDatabase())
     {
         return(context.Clients.Select(rec => new ClientViewModel
         {
             Id = rec.Id,
             ClientName = rec.ClientName,
             ClientSurame = rec.ClientSurame,
             Login = rec.Login,
             Password = rec.Password,
             Mail = rec.Mail,
             Tel = rec.Tel
         })
                .ToList());
     }
 }
Ejemplo n.º 16
0
 public List <ReceiptViewModel> GetFullList()
 {
     using (var context = new BeautySaloonDatabase())
     {
         return(context.Receipts
                .Include(rec => rec.Employee)
                .Include(rec => rec.ReceiptCosmetics)
                .ThenInclude(rec => rec.Cosmetic)
                .ToList()
                .Select(rec => new ReceiptViewModel
         {
             Id = rec.Id,
             TotalCost = rec.TotalCost,
             PurchaseDate = rec.PurchaseDate,
             ReceiptCosmetics = rec.ReceiptCosmetics.ToDictionary(recRC => recRC.CosmeticId, recRC => (recRC.Cosmetic?.CosmeticName, recRC.Count)),
             EmployeeId = rec.EmployeeId
         })
 public List <EmployeeViewModel> GetFullList()
 {
     using (var context = new BeautySaloonDatabase())
     {
         return(context.Employees
                .Select(rec => new EmployeeViewModel
         {
             Id = rec.Id,
             F_Name = rec.F_Name,
             L_Name = rec.L_Name,
             Login = rec.Login,
             Password = rec.Password,
             EMail = rec.EMail,
             PhoneNumber = rec.PhoneNumber
         })
                .ToList());
     }
 }
Ejemplo n.º 18
0
 public List <DistributionViewModel> GetFullList()
 {
     using (var context = new BeautySaloonDatabase())
     {
         return(context.Distributions
                .Include(rec => rec.Employee)
                .Include(rec => rec.Visit)
                .Include(rec => rec.DistributionCosmetics)
                .ThenInclude(rec => rec.Cosmetic)
                .ToList()
                .Select(rec => new DistributionViewModel
         {
             Id = rec.Id,
             IssueDate = rec.IssueDate,
             DistributionCosmetics = rec.DistributionCosmetics.ToDictionary(recDC => recDC.CosmeticId, recDC => (recDC.Cosmetic?.CosmeticName, recDC.Count)),
             EmployeeId = rec.EmployeeId,
             VisitId = rec.VisitId
         })
 public List <PurchaseViewModel> GetFullList()
 {
     using (var context = new BeautySaloonDatabase())
     {
         return(context.Purchases
                .Include(rec => rec.Client)
                .Include(rec => rec.Receipt)
                .Include(rec => rec.ProcedurePurchase)
                .ThenInclude(rec => rec.Procedure)
                .ToList()
                .Select(rec => new PurchaseViewModel
         {
             Id = rec.Id,
             ClientId = rec.ClientId,
             Date = rec.Date,
             Price = rec.Price,
             PurchaseProcedures = rec.ProcedurePurchase.ToDictionary(recPP => recPP.ProcedureId, recPP => (recPP.Procedure?.ProcedureName, recPP.Procedure.Price)),
             ReceiptId = rec.ReceiptId
         })
Ejemplo n.º 20
0
 public List <VisitViewModel> GetFullList()
 {
     using (var context = new BeautySaloonDatabase())
     {
         return(context.Visits
                .Include(rec => rec.Client)
                .Include(rec => rec.ProcedureVisit)
                .ThenInclude(rec => rec.Procedure)
                .ToList()
                .Select(rec => new VisitViewModel
         {
             Id = rec.Id,
             ClientId = rec.ClientId,
             Date = rec.Date,
             VisitProcedures = rec.ProcedureVisit.ToDictionary(recPP => recPP.ProcedureId, recPP => (recPP.Procedure?.ProcedureName))
         })
                .ToList());
     }
 }
Ejemplo n.º 21
0
 public List <ReportCosmeticsViewModel> GetDistributionsForAll(ReportBindingModelEmployee model)
 {
     using (var context = new BeautySaloonDatabase())
     {
         return((
                    from c in context.Cosmetics
                    join dc in context.DistributionCosmetics on c.Id equals dc.CosmeticId
                    join d in context.Distributions on dc.DistributionId equals d.Id
                    where d.IssueDate >= model.DateFrom
                    where d.IssueDate <= model.DateTo
                    select new ReportCosmeticsViewModel
         {
             TypeOfService = "Выдача",
             DateOfService = d.IssueDate,
             CosmeticName = c.CosmeticName,
             Count = dc.Count
         })
                .ToList());
     }
 }
Ejemplo n.º 22
0
 public void Insert(VisitBindingModel model)
 {
     using (var context = new BeautySaloonDatabase())
     {
         using (var transaction = context.Database.BeginTransaction())
         {
             try
             {
                 CreateModel(model, new Visit(), context);
                 context.SaveChanges();
                 transaction.Commit();
             }
             catch
             {
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }
Ejemplo n.º 23
0
 public List <ReportCosmeticsViewModel> GetReceiptsForAll(ReportBindingModelEmployee model)
 {
     using (var context = new BeautySaloonDatabase())
     {
         return((
                    from c in context.Cosmetics
                    join rc in context.ReceiptCosmetics on c.Id equals rc.CosmeticId
                    join r in context.Receipts on rc.ReceiptId equals r.Id
                    where r.PurchaseDate >= model.DateFrom
                    where r.PurchaseDate <= model.DateTo
                    select new ReportCosmeticsViewModel
         {
             TypeOfService = "Чек",
             DateOfService = r.PurchaseDate,
             CosmeticName = c.CosmeticName,
             Count = rc.Count
         })
                .ToList());
     }
 }
Ejemplo n.º 24
0
 public List <ReportPurchaseCosmeticViewModel> GetPurchaseList(int cosmeticId)
 {
     using (var context = new BeautySaloonDatabase())
     {
         return((
                    from c in context.Cosmetics
                    where c.Id == cosmeticId
                    join rc in context.ReceiptCosmetics on c.Id equals rc.CosmeticId
                    join r in context.Receipts on rc.ReceiptId equals r.Id
                    join p in context.Purchases on r.Id equals p.ReceiptId
                    select new ReportPurchaseCosmeticViewModel
         {
             CosmeticName = c.CosmeticName,
             Price = c.Price,
             Date = p.Date,
             Count = rc.Count,
             ClientId = p.ClientId,
         })
                .ToList());
     }
 }
Ejemplo n.º 25
0
 public List <CosmeticViewModel> GetFilteredList(CosmeticBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new BeautySaloonDatabase())
     {
         return(context.Cosmetics
                .Include(rec => rec.Employee)
                .Where(rec => rec.EmployeeId == model.EmployeeId || rec.CosmeticName.Contains(model.CosmeticName))
                .Select(rec => new CosmeticViewModel
         {
             Id = rec.Id,
             CosmeticName = rec.CosmeticName,
             Price = rec.Price,
             EmployeeId = rec.EmployeeId
         })
                .ToList());
     }
 }
Ejemplo n.º 26
0
 public CosmeticViewModel GetElement(CosmeticBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new BeautySaloonDatabase())
     {
         var tmp      = model.EmployeeId;
         var cosmetic = context.Cosmetics
                        .Include(rec => rec.Employee)
                        .FirstOrDefault(rec => rec.CosmeticName == model.CosmeticName || rec.Id == model.Id);
         return(cosmetic != null ?
                new CosmeticViewModel
         {
             Id = cosmetic.Id,
             CosmeticName = cosmetic.CosmeticName,
             Price = cosmetic.Price,
             EmployeeId = cosmetic.EmployeeId
         } :
                null);
     }
 }
 public List <EmployeeViewModel> GetFilteredList(EmployeeBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new BeautySaloonDatabase())
     {
         return(context.Employees
                .Where(rec => rec.Login == model.Login && rec.Password == model.Password)
                .Select(rec => new EmployeeViewModel
         {
             Id = rec.Id,
             F_Name = rec.F_Name,
             L_Name = rec.L_Name,
             Login = rec.Login,
             Password = rec.Password,
             EMail = rec.EMail,
             PhoneNumber = rec.PhoneNumber
         })
                .ToList());
     }
 }
Ejemplo n.º 28
0
        private Visit CreateModel(VisitBindingModel model, Visit visit, BeautySaloonDatabase context)
        {
            visit.Date     = model.Date;
            visit.ClientId = (int)model.ClientId;

            if (visit.Id == 0)
            {
                context.Visits.Add(visit);
                context.SaveChanges();
            }

            if (model.Id.HasValue)
            {
                var VisitComponents = context.ProcedureVisits.Where(rec =>
                                                                    rec.VisitId == model.Id.Value).ToList();

                context.ProcedureVisits.RemoveRange(VisitComponents.Where(rec =>
                                                                          !model.VisitProcedures.ContainsKey(rec.ProcedureId)).ToList());

                foreach (var updateProcedure in VisitComponents)
                {
                    model.VisitProcedures.Remove(updateProcedure.ProcedureId);
                }
                context.SaveChanges();
            }
            // добавили новые
            foreach (var vp in model.VisitProcedures)
            {
                context.ProcedureVisits.Add(new ProcedureVisit
                {
                    VisitId     = visit.Id,
                    ProcedureId = vp.Key,
                });
                context.SaveChanges();
            }
            return(visit);
        }
Ejemplo n.º 29
0
 public List <ReportCosmeticsViewModel> GetCosmetics(ReportBindingModelEmployee model)
 {
     using (var context = new BeautySaloonDatabase())
     {
         return((
                    from c in context.Cosmetics
                    join rc in context.ReceiptCosmetics on c.Id equals rc.CosmeticId
                    join r in context.Receipts on rc.ReceiptId equals r.Id
                    where r.EmployeeId == model.EmployeeId
                    where r.PurchaseDate >= model.DateFrom
                    where r.PurchaseDate <= model.DateTo
                    select new ReportCosmeticsViewModel
         {
             TypeOfService = "Чек",
             DateOfService = r.PurchaseDate,
             CosmeticName = c.CosmeticName,
             Count = rc.Count
         })
                .Union(
                    from c in context.Cosmetics
                    join dc in context.DistributionCosmetics on c.Id equals dc.CosmeticId
                    join d in context.Distributions on dc.DistributionId equals d.Id
                    where d.EmployeeId == model.EmployeeId
                    where d.IssueDate >= model.DateFrom
                    where d.IssueDate <= model.DateTo
                    select new ReportCosmeticsViewModel
         {
             TypeOfService = "Выдача",
             DateOfService = d.IssueDate,
             CosmeticName = c.CosmeticName,
             Count = dc.Count
         })
                .OrderBy(x => x.DateOfService)
                .ToList());
     }
 }
 public EmployeeViewModel GetElement(EmployeeBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new BeautySaloonDatabase())
     {
         var employee = context.Employees
                        .FirstOrDefault(rec => rec.Login == model.Login || rec.Id == model.Id);
         return(employee != null ?
                new EmployeeViewModel
         {
             Id = employee.Id,
             F_Name = employee.F_Name,
             L_Name = employee.L_Name,
             Login = employee.Login,
             Password = employee.Password,
             EMail = employee.EMail,
             PhoneNumber = employee.PhoneNumber
         } :
                null);
     }
 }