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); }
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)); }
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); }
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(VisitBindingModel model) { using (var context = new AutoServiceDatabase()) { CreateModel(model, new Visit(), context); context.SaveChanges(); } }
public void Create(VisitBindingModel model) { if (model.Id.HasValue) { //здесь может быть апдейт данных } else { _visitStorage.Insert(model); } }
public void Delete(VisitBindingModel model) { var element = _visitStorage.GetElement(new VisitBindingModel { Id = model.Id }); if (element == null) { throw new Exception("Посещение не найдено"); } _visitStorage.Delete(model); }
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)); }
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("Визит не найден"); } } }
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("Элемент не найден"); } } }
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); } }
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); } }
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; } } } }
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()); } }
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)); }
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()); }
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); }
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); } }