public async Task <ActionResult> Create([Bind(Include = "MeshId,Name,CustValue,Yeild,Sublimation,MeasureId,ColorMeshId,DataCreate")] Mesh mesh) { if (ModelState.IsValid) { try{ db.Meshes.Add(mesh); await db.SaveChangesAsync(); } catch (System.Exception ex) { if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("Mesh_Name_Index")) { ModelState.AddModelError(string.Empty, "Não é possível inserir com o mesmo nome!"); } else { ModelState.AddModelError(string.Empty, ex.Message); } ViewBag.MeasureId = new SelectList(CombosHelper.GetMeasures(), "MeasureId", "Name", mesh.MeasureId); ViewBag.ColorMeshId = new SelectList(CombosHelper.GetColors(), "ColorMeshId", "Color", mesh.ColorMeshId); return(View(mesh)); } } ViewBag.ColorMeshId = new SelectList(CombosHelper.GetColors(), "ColorMeshId", "Color", mesh.ColorMeshId); ViewBag.MeasureId = new SelectList(CombosHelper.GetMeasures(), "MeasureId", "Name", mesh.MeasureId); return(View(mesh)); }
// GET: Meshes/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Mesh mesh = await db.Meshes.FindAsync(id); if (mesh == null) { return(HttpNotFound()); } ViewBag.ColorMeshId = new SelectList(CombosHelper.GetColors(), "ColorMeshId", "Color", mesh.ColorMeshId); ViewBag.MeasureId = new SelectList(CombosHelper.GetMeasures(), "MeasureId", "Name", mesh.MeasureId); return(View(mesh)); }
// GET: Meshes/Create public ActionResult Create() { ViewBag.ColorMeshId = new SelectList(CombosHelper.GetColors(), "ColorMeshId", "Color"); ViewBag.MeasureId = new SelectList(CombosHelper.GetMeasures(), "MeasureId", "Name"); return(View()); }