public ActionResult NewWishlistItem(WishlistIDModel wlreq) { using (var db = new WishlistContext()) { var wl = db.Wishlists.FirstOrDefault(wl2 => wl2.WishlistId == wlreq.ID); if (wl == null) { return(Json(new { Success = false, Exception = "Invalid wishlist id." })); } else if (wl.UserId != WebSecurity.CurrentUserId) { return(Json(new { Success = false, Exception = "Add requested by an unauthorized user." })); } else { var wli = new Models.WishlistItem { WishlistId = wl.WishlistId, WishlistItemContent = "New Wishlist Item" }; db.WishlistItems.Add(wli); db.SaveChanges(); return(Json(new { Success = true, Result = new WishlistItemJsonModel { ID = wli.WishlistItemId, Content = wli.WishlistItemContent } })); } } }
public ActionResult RemoveWishlist(WishlistIDModel wlreq) { using (var db = new WishlistContext()) { var wl = db.Wishlists.FirstOrDefault(wl2 => wl2.WishlistId == wlreq.ID); if (wl == null) { return(Json(new { Success = false, Exception = "Invalid wishlist id." })); } else if (wl.UserId != WebSecurity.CurrentUserId) { return(Json(new { Success = false, Exception = "Removal requested by an unauthorized user." })); } else { foreach (var wli in wl.WishlistItems.ToList()) { db.WishlistItems.Remove(wli); } db.Wishlists.Remove(wl); db.SaveChanges(); return(Json(new { Success = true })); } } }