public async Task <IActionResult> Create([Bind("ID,Top,Bottom,UserId, TopImage, TopName, BottomImage, BottomFile")] MixnMatch mixnMatch) { ViewBag.userid = _userManager.GetUserId(HttpContext.User); if (ModelState.IsValid) { //Get file based on chosen wardrobe string top = mixnMatch.Top; if (!String.IsNullOrEmpty(top)) { var usermatch = _context.Wardrobe.FirstOrDefault(m => m.Name.Contains(top)); mixnMatch.TopUrl = usermatch.ImageUrl; mixnMatch.TopFile = usermatch.FileName; } string bottom = mixnMatch.Bottom; if (!String.IsNullOrEmpty(top)) { var usermatch = _context.Wardrobe.FirstOrDefault(m => m.Name.Contains(bottom)); mixnMatch.BottomUrl = usermatch.ImageUrl; mixnMatch.BottomFile = usermatch.FileName; } _context.Add(mixnMatch); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(mixnMatch)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Top,Bottom,UserId")] MixnMatch mixnMatch) { if (id != mixnMatch.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(mixnMatch); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MixnMatchExists(mixnMatch.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(mixnMatch)); }
public async Task <IActionResult> Create([Bind("ID,Top,Bottom,UserId")] MixnMatch mixnMatch) { ViewBag.userid = _userManager.GetUserId(HttpContext.User); if (ModelState.IsValid) { _context.Add(mixnMatch); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(mixnMatch)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Top,Bottom,UserId, TopImage, TopName, BottomImage, BottomFile")] MixnMatch mixnMatch) { if (id != mixnMatch.ID) { return(NotFound()); } if (ModelState.IsValid) { try { //Get file based on chosen wardrobe string top = mixnMatch.Top; if (!String.IsNullOrEmpty(top)) { var usermatch = _context.Wardrobe.FirstOrDefault(m => m.Name.Contains(top)); mixnMatch.TopUrl = usermatch.ImageUrl; mixnMatch.TopFile = usermatch.FileName; } string bottom = mixnMatch.Bottom; if (!String.IsNullOrEmpty(top)) { var usermatch = _context.Wardrobe.FirstOrDefault(m => m.Name.Contains(bottom)); mixnMatch.BottomUrl = usermatch.ImageUrl; mixnMatch.BottomFile = usermatch.FileName; } _context.Update(mixnMatch); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MixnMatchExists(mixnMatch.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(mixnMatch)); }