예제 #1
0
        public async Task <IActionResult> Create([Bind("ID,BeerID,UserID,Rating,Description,LikesCount,IsDeleted,IsFlagged")] ReviewViewModel review)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await _service.CreateAsync(review.MapReviewViewToDTO());

                    return(RedirectToAction(nameof(Details), "Beers", new { id = review.BeerID }));
                }
                catch (Exception)
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            ViewData["BeerID"] = _beerService.GetAsync(review.BeerID);
            ViewData["UserID"] = _userService.GetUser(review.UserID);
            return(View(review));
        }
예제 #2
0
        public async Task <IActionResult> Edit(int?id, [Bind("ID,BeerID,UserID,Rating,Description,LikesCount,IsDeleted,IsFlagged")] ReviewViewModel review)
        {
            if (id != review.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var updateModel = review.MapReviewViewToDTO();
                    await _service.UpdateAsync(id, updateModel);
                }
                catch (Exception)
                {
                    return(NotFound());
                }
                return(RedirectToAction(nameof(Details), "BeersController", review.BeerID));
            }
            ViewData["BeerID"] = new SelectList(_beerService.GetAllAsync().Result, "ID", "Name");
            ViewData["UserID"] = new SelectList(_userService.GetAllUsers().Result, "Id", "Name");
            return(View(review));
        }