public async Task <IActionResult> Edit(Guid barId, Guid userId, [Bind("BarId,UserId,Text,IsFlagged")] BarUserCommentView barUserComment) { if (barId != barUserComment.BarId || userId != barUserComment.UserId) { return(NotFound()); } if (ModelState.IsValid) { //try //{ var commentDTO = _mapper.MapViewToDTO(barUserComment); var result = await _service.UpdateAsync(commentDTO); //_context.Update(barUserComment); //await _context.SaveChangesAsync(); //} //catch (DbUpdateConcurrencyException) //{ // if (!BarUserCommentExists(barUserComment.BarId)) // { // return NotFound(); // } // else // { // throw; // } //} return(RedirectToAction(nameof(Index), new { barId = barUserComment.BarId })); } //ViewData["BarId"] = new SelectList(_context.Bars, "Id", "Address", barUserComment.BarId); //ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", barUserComment.UserId); return(View(barUserComment)); }
public async Task <IActionResult> Create([Bind("BarId,UserId,Text,IsFlagged")] BarUserCommentView barUserComment) { if (ModelState.IsValid) { try { await _service.CreateAsync(_mapper.MapViewToDTO(barUserComment)); return(RedirectToAction(nameof(Index), new { barId = barUserComment.BarId })); } catch (Exception) { return(Error()); } //barUserComment.BarId = Guid.NewGuid(); //_context.Add(barUserComment); //await _context.SaveChangesAsync(); //return RedirectToAction(nameof(Index)); } //ViewData["BarId"] = new SelectList(_context.Bars, "Id", "Address", barUserComment.BarId); //ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", barUserComment.UserId); return(View(barUserComment)); }