예제 #1
0
 /// <summary>
 /// This the commit method which is called just once during a database transaction.
 /// </summary>
 /// <returns></returns>
 public int Complete()
 {
     try
     {
         _context.SaveChanges();
         return(1);
     }
     catch (Exception ex)
     {
         return(0);
     }
 }
예제 #2
0
 public ActionResult Delete(int id)
 {
     using (var db = new AngularDemoContext())
     {
         var existing = db.Beer.FirstOrDefault(x => x.Id == id);
         if (existing != null)
         {
             db.Beer.Remove(existing);
             db.SaveChanges();
         }
     }
     return(RedirectToAction("Index", "Beer"));
 }
예제 #3
0
        public ActionResult Edit(BeerEditVM model)
        {
            Thread.Sleep(2000);
            if (ModelState.IsValid)
            {
                using (var db = new AngularDemoContext())
                {
                    var beer = new Beer()
                    {
                        Name     = model.Name,
                        Colour   = model.Colour,
                        HasTried = model.HasTried
                    };

                    db.Beer.Add(beer);
                    db.SaveChanges();

                    return(Json(beer, JsonRequestBehavior.AllowGet));
                }
            }
            throw new HttpException(400, "error");
        }