public ActionResult Create(Context model) { if (ModelState.IsValid) { model.ContextId = Guid.NewGuid(); this.DataContext.AddToContexts(model); return RedirectToAction("Index"); } return View(); }
public ActionResult Edit(Guid id, Context model) { if (ModelState.IsValid) { this.DataContext.Contexts.Single(x => x.ContextId == id); this.DataContext.Contexts.ApplyCurrentValues(model); return RedirectToAction("Index"); } return this.View(model); }
public ActionResult Delete(Guid id, Context model) { var entity = this.DataContext.Contexts.Include("Todos").Single(x => x.ContextId == id); if (entity.Todos.Count > 0) { ModelState.AddModelError(string.Empty, "Could not delete Context because there are To-Do items assigned to it."); return this.View(entity); } this.DataContext.Contexts.DeleteObject(entity); return RedirectToAction("Index"); }
/// <summary> /// Create a new Context object. /// </summary> /// <param name="contextId">Initial value of the ContextId property.</param> /// <param name="name">Initial value of the Name property.</param> public static Context CreateContext(global::System.Guid contextId, global::System.String name) { Context context = new Context(); context.ContextId = contextId; context.Name = name; return context; }
/// <summary> /// Deprecated Method for adding a new object to the Contexts EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToContexts(Context context) { base.AddObject("Contexts", context); }