Beispiel #1
0
        public void Delete(KidBindingModel model)
        {
            using (var context = new SchoolAgainDatabase())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        Kid element = context.Kids.FirstOrDefault(rec => rec.Id == model.Id.Value);

                        if (element != null)
                        {
                            context.ClientKids.RemoveRange(
                                context.ClientKids.Where(
                                    rec => rec.KidId == model.Id.Value));
                            context.Kids.Remove(element);
                            context.SaveChanges();
                        }
                        else
                        {
                            throw new Exception("Элемент не найден");
                        }
                        transaction.Commit();
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }
 protected override List <T> GetList <T>()
 {
     using (var context = new SchoolAgainDatabase())
     {
         return(context.Set <T>().ToList());
     }
 }
        public void CreateOrUpdate(ReceptionBindingModel model)
        {
            using (var context = new SchoolAgainDatabase())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        Reception element = model.Id.HasValue ? null : new Reception();
                        if (model.Id.HasValue)
                        {
                            element = context.Receptions.FirstOrDefault(rec => rec.Id ==
                                                                        model.Id);
                            if (element == null)
                            {
                                throw new Exception("Элемент не найден");
                            }
                            element.ClientId        = model.ClientId;
                            element.DateCreate      = model.DateCreate;
                            element.TotalSum        = model.TotalSum;
                            element.ReceptionStatus = model.ReceptionStatus;
                            context.SaveChanges();
                        }
                        else
                        {
                            element.ClientId        = model.ClientId;
                            element.DateCreate      = model.DateCreate;
                            element.TotalSum        = model.TotalSum;
                            element.ReceptionStatus = model.ReceptionStatus;
                            context.Receptions.Add(element);
                            context.SaveChanges();
                            var groupServices = model.ReceptionServices
                                                .GroupBy(rec => rec.ServiceId)
                                                .Select(rec => new
                            {
                                ServiceId = rec.Key,
                                Count     = rec.Sum(r => r.Count)
                            });

                            foreach (var groupService in groupServices)
                            {
                                context.ReceptionServices.Add(new ReceptionService
                                {
                                    ReceptionId = element.Id,
                                    ServiceId   = groupService.ServiceId,
                                    Count       = groupService.Count
                                });
                                context.SaveChanges();
                            }
                        }
                        transaction.Commit();
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }
Beispiel #4
0
 public void CreateOrUpdate(PaymentBindingModel model)
 {
     using (var context = new SchoolAgainDatabase())
     {
         Payment element = model.Id.HasValue ? null : new Payment();
         if (model.Id.HasValue)
         {
             element = context.Payments.FirstOrDefault(rec => rec.Id ==
                                                       model.Id);
             if (element == null)
             {
                 throw new Exception("Элемент не найден");
             }
         }
         else
         {
             element = new Payment();
             context.Payments.Add(element);
         }
         element.ReceptionId = model.ReceptionId;
         element.ClientId    = model.ClientId;
         element.Sum         = model.Sum;
         element.DatePayment = model.DatePayment;
         context.SaveChanges();
     }
 }
 public void CreateOrUpdate(ClientBindingModel model)
 {
     using (var context = new SchoolAgainDatabase())
     {
         Client element = model.Id.HasValue ? null : new Client();
         if (model.Id.HasValue)
         {
             element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
             if (element == null)
             {
                 throw new Exception("Элемент не найден");
             }
         }
         else
         {
             element = new Client();
             context.Clients.Add(element);
         }
         element.ClientFIO = model.ClientFIO;
         element.Email     = model.Email;
         element.Login     = model.Login;
         element.Phone     = model.Phone;
         element.Block     = model.Block;
         element.Password  = model.Password;
         context.SaveChanges();
     }
 }
 protected override List <PropertyInfo> GetFullList()
 {
     using (var context = new SchoolAgainDatabase())
     {
         Type type = context.GetType();
         return(type.GetProperties().Where(x =>
                                           x.PropertyType.FullName.StartsWith("Microsoft.EntityFrameworkCore.DbSet")).ToList());
     }
 }
Beispiel #7
0
        public void CreateOrUpdate(KidBindingModel model)
        {
            using (var context = new SchoolAgainDatabase())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        Kid element = model.Id.HasValue ? null : new Kid();
                        if (model.Id.HasValue)
                        {
                            element = context.Kids.FirstOrDefault(rec => rec.ClientId ==
                                                                  model.ClientId && rec.KidName == model.KidName);
                            if (element == null)
                            {
                                throw new Exception("Такой питомец уже существует");
                            }
                            element.KidName  = model.KidName;
                            element.Height   = model.Height;
                            element.Free     = model.Free;
                            element.Age      = model.Age;
                            element.Gender   = model.Gender;
                            element.ClientId = model.ClientId;
                            context.SaveChanges();
                        }
                        else
                        {
                            element.KidName  = model.KidName;
                            element.Height   = model.Height;
                            element.Free     = model.Free;
                            element.Age      = model.Age;
                            element.Gender   = model.Gender;
                            element.ClientId = model.ClientId;
                        }
                        context.Kids.Add(element);
                        context.SaveChanges();

                        transaction.Commit();
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }
        public void Delete(ReceptionBindingModel model)
        {
            using (var context = new SchoolAgainDatabase())
            {
                Reception element = context.Receptions.FirstOrDefault(rec => rec.Id == model.Id.Value);

                if (element != null)
                {
                    context.Receptions.Remove(element);
                    context.SaveChanges();
                }
                else
                {
                    throw new Exception("Элемент не найден");
                }
            }
        }
Beispiel #9
0
 public List <PaymentViewModel> Read(PaymentBindingModel model)
 {
     using (var context = new SchoolAgainDatabase())
     {
         return(context.Payments
                .Where(rec => model == null || rec.Id == model.Id || rec.ReceptionId.Equals(model.ReceptionId))
                .Select(rec => new PaymentViewModel
         {
             Id = rec.Id,
             ClientId = rec.ClientId,
             DatePayment = rec.DatePayment,
             ReceptionId = rec.ReceptionId,
             Sum = rec.Sum
         })
                .ToList());
     }
 }
Beispiel #10
0
 public List <KidViewModel> Read(KidBindingModel model)
 {
     using (var context = new SchoolAgainDatabase())
     {
         return(context.Kids
                .Where(rec => model == null ||
                       rec.Id == model.Id ||
                       (rec.ClientId == model.ClientId))
                .Select(rec => new KidViewModel
         {
             Id = rec.Id,
             ClientId = rec.ClientId,
             Height = rec.Height,
             KidName = rec.KidName,
             Free = rec.Free,
             Age = rec.Age,
             Gender = rec.Gender,
             ClientKids = GetClientKidViewModel(rec)
         })
                .ToList());
     }
 }
Beispiel #11
0
 public static List <ClientKidViewModel> GetClientKidViewModel(Kid kid)
 {
     using (var context = new SchoolAgainDatabase())
     {
         var ClientKids = context.ClientKids
                          .Where(rec => rec.KidId == kid.Id)
                          .Include(rec => rec.Client)
                          .Select(rec => new ClientKidViewModel
         {
             Id       = rec.Id,
             KidId    = rec.KidId,
             ClientId = rec.ClientId,
             Count    = rec.Count
         }).ToList();
         foreach (var client in ClientKids)
         {
             var clientData = context.Clients.Where(rec => rec.Id == client.ClientId).FirstOrDefault();
             client.ClientFIO = clientData.ClientFIO;
         }
         return(ClientKids);
     }
 }
 public List <ClientViewModel> Read(ClientBindingModel model)
 {
     using (var context = new SchoolAgainDatabase())
     {
         return(context.Clients
                .Where(rec => model == null ||
                       rec.Id == model.Id ||
                       (rec.Login == model.Login || rec.Email == model.Email) &&
                       (model.Password == null || rec.Password == model.Password))
                .Select(rec => new ClientViewModel
         {
             Id = rec.Id,
             Login = rec.Login,
             ClientFIO = rec.ClientFIO,
             Email = rec.Email,
             Password = rec.Password,
             Phone = rec.Phone,
             Block = rec.Block
         })
                .ToList());
     }
 }
 public static List <ReceptionServiceViewModel> GetReceptionServiceViewModel(Reception reception)
 {
     using (var context = new SchoolAgainDatabase())
     {
         var ReceptionServices = context.ReceptionServices
                                 .Where(rec => rec.ReceptionId == reception.Id)
                                 .Include(rec => rec.Service)
                                 .Select(rec => new ReceptionServiceViewModel
         {
             Id          = rec.Id,
             ReceptionId = rec.ReceptionId,
             ServiceId   = rec.ServiceId,
             Count       = rec.Count
         }).ToList();
         foreach (var service in ReceptionServices)
         {
             var serviceData = context.Services.Where(rec => rec.Id == service.ServiceId).FirstOrDefault();
             service.ServiceName = serviceData.ServiceName;
             service.Price       = serviceData.Price;
         }
         return(ReceptionServices);
     }
 }
 public List <ReceptionViewModel> Read(ReceptionBindingModel model)
 {
     using (var context = new SchoolAgainDatabase())
     {
         return(context.Receptions.Where(rec => rec.Id == model.Id ||
                                         (rec.ClientId == model.ClientId) &&
                                         (model.Date == null &&
                                          model.DateTo == null ||
                                          rec.DateCreate >= model.Date &&
                                          rec.DateCreate <= model.DateTo))
                .Select(rec => new ReceptionViewModel
         {
             Id = rec.Id,
             ClientId = rec.ClientId,
             ClientFIO = rec.Client.ClientFIO,
             TotalSum = rec.TotalSum,
             DateCreate = rec.DateCreate,
             LeftSum = rec.TotalSum - context.Payments.Where(recP => recP.ReceptionId == rec.Id).Select(recP => recP.Sum).Sum(),
             ReceptionStatus = rec.ReceptionStatus,
             ReceptionServices = GetReceptionServiceViewModel(rec)
         })
                .ToList());
     }
 }
        public void SaveToDatabase()
        {
            var services = LoadServices();

            using (var context = new SchoolAgainDatabase())
            {
                foreach (var service in services)
                {
                    Service element = context.Services.FirstOrDefault(rec => rec.Id == service.Id);
                    if (element != null)
                    {
                        break;
                    }
                    else
                    {
                        element = new Service();
                        context.Services.Add(element);
                    }
                    element.ServiceName = service.ServiceName;
                    element.Price       = service.Price;
                    context.SaveChanges();
                }
            }
        }