예제 #1
0
        private async Task <CommentRatingDTO> GetCommentRatingDTOFromModel(CommentRatingModel rating, string userId, string commentId)
        {
            UserDTO user = await _userService.GetUserById(userId);

            return(new CommentRatingDTO {
                CommentId = commentId,
                ApplicationUserId = userId,
                GivenRating = rating.givenRating
            });
        }
예제 #2
0
        public ActionResult CommentRating(Guid commentId, Guid storeItemId)
        {
            CommentRatingModel model = new CommentRatingModel()
            {
                Id          = Guid.NewGuid(),
                CommentId   = commentId,
                StoreItemId = storeItemId,
            };

            return(View(model));
        }
예제 #3
0
        public static void UpdateCommentRating(CommentRatingModel model)
        {
            UnitOfWorkRepository unitOfWork = new UnitOfWorkRepository();

            if (model == null)
            {
                return;
            }

            var commentRating = ConvertToCommentRating(model);

            unitOfWork.CommentRatingRepository.Update(commentRating);
        }
예제 #4
0
        public static void AddCommentRating(CommentRatingModel model)
        {
            var commentRating = ConvertToCommentRating(model);

            if (commentRating == null)
            {
                return;
            }

            UnitOfWorkRepository unitOfWork = new UnitOfWorkRepository();

            unitOfWork.UserCommentRepository.AddCommentRating(commentRating);
        }
예제 #5
0
        public async Task <IActionResult> CreateCommentRating([Required] string id, [FromBody] CommentRatingModel item)
        {
            if (ModelState.IsValid && User.Identity.IsAuthenticated)
            {
                ApplicationUser user = await _authenticationManager.UserManager.FindByNameAsync(User.Identity.Name);

                CommentRatingDTO commentRating = await GetCommentRatingDTOFromModel(item, user.Id, id);

                commentRating = await _commentRatingService.Create(commentRating);

                return(Ok(await GetCommentRatingModelFromDTO(commentRating)));
            }

            return(BadRequest(ModelState));
        }
예제 #6
0
        public ActionResult CommentRating(CommentRatingModel model)
        {
            string identity = User.Identity.Name;
            Guid   userId   = Guid.Parse(identity);

            if (model == null)
            {
                return(View(model));
            }

            model.OwnerId     = userId;
            model.Id          = Guid.NewGuid();
            model.DataCreated = DateTime.Now;

            CommentProcessor.AddCommentRating(model);
            return(RedirectToAction("Details", "Products", new { id = model.StoreItemId }));
        }
예제 #7
0
        public static CommentRating ConvertToCommentRating(CommentRatingModel model)
        {
            if (model == null)
            {
                return(null);
            }

            CommentRating commentRating = new CommentRating()
            {
                Id          = model.Id,
                CommentId   = model.CommentId,
                OwnerId     = model.OwnerId,
                storeItemId = model.StoreItemId,
                DataCreated = model.DataCreated,
                Rating      = model.Rating,
                DownVote    = model.DownVote,
                UpVote      = model.UpVote,
                Reported    = model.Report,
                ReportText  = model.OpinionText,
            };

            return(commentRating);
        }
예제 #8
0
        public static CommentRatingModel ConvertToCommentRatingModel(CommentRating commentRating)
        {
            if (commentRating == null)
            {
                return(null);
            }

            CommentRatingModel model = new CommentRatingModel()
            {
                Id          = commentRating.Id,
                CommentId   = commentRating.CommentId,
                OwnerId     = commentRating.OwnerId,
                StoreItemId = commentRating.storeItemId,
                DataCreated = commentRating.DataCreated,
                Rating      = commentRating.Rating,
                DownVote    = commentRating.DownVote,
                UpVote      = commentRating.UpVote,
                Report      = commentRating.Reported,
                OpinionText = commentRating.ReportText,
            };

            return(model);
        }
예제 #9
0
 public ActionResult EditCommentRating(CommentRatingModel model)
 {
     CommentProcessor.UpdateCommentRating(model);
     return(RedirectToAction("Details", "Products", new { id = model.StoreItemId }));
 }