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 async Task <IActionResult> Medidas()
        {
            UserEntity user = await _userHelper.GetUserAsync(User.Identity.Name);

            MeaDispViewModel measurement = new MeaDispViewModel
            {
                Station  = _context.Stations.Where(s => s.Id == user.Station.Id).FirstOrDefault(),
                Seraphin = _context.Seraphin.Where(s => s.Station.Id == user.Station.Id).FirstOrDefault(),
                User     = user,
                Date     = DateTime.Now,
                MedTemps = _context.MedTemps
                           .Include(m => m.Dispenser)
                           .Include(m => m.Hose)
                           .OrderBy(m => m.Dispenser.Name)
                           .ThenBy(m => m.Hose.Number)
                           .ToList(),
                Number = NextNumber()
            };

            return(View(measurement));
        }