public async Task <IActionResult> Edit(int id, [Bind("GalleryEntryID,ApplicationUserID")] GalleryEntry_ApplicationUser galleryEntry_ApplicationUser) { if (id != galleryEntry_ApplicationUser.GalleryEntryID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(galleryEntry_ApplicationUser); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GalleryEntry_ApplicationUserExists(galleryEntry_ApplicationUser.GalleryEntryID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } ViewData["ApplicationUserID"] = new SelectList(_context.ApplicationUsers, "Id", "Id", galleryEntry_ApplicationUser.ApplicationUserID); ViewData["GalleryEntryID"] = new SelectList(_context.GalleryEntries, "GalleryEntryID", "GalleryEntryID", galleryEntry_ApplicationUser.GalleryEntryID); return(View(galleryEntry_ApplicationUser)); }
public async Task <IActionResult> Create([Bind("GalleryEntryID,ApplicationUserID")] GalleryEntry_ApplicationUser galleryEntry_ApplicationUser) { if (ModelState.IsValid) { _context.Add(galleryEntry_ApplicationUser); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["ApplicationUserID"] = new SelectList(_context.ApplicationUsers, "Id", "Id", galleryEntry_ApplicationUser.ApplicationUserID); ViewData["GalleryEntryID"] = new SelectList(_context.GalleryEntries, "GalleryEntryID", "GalleryEntryID", galleryEntry_ApplicationUser.GalleryEntryID); return(View(galleryEntry_ApplicationUser)); }
public async Task <IActionResult> PostGalleryEntry_ApplicationUser([FromBody] GalleryEntry_ApplicationUser galleryEntry_ApplicationUser) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = await _userManager.GetUserAsync(User); if (user != null) { galleryEntry_ApplicationUser.ApplicationUserID = user.Id; if (UserHasLiked(galleryEntry_ApplicationUser.GalleryEntryID, galleryEntry_ApplicationUser.ApplicationUserID)) { _context.GalleryEntry_ApplicationUser.Remove(galleryEntry_ApplicationUser); } else { _context.GalleryEntry_ApplicationUser.Add(galleryEntry_ApplicationUser); } } else { return(new StatusCodeResult(StatusCodes.Status401Unauthorized)); } try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (GalleryEntry_ApplicationUserExists(galleryEntry_ApplicationUser.GalleryEntryID)) { // This is what happens when the user favorites something that has already been favorited. // Decision has been to ignore this. return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetGalleryEntry_ApplicationUser", new { id = galleryEntry_ApplicationUser.GalleryEntryID }, galleryEntry_ApplicationUser)); }
public async Task <IActionResult> PutGalleryEntry_ApplicationUser([FromRoute] int id, [FromBody] GalleryEntry_ApplicationUser galleryEntry_ApplicationUser) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != galleryEntry_ApplicationUser.GalleryEntryID) { return(BadRequest()); } _context.Entry(galleryEntry_ApplicationUser).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GalleryEntry_ApplicationUserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }