public ActionResult AddToCart(int partNumber, string encryptedUserToken, string PartDescription, int VehID) { string result = "OK"; var per = Crypto.DecryptID(encryptedUserToken); if (per == -1) { throw new Exception("person invalid"); } var cartEntry = new Models.ShoppingCart(); cartEntry.DateAdded = DateTime.Now; cartEntry.PersonID = Crypto.DecryptID(encryptedUserToken); if (partNumber != -1) { cartEntry.PartNumber = partNumber; } cartEntry.PartDescription = PartDescription; cartEntry.Quantity = 1; cartEntry.Status = "Shopping"; cartEntry.IsDeleted = false; cartEntry.Save(); return(Content(result, "text/html")); }
protected ActionResult ProcessForm(Models.ShoppingCart record) { try { record.UpdateFromRequest(); Validate(record); if (ModelState.IsValid) { Save(record, record.IsNewRecord); Web.InfoMessage = "Shopping Cart " + record.GetName() + " saved."; } } catch (Exception e) { ModelState.AddModelError("Record", e.Message); } if (!ModelState.IsValid) { // invalid so redisplay form with validation message(s) return(View("ShoppingCartEdit", record)); } else if (Web.Request["SaveAndRefreshButton"] != null) { return(RedirectToEdit(record.ID)); } else if (Web.Request["DuplicateButton"] != null) { var newRecord = new Models.ShoppingCart(); newRecord.UpdateFrom(record); newRecord.Save(); Web.InfoMessage = "Copy of Shopping Cart " + record.GetName() + " created. You are now editing the new copy."; return(RedirectToEdit(newRecord.ID)); } else { return(RedirectToReturnPage()); } }
private void Save(Models.ShoppingCart record, bool isNew) { // add any code to update other fields/tables here record.Save(); }