public ActionResult Edit(Part part) { if (ModelState.IsValid && Part.Update(part)) { return RedirectToAction("Index"); } ViewBag.Category_id = new SelectList(Category.All(), "Id", "Name", part.Category_id); ViewBag.Vendor_id = new SelectList(Vendor.All(), "Id", "Name", part.Vendor_id); return View(part); }
public static bool Create(Part part) { bool result = true; try { db.Parts.AddObject(part); db.SaveChanges(); } catch (Exception) { result = false; } return result; }
public static bool Update(Part part) { bool result = true; try { EntityDataModelContainer mc = new EntityDataModelContainer(); mc.Parts.Attach(part); mc.ObjectStateManager.ChangeObjectState(part, EntityState.Modified); mc.SaveChanges(); db.Refresh(System.Data.Objects.RefreshMode.StoreWins, part); } catch (Exception) { result = false; } return result; }
/// <summary> /// Deprecated Method for adding a new object to the Parts EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToParts(Part part) { base.AddObject("Parts", part); }
/// <summary> /// Create a new Part object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="category_id">Initial value of the Category_id property.</param> /// <param name="vendor_id">Initial value of the Vendor_id property.</param> /// <param name="part_num">Initial value of the Part_num property.</param> /// <param name="description">Initial value of the Description property.</param> public static Part CreatePart(global::System.Int32 id, global::System.Int32 category_id, global::System.Int32 vendor_id, global::System.String part_num, global::System.String description) { Part part = new Part(); part.Id = id; part.Category_id = category_id; part.Vendor_id = vendor_id; part.Part_num = part_num; part.Description = description; return part; }