示例#1
0
 public async Task <ActionResult> Rate(DestinationRatingCreate model)
 {
     if (ModelState.IsValid)
     {
         var service = new RatingService(User.Identity.GetUserId());
         if (await service.CreateDestinationRatingAsync(model))
         {
             return(RedirectToAction(nameof(Index)));
         }
     }
     return(View(model));
 }
示例#2
0
        public async Task <ActionResult> Rate(int id)
        {
            var service = GetDestinationService();

            ViewBag.Detail = await service.GetDestinationByIdAsync(id);

            var model = new DestinationRatingCreate {
                DestinationId = id
            };

            return(View(model));
        }
        public async Task <bool> CreateDestinationRatingAsync(DestinationRatingCreate model)
        {
            var entity = new DestinationRating
            {
                Comment       = model.Comment,
                DestinationId = model.DestinationId,
                Grade         = model.Grade,
                UserId        = _userId,
                StayDate      = model.StayDate
            };

            _context.Ratings.Add(entity);
            var changeCount = await _context.SaveChangesAsync();

            return(changeCount == 1);
        }