예제 #1
0
        public async Task <IActionResult> Reviews(ReviewViewModel model)
        {
            var id     = GetVendorID();
            var vendor = await _vendorService.GetVendorAsync(id);

            var user = await _userManager.GetUserAsync(User);

            if (vendor == null)
            {
                return(NotFound());
            }

            if (!string.IsNullOrWhiteSpace(Request.Form["vendorReply"]))
            {
                var index = int.Parse(Request.Form["postReview"]);

                await _reviewsService.AddReplyAsync(id, index, Request.Form["vendorReply"], vendor.Title);
            }

            if (!string.IsNullOrWhiteSpace(Request.Form["comment"]) && (int.Parse(Request.Form["starRating"]) != 0))
            {
                var commentId = int.Parse(Request.Form["listItemCount"]);
                var stars     = int.Parse(Request.Form["starRating"]);
                var userName  = (user != null) ? user.UserName : "******";
                new Review(id, commentId, userName, Request.Form["comment"], stars, vendor.Title);
            }

            return(await Reviews());
        }