public async Task <IActionResult> Edit(int id, [Bind("Id,MerchDescription,MerchPrice,ApplicationUserId,ImagePath,MerchTypeId,Quantity,Small,Medium,Large,Xlarge,Xxlarge,AllSize")] Merch merch) { if (id != merch.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(merch); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MerchExists(merch.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["MerchTypeId"] = new SelectList(_context.MerchType, "Id", "Title", merch.MerchTypeId); return(View(merch)); }
public async Task <IActionResult> Edit(int id, [Bind("MerchId,Description,Title,Price,Quantity,UserId,MerchTypeId")] Merch merch) { if (id != merch.MerchId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(merch); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MerchExists(merch.MerchId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["MerchTypeId"] = new SelectList(_context.MerchType, "Id", "Id", merch.MerchTypeId); ViewData["UserId"] = new SelectList(_context.ApplicationUsers, "Id", "Id", merch.UserId); return(View(merch)); }
public async Task <IActionResult> Add(Merch merch) { _dbContext.Merch.Add(merch); await _dbContext.SaveChangesAsync(); var merches = await _dbContext.Merch.ToListAsync(); return(RedirectToAction("List")); }
public async Task <IActionResult> Create([Bind("MerchId,Description,Title,Price,Quantity,UserId,MerchTypeId")] Merch merch) { if (ModelState.IsValid) { _context.Add(merch); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["MerchTypeId"] = new SelectList(_context.MerchType, "Id", "Id", merch.MerchTypeId); ViewData["UserId"] = new SelectList(_context.ApplicationUsers, "Id", "Id", merch.UserId); return(View(merch)); }
public async Task <IActionResult> Create([Bind("Id,MerchDescription,MerchPrice,ApplicationUserId,ImagePath,MerchTypeId,Quantity,Small,Medium,Large,Xlarge,Xxlarge,AllSize")] Merch merch) { var user = await GetCurrentUserAsync(); merch.ApplicationUserId = user.Id; ModelState.Remove("ApplicationUserId"); if (ModelState.IsValid) { _context.Add(merch); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["MerchTypeId"] = new SelectList(_context.MerchType, "Id", "Title", merch.MerchTypeId); return(View(merch)); }
public async Task <IActionResult> Create([Bind("Id,MerchDescription,MerchPrice,UserId,ImagePath,MerchTypeId")] Merch merch) { //line to attach user's Id to merches userid // few line of code here to convert viewmodel to data model var user = await GetCurrentUserAsync(); merch.ApplicationUserId = user.Id; ModelState.Remove("ApplicationUserId"); if (ModelState.IsValid) { _context.Add(merch); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["MerchTypeId"] = new SelectList(_context.Set <MerchType>(), "Id", "Title", merch.MerchTypeId); return(View(merch)); }