//
        // GET: /PelotonCombinadas/Delete/5

        public ActionResult Delete(int id = 0)
        {
            PelotonCombinadas pelotoncombinadas = db.PelotonCombinadas.Find(id);

            if (pelotoncombinadas == null)
            {
                return(HttpNotFound());
            }
            return(View(pelotoncombinadas));
        }
 public ActionResult DeleteConfirmed(int id)
 {
     try
     {
         PelotonCombinadas pelotoncombinadas = db.PelotonCombinadas.Find(id);
         db.PelotonCombinadas.Remove(pelotoncombinadas);
         db.SaveChanges();
     }
     catch (Exception exception)
     {
         throw new Exception("Este registro tiene relación con otros y no se puede borrar");
     }
     return(RedirectToAction("Index"));
 }
        //
        // GET: /PelotonCombinadas/Edit/5

        public ActionResult Edit(int id = 0)
        {
            PelotonCombinadas pelotoncombinadas = db.PelotonCombinadas.Find(id);

            if (pelotoncombinadas == null)
            {
                return(HttpNotFound());
            }
            var p = from it in db.Suministradores
                    where it.activo
                    select
                    new { it.id, data = it.TiposSectorPropiedad.nombreTipoSector + " " + it.nombreSuministrador };

            ViewBag.Suministradoresid = new SelectList(p, "id", "data", pelotoncombinadas.Suministradoresid);
            return(View(pelotoncombinadas));
        }
        public ActionResult Edit(PelotonCombinadas pelotoncombinadas)
        {
            var peloton = db.PelotonCombinadas.FirstOrDefault(pe => pe.Suministradoresid == pelotoncombinadas.Suministradoresid && pe.id != pelotoncombinadas.id);

            if (peloton != null)
            {
                ModelState.AddModelError("", "Ya existe un peloton para este suministrador");
            }
            if (ModelState.IsValid)
            {
                db.Entry(pelotoncombinadas).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            var p = from it in db.Suministradores
                    where it.activo
                    select
                    new { it.id, data = it.TiposSectorPropiedad.nombreTipoSector + " " + it.nombreSuministrador };

            ViewBag.Suministradoresid = new SelectList(p, "id", "data", pelotoncombinadas.Suministradoresid);
            return(View(pelotoncombinadas));
        }