Exemplo n.º 1
0
        public JsonResult GetHoses(int dispenserId)
        {
            DispenserEntity dispenser = _context.Dispensers
                                        .Include(d => d.Hoses)
                                        .FirstOrDefault(d => d.Id == dispenserId);

            if (dispenser == null)
            {
                return(null);
            }
            List <HoseEntity> aux = dispenser.Hoses.ToList();

            List <HoseEntity> disps = _context.MedTemps.Include(m => m.Hose).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);
                }
            }
            JsonResult x = Json(aux.OrderBy(c => c.Number));

            return(Json(aux.OrderBy(h => h.Number)));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> DeleteHose(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }



            HoseEntity hose = await _context.Hoses
                              .FirstOrDefaultAsync(m => m.Id == id);

            if (hose == null)
            {
                return(NotFound());
            }
            DispenserEntity disp = _context.Dispensers
                                   .Include(d => d.Hoses)
                                   .Where(d => d.Hoses.Contains(hose))
                                   .FirstOrDefault();

            _context.Hoses.Remove(hose);
            await _context.SaveChangesAsync();



            return(RedirectToAction($"{nameof(DetailsDispenser)}/{disp.Id}"));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> AddHose(HoseEntity hose)
        {
            if (ModelState.IsValid)
            {
                DispenserEntity dispenser = await _context.Dispensers
                                            .Include(c => c.Hoses)
                                            .FirstOrDefaultAsync(c => c.Id == hose.IdDispenser);

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

                switch (hose.Type)
                {
                case "1":
                    hose.Type = TypeFuel.Regular.ToString();
                    break;

                case "0":
                    hose.Type = TypeFuel.Diesel.ToString();
                    break;

                case "2":
                    hose.Type = TypeFuel.Super.ToString();
                    break;

                case "3":
                    hose.Type = TypeFuel.Exonerado.ToString();
                    break;
                }

                try
                {
                    hose.Id = 0;
                    dispenser.Hoses.Add(hose);
                    _context.Update(dispenser);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction($"{nameof(DetailsDispenser)}/{dispenser.Id}"));
                }
                catch (DbUpdateException dbUpdateException)
                {
                    if (dbUpdateException.InnerException.Message.Contains("duplicate"))
                    {
                        ModelState.AddModelError(string.Empty, "There are a record with the same name.");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message);
                    }
                }
                catch (Exception exception)
                {
                    ModelState.AddModelError(string.Empty, exception.Message);
                }
            }

            return(View(hose));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> EditHose(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            HoseEntity hose = await _context.Hoses.FindAsync(id);

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


            return(View(hose));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> AddHose(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            DispenserEntity dispenser = await _context.Dispensers.FindAsync(id);

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

            HoseEntity model = new HoseEntity {
                IdDispenser = dispenser.Id
            };

            return(View(model));
        }