public IHttpActionResult PutMarcas(int id, Marcas marcas) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != marcas.IdMarca) { return(BadRequest()); } db.Entry(marcas).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!MarcasExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "IdTipos,Tipo,Descripcion,Alta,Operador,imagen,ActInac,NombreTipo")] Tipos tipos) { if (ModelState.IsValid) { db.Tipos.Add(tipos); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tipos)); }
public ActionResult Create([Bind(Include = "IdUsuario,Usuario,Nivel,Localidad")] Usuarios usuarios) { if (ModelState.IsValid) { db.usuarios.Add(usuarios); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(usuarios)); }
public ActionResult Create(MarcasView view) { if (view == null) { ViewBag.DropDownTipos = (from c in db.Tipos select new { c.IdTipos, c.NombreTipo }).Distinct(); ViewBag.ResultMessage = "COMPLETA LOS CAMPOS POR FAVOR!!"; return(View(view)); } view.Alta = DateTime.Now; if (!ModelState.IsValid) { ViewBag.DropDownTipos = (from c in db.Tipos select new { c.IdTipos, c.NombreTipo }).Distinct(); ViewBag.ResultMessage = "ALGUN CAMPO NO ES ADMITIDO REVISA POR FAVOR"; return(View(view)); } using (var transaction = db.Database.BeginTransaction()) { try { view.Imagen = "NULL"; var pic = string.Empty; var folder = "~/Images/Brands"; if (view.ImageFile != null) { pic = FileHelper.UploadPhoto(view.ImageFile, folder); pic = string.Format("{0}/{1}", folder, pic); } var Marcas = newMarca(view); Marcas.Imagen = pic; db.Marcas.Add(Marcas); db.SaveChanges(); transaction.Commit(); ViewBag.ResultMessage = "1"; ViewBag.DropDownTipos = (from c in db.Tipos select new { c.IdTipos, c.NombreTipo }).Distinct(); view = null; return(View());//POR SI DESEA AGREGAR MAS //return RedirectToAction("Index"); } catch (Exception) { transaction.Rollback(); ViewBag.ResultMessage = "0"; } } ViewBag.ResultMessage = "1"; ViewBag.DropDownTipos = (from c in db.Tipos select new { c.IdTipos, c.NombreTipo }).Distinct(); return(View()); #region MyRegion //if (ModelState.IsValid) //{ // var pic = string.Empty; // var folder = "~/Images/Brands"; // if (view.ImageFile != null) // { // pic = FileHelper.UploadPhoto(view.ImageFile, folder); // pic = string.Format("{0}/{1}", folder, pic); // } // var Marcas = newMarca(view); // Marcas.Imagen = pic; // db.marcas.Add(Marcas); // db.SaveChanges(); // return RedirectToAction("Index"); //} //return View(view); #endregion }