示例#1
0
 public ActionResult Edit(Review review)
 {
     try
     {
         db.Entry(review).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch (DbUpdateConcurrencyException ex)
     {
         var entry         = ex.Entries.Single();
         var clientValues  = (Review)entry.Entity;
         var databaseEntry = entry.GetDatabaseValues();
         if (databaseEntry == null)
         {
             ModelState.AddModelError(string.Empty, "Unable to save changes.the review was deleted by another user.");
         }
         else
         {
             var databaseValues = (Review)databaseEntry.ToObject();
             if (databaseValues.Title != clientValues.Title)
             {
                 ModelState.AddModelError("Title", "Current Value:" + databaseValues.Title);
             }
             if (databaseValues.Description != clientValues.Description)
             {
                 ModelState.AddModelError("Description", "Current Value:" + databaseValues.Description);
             }
             if (databaseValues.Name != clientValues.Name)
             {
                 ModelState.AddModelError("Head1", "Current Value:" + databaseValues.Name);
             }
             if (databaseValues.City != clientValues.City)
             {
                 ModelState.AddModelError("Head2", "Current Value:" + databaseValues.City);
             }
             if (databaseValues.Image != clientValues.Image)
             {
                 ModelState.AddModelError("Image", "Current Value:" + databaseValues.Image);
             }
             ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you got the original value. The" + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to edit this record, click " + "the Save button again. Otherwise click the Back to List hyperlink.");
             review.RowVersion = databaseValues.RowVersion;
         }
     }
     catch (RetryLimitExceededException)
     {
         ModelState.AddModelError(string.Empty, "Unable to save changes. Try again, and if the problem persists contact your system administrator.");
     }
     return(View(review));
 }
示例#2
0
        public ActionResult Edit(Product product)
        {
            try
            {
                db.Entry(product).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch (DbUpdateConcurrencyException ex)
            {
                var entry         = ex.Entries.Single();
                var clientValues  = (Product)entry.Entity;
                var databaseEntry = entry.GetDatabaseValues();
                if (databaseEntry == null)
                {
                    ModelState.AddModelError(string.Empty, "Unable to save changes.The feature was deleted by another  user.");
                }
                else
                {
                    var databaseValues = (Product)databaseEntry.ToObject();
                    if (databaseValues.FeatureID != clientValues.FeatureID)
                    {
                        ModelState.AddModelError("FeatureID", "Current Value:" + db.Features.Find(databaseValues.FeatureID));
                    }
                    if (databaseValues.TypeWatchID != clientValues.TypeWatchID)
                    {
                        ModelState.AddModelError("TypeWatchID", "Current Value:" + db.TypesWatches.Find(databaseValues.TypeWatchID));
                    }
                    ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you got the original value. The" + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to edit this record, click " + "the Save button again. Otherwise click the Back to List hyperlink.");
                    product.RowVersion = databaseValues.RowVersion;
                }
            }
            catch (RetryLimitExceededException)
            {
                ModelState.AddModelError(string.Empty, "Unable to save changes. Try again, and if the problem persists contact your system administrator.");
            }


            ViewBag.FeatureID   = new SelectList(db.Features, "FeatureID", "FeatureID", product.FeatureID);
            ViewBag.TypeWatchID = new SelectList(db.TypesWatches, "TypeWatchID", "TypeWatchID", product.TypeWatchID);
            return(View(product));
        }