示例#1
0
        private Visit CreateModel(VisitBindingModel model, Visit visit, AutoServiceDatabase context)
        {
            visit.Date        = model.Date;
            visit.TotalSum    = model.TotalSum;
            visit.TransportId = model.TransportId;

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

            foreach (var newWorktype in model.Worktypes)
            {
                context.VisitWorktypes.Add(new VisitWorktype
                {
                    VisitId    = visit.Id,
                    WorktypeId = newWorktype.Key
                });
                context.SaveChanges();
            }

            foreach (var newMaterial in model.UsedMaterials)
            {
                context.UsedMaterials.Add(new VisitMaterial
                {
                    VisitId    = visit.Id,
                    MaterialId = newMaterial.Key,
                    Count      = newMaterial.Value.Item2
                });
                context.SaveChanges();
            }

            return(visit);
        }
示例#2
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 IHttpActionResult RecordVisit(int id, VisitBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var patient = DbContext.Patients.Where(p => p.Id == id).FirstOrDefault();

            if (patient == null)
            {
                return(NotFound());
            }

            var visit = Mapper.Map <Visit>(model);

            visit.Date      = DateTime.Now;
            visit.PatientId = id;

            patient.Visits.Add(visit);
            DbContext.SaveChanges();

            var visitModel = Mapper.Map <VisitViewModel>(visit);

            return(Ok(visitModel));
        }
示例#4
0
        public List <DateTime> GetPickDate(VisitBindingModel model)
        {
            var list = _visitStorage.GetFilteredList(model);

            List <DateTime> dateOfDay = new List <DateTime>();
            bool            end       = false;
            TimeVisit       time      = TimeVisit.ten;

            while (!end) // создали список дат на этот день (потом их будем удалять если они совпадают с эл-ми list)
            {
                DateTime date = new DateTime(model.Date.Year, model.Date.Month, model.Date.Day, Convert.ToInt32(time), 0, 0);
                dateOfDay.Add(date);
                time++;
                if (time > TimeVisit.fourteen)
                {
                    end = true;
                }
            }

            foreach (var item in list)
            {
                DateTime date = new DateTime(model.Date.Year, model.Date.Month, model.Date.Day, item.Date.Hour, 0, 0);
                if (dateOfDay.Contains(date))
                {
                    dateOfDay.Remove(date);
                }
            }
            return(dateOfDay);
        }
示例#5
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());
     }
 }
示例#6
0
 public void Insert(VisitBindingModel model)
 {
     using (var context = new AutoServiceDatabase())
     {
         CreateModel(model, new Visit(), context);
         context.SaveChanges();
     }
 }
示例#7
0
 public void Create(VisitBindingModel model)
 {
     if (model.Id.HasValue)
     {
         //здесь может быть апдейт данных
     }
     else
     {
         _visitStorage.Insert(model);
     }
 }
示例#8
0
        public void Delete(VisitBindingModel model)
        {
            var element = _visitStorage.GetElement(new VisitBindingModel {
                Id = model.Id
            });

            if (element == null)
            {
                throw new Exception("Посещение не найдено");
            }
            _visitStorage.Delete(model);
        }
示例#9
0
 public List <VisitViewModel> Read(VisitBindingModel model)
 {
     if (model == null)
     {
         return(_visitStorage.GetFullList());
     }
     if (model.Id.HasValue)
     {
         return(new List <VisitViewModel> {
             _visitStorage.GetElement(model)
         });
     }
     return(_visitStorage.GetFilteredList(model));
 }
示例#10
0
 public void Delete(VisitBindingModel model)
 {
     using (var context = new AutoServiceDatabase())
     {
         var element = context.Visits.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Visits.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Визит не найден");
         }
     }
 }
示例#11
0
 public void Delete(VisitBindingModel model)
 {
     using (var context = new BeautySaloonDatabase())
     {
         Visit element = context.Visits.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Visits.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Элемент не найден");
         }
     }
 }
示例#12
0
 public VisitViewModel GetElement(VisitBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new AutoServiceDatabase())
     {
         var material = context.Visits
                        .Include(rec => rec.Transport)
                        .Include(rec => rec.VisitWorktypes)
                        .ThenInclude(rec => rec.Worktype)
                        .Include(rec => rec.UsedMaterials)
                        .ThenInclude(rec => rec.Material).FirstOrDefault(rec => rec.Date.Equals(model.Date) || rec.Id == model.Id);
         return(material != null?CreateModel(material) : null);
     }
 }
示例#13
0
        public void CreateOrUpdate(VisitBindingModel model)
        {
            var element = _visitStorage.GetElement(new VisitBindingModel
            {
                Date = model.Date
            });

            if (element != null && element.Id != model.Id)
            {
                throw new Exception("Уже есть посещение на это время");
            }
            if (model.Id.HasValue)
            {
                _visitStorage.Update(model);
            }
            else
            {
                _visitStorage.Insert(model);
            }
        }
示例#14
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;
             }
         }
     }
 }
示例#15
0
 public List <VisitViewModel> GetFilteredList(VisitBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new AutoServiceDatabase())
     {
         return(context.Visits
                .Include(rec => rec.Transport)
                .Include(rec => rec.VisitWorktypes)
                .ThenInclude(rec => rec.Worktype)
                .Include(rec => rec.UsedMaterials)
                .ThenInclude(rec => rec.Material)
                .Where(rec => (model.DateFrom.HasValue && model.DateTo.HasValue &&
                               rec.Date.Date >= model.DateFrom.Value.Date &&
                               rec.Date.Date <= model.DateTo.Value.Date))
                .Select(CreateModel).ToList());
     }
 }
示例#16
0
        public IHttpActionResult RecordVisit(int id, VisitBindingModel model)
        {
            var patientId = DbContext.Patients.FirstOrDefault(p => p.Id == id).Id;
            var patient   = DbContext.Patients.FirstOrDefault(p => p.Id == id);

            var visit = new Visit()
            {
                Date      = DateTime.Now,
                Comments  = model.Comments,
                PatientId = patientId
            };

            patient.Visits.Add(visit);
            DbContext.SaveChanges();

            var url = Url.Link("VisitById", new { Id = visit.Id });

            var viewModel = new PatientViewModel(patient);

            return(Created(url, viewModel));
        }
示例#17
0
        public IHttpActionResult RecordVisit(int id, VisitBindingModel formData)
        {
            var patient = DbContext
                          .Patients
                          .FirstOrDefault(p => p.Id == id);

            if (patient == null)
            {
                return(NotFound());
            }

            var visit = Mapper.Map <Visit>(formData);

            visit.Date = DateTime.Now;

            patient.Visits.Add(visit);

            DbContext.SaveChanges();

            return(Ok());
        }
示例#18
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);
        }
示例#19
0
 public VisitViewModel GetElement(VisitBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new BeautySaloonDatabase())
     {
         var visit = context.Visits
                     .Include(rec => rec.Client)
                     .Include(rec => rec.ProcedureVisit)
                     .ThenInclude(rec => rec.Procedure)
                     .FirstOrDefault(rec => rec.Date == model.Date || rec.Id == model.Id);
         return(visit != null ?
                new VisitViewModel
         {
             Id = visit.Id,
             ClientId = visit.ClientId,
             Date = visit.Date,
             VisitProcedures = visit.ProcedureVisit.ToDictionary(recVP => recVP.ProcedureId, recVP => (recVP.Procedure?.ProcedureName))
         } :
                null);
     }
 }