public async Task <IActionResult> Create([Bind("Id,Name,UserID")] UserSpecificItemModel userSpecificItemModel) { // zhenying: does this work? if (ModelState.IsValid) { IdentityUser currentUser = await this._userManager.FindByNameAsync(User.Identity.Name); userSpecificItemModel.StoreUser = currentUser; _context.Add(userSpecificItemModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(userSpecificItemModel)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,UserID")] UserSpecificItemModel userSpecificItemModel) { if (id != userSpecificItemModel.Id) { return(NotFound()); } string username = User.Identity.Name; if (userSpecificItemModel.StoreUser.UserName != username) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(userSpecificItemModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserSpecificItemModelExists(userSpecificItemModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(userSpecificItemModel)); }