public async Task <IActionResult> PutWishlistItem(long id, WishlistItem wishlistItem) { if (id != wishlistItem.Id) { return(BadRequest()); } _context.Entry(wishlistItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WishlistItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutProduct([FromRoute] int id, [FromBody] Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != product.IdProduct) { return(BadRequest()); } _context.Entry(product).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private async Task <Family> CreateFamilyModel(RegisterFamilyModel registration) { var family = new Family { ParentFirstName = registration.ParentFirstName, ParentLastName = registration.ParentLastName, Phone = registration.Phone, Email = registration.Email }; if (!registration.IsShippingToCharity) { family.ShippingAddress = new Address { LineOne = registration.ShippingAddress.LineOne, LineTwo = registration.ShippingAddress.LineTwo, City = registration.ShippingAddress.City, State = registration.ShippingAddress.State, PostalCode = registration.ShippingAddress.PostalCode }; } _db.Families.Add(family); await _db.SaveChangesAsync(); return(family); }
public async Task <ActionResult> Register(RegisterDonorViewModel registration) { var userManager = HttpContext.GetOwinContext().GetUserManager <WishlistUserManager>(); var user = await CreateDonor(registration, userManager); if (registration.DonorId.HasValue) { await AuthorizeDonorForUser(user, registration.DonorId.Value, userManager); await SendConfirmationEmail(user, userManager); await SignDonorIn(user, userManager); return(RedirectToAction("Index", "Home")); } var donor = new Donor(); _db.Donors.Add(donor); var cart = new Cart { Donor = donor, ModifiedDate = DateTime.Now }; _db.Carts.Add(cart); await _db.SaveChangesAsync(); await AuthorizeDonorForUser(user, donor.Id, userManager); await SendConfirmationEmail(user, userManager); await SignDonorIn(user, userManager); return(RedirectToAction("Index", "Home")); }
public async Task <ActionResult> AddItem(int id, string itemId) { var isItemOnWishlist = await( from wi in _db.WishlistItems where wi.WishlistId == id && wi.ItemId == itemId select wi ).AnyAsync(); if (isItemOnWishlist) { return(Json(new { IsOnWishlist = true })); } var wishItem = new WishlistItem { WishlistId = id, ItemId = itemId, Status = WishlistItemStatus.Unapproved, }; _db.WishlistItems.Add(wishItem); await _db.SaveChangesAsync(); return(Json(new { IsOnWishlist = true })); }
public async Task <ActionResult> EditProfile(int id, EditChildProfileModel edit) { if (!ModelState.IsValid) { edit.Id = id; return(View(edit)); } var bio = new ChildBiography { ChildId = id, CreationDate = DateTime.Now, Text = edit.BiographyText }; _db.Biographies.Add(bio); await _db.SaveChangesAsync(); TempData["profileSaved"] = true; return(RedirectToAction("EditProfile", new { id = id })); }