コード例 #1
0
 public ActionResult Create(Category Model)
 {
     if (!this.ModelState.IsValid)
     {
         this.View(Model);
     }
     Model.EntityId = Guid.NewGuid();
     Model.CreatedBy = this.User.Identity.Name;
     Model.CreatedOn = DateTime.Now;
     Context.Categories.Add(Model);
     Context.SaveChanges();
     return this.RedirectToAction("Index");
 }
コード例 #2
0
 public ActionResult Edit(Category Model)
 {
     //development chagne
     var category = this.Context.Categories.Find(Model.Id);
     if (category == null)
     {
         return this.HttpNotFound();
     }
     else
     {
         try
         {
             this.UpdateModel(category, "", new string[] { "Name", "Description" });
             this.Context.SaveChanges();
             return this.RedirectToAction("Index");
         }
         catch (Exception ex)
         {
             this.ModelState.AddModelError("", ex);
             return this.View(category);
         }
     }
 }