public async Task <IActionResult> DeleteMeaItem(int?id) { if (id == null) { return(NotFound()); } MeaItem meaItem = await _context.MeaItems .FirstOrDefaultAsync(m => m.Id == id); MeaDisp result = _context.MeaDisps .Include(m => m.MeaItems) .Where(m => m.MeaItems.Contains(meaItem)).FirstOrDefault(); if (meaItem == null) { return(NotFound()); } _context.MeaItems.Remove(meaItem); await _context.SaveChangesAsync(); return(RedirectToAction($"{nameof(DetailsMeaDisp)}/{result.Id}")); }
public async Task <IActionResult> DeleteMeaDisp(int?id) { if (id == null) { return(NotFound()); } MeaDisp meaDisp = await _context.MeaDisps .Include(m => m.Station) .Include(m => m.Seraphin) .Include(m => m.User) .Include(m => m.MeaItems) .ThenInclude(m => m.Dispenser) .Include(m => m.MeaItems) .ThenInclude(m => m.Hose) .FirstOrDefaultAsync(m => m.Id == id); if (meaDisp == null) { return(NotFound()); } _context.MeaDisps.Remove(meaDisp); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(IndexMeaDisp))); }
public async Task <IActionResult> UpdateMeaDip(MeaDisp model) { if (ModelState.IsValid != false) { MeaDisp meaDisp = _context.MeaDisps.Include(m => m.Station) .Include(m => m.Seraphin) .Include(m => m.User) .Include(m => m.MeaItems) .ThenInclude(m => m.Dispenser) .Include(m => m.MeaItems) .ThenInclude(m => m.Hose) .FirstOrDefault(m => m.Id == model.Id); meaDisp.Date = model.Date; meaDisp.Observation = model.Observation; meaDisp.Number = model.Number; meaDisp.EndHour = model.EndHour; meaDisp.StartHour = model.StartHour; _context.Update(meaDisp); await _context.SaveChangesAsync(); return(RedirectToAction($"{nameof(DetailsMeaDisp)}/{meaDisp.Id}")); } return(RedirectToAction($"{nameof(DetailsMeaDisp)}/{model.Id}")); }
public async Task <IActionResult> Medidas(MeaDispViewModel model) { UserEntity user = await _userHelper.GetUserAsync(User.Identity.Name); if (ModelState.IsValid != false) { model.Id = 0; model.MeaItems = _context.MedTemps.Include(m => m.Dispenser).Include(m => m.Hose).ToList().Select(t => new MeaItem { Detail = t.Detail, Dispenser = t.Dispenser, Hose = t.Hose, Id = 0, Md1 = t.Md1, Md2 = t.Md2, Md3 = t.Md3 }).ToList(); if (model.MeaItems.Count > 0) { MeaDisp meaDisp = new MeaDisp { Date = model.Date, EndHour = model.EndHour, Id = 0, MeaItems = model.MeaItems, Number = model.Number, Observation = model.Observation, StartHour = model.StartHour, User = user, Station = _context.Stations.Where(s => s.Id == user.Station.Id).FirstOrDefault(), Seraphin = _context.Seraphin.Where(s => s.Station.Id == user.Station.Id).FirstOrDefault() }; _context.Add(meaDisp); List <MedTemp> aux = _context.MedTemps.ToList(); foreach (MedTemp item in aux) { _context.MedTemps.Remove(item); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Medidas))); } ViewBag.Error = "You must insert a measurement to the list"; List <MedTemp> medTemps = new List <MedTemp>(); model.MedTemps = medTemps; model.Seraphin = _context.Seraphin.Where(s => s.Station.Id == user.Station.Id).FirstOrDefault(); model.Station = _context.Stations.Where(s => s.Id == user.Station.Id).FirstOrDefault(); model.User = user; return(View(model)); } model.MedTemps = _context.MedTemps.Include(m => m.Hose).Include(m => m.Dispenser).ToList(); model.Seraphin = _context.Seraphin.Where(s => s.Station.Id == user.Station.Id).FirstOrDefault(); model.Station = _context.Stations.Where(s => s.Id == user.Station.Id).FirstOrDefault(); model.User = user; return(View(model)); }
public JsonResult GetHosesItem(int dispenserId, int meaDispId) { DispenserEntity dispenser = _context.Dispensers .Include(d => d.Hoses) .FirstOrDefault(d => d.Id == dispenserId); if (dispenser == null) { return(null); } List <HoseEntity> aux = dispenser.Hoses.ToList(); MeaDisp disp = _context.MeaDisps.Include(m => m.MeaItems) .ThenInclude(m => m.Hose).FirstOrDefault(m => m.Id == meaDispId); List <HoseEntity> disps = disp.MeaItems.Select(t => new HoseEntity { Id = t.Hose.Id, Number = t.Hose.Number, Type = t.Hose.Type }).ToList(); if (disps != null) { foreach (HoseEntity item in disps) { HoseEntity test = _context.Hoses.Find(item.Id); aux.Remove(test); } } return(Json(aux.OrderBy(h => h.Number))); }
public IActionResult AddIMeaItem(MedTempViewModel model) { if (ModelState.IsValid != false) { MeaDisp meaDisp = _context.MeaDisps.Include(m => m.Station) .Include(m => m.Seraphin) .Include(m => m.User) .Include(m => m.MeaItems) .ThenInclude(m => m.Dispenser) .Include(m => m.MeaItems) .ThenInclude(m => m.Hose) .FirstOrDefault(m => m.Id == model.IdMeaDips); MeaItem var = new MeaItem { Detail = model.Detail, Dispenser = _context.Dispensers.Find(model.DispenserId), Hose = _context.Hoses.Find(model.HoseId), Id = 0, Md1 = model.Md1, Md2 = model.Md2, Md3 = model.Md3 }; meaDisp.MeaItems.Add(var); _context.Update(meaDisp); _context.SaveChanges(); return(RedirectToAction($"{nameof(DetailsMeaDisp)}/{model.IdMeaDips}")); } return(View(model)); }