public static CommentModel ToCommentModel(this Z_Consultant_Comment entity)
        {
            var model = entity.MapTo <Z_Consultant_Comment, CommentModel>();

            model.Photos = entity.Photos.Select(b => b.Url).ToList();
            return(model);
        }
示例#2
0
        public Z_Consultant_Comment AddCommentByCustomer(CommentForPostModel CommentForPostDto, int customerId, IList <string> files, List <string> errors)
        {
            List <KeyAndValue> filesUrl = UploadFiles(files, errors);

            if (errors.Count > 0)
            {
                return(null);
            }
            var comment = new Z_Consultant_Comment()
            {
                Text        = CommentForPostDto.Text,
                PostId      = CommentForPostDto.PostId,
                CustomerId  = customerId,
                CommentedBy = CommentByTypes.Registered,
                DateCreated = DateTime.Now
            };

            foreach (var item in filesUrl)
            {
                if (item.Key.ToLower() == "image")
                {
                    comment.Photos.Add(new Z_Consultant_CommentPhoto()
                    {
                        Url = item.Value
                    });
                }
                //else if (item.Key.ToLower() == "video")
                //    post.Videos.Add(new Video()
                //    {
                //        Url = item.Value
                //    });
            }
            _commentRepository.Insert(comment);
            return(comment);
        }
 public static Z_Consultant_Comment ToEntity(this CommentModel model, Z_Consultant_Comment destination)
 {
     return(model.MapTo(destination));
 }
 public static CommentModel ToCommentModel(this Z_Consultant_Comment entity)
 {
     return(entity.MapTo <Z_Consultant_Comment, CommentModel>());
 }
示例#5
0
        public IActionResult GetComment(int CommentId)
        {
            Z_Consultant_Comment model = null;
            string commentOwner        = string.Empty;

            var postId = _commentService.GetPostIdByCommentId(CommentId);

            if (!_postService.IsClosed(postId))
            {
                if (!_workContext.CurrentCustomer.IsRegistered())
                {
                    return(Unauthorized());
                }

                var currentUserId = _workContext.CurrentCustomer.Id;


                if (_workContext.CurrentCustomer.IsInCustomerRole(RolesType.Consultant, true))
                {
                    ViewBag.UserRole = "Consultant";

                    if (_postService.IsConsultantAuthToPost(postId, currentUserId))
                    {
                        model        = _commentService.GetCommentByCommentIdAndConsultantId(CommentId, currentUserId);
                        commentOwner = model.Consultant.Username;
                    }
                    else
                    {
                        return(Forbid());
                    }
                }
                else if (_workContext.CurrentCustomer.IsInCustomerRole(RolesType.Registered, true))
                {
                    ViewBag.UserRole = "Registered";

                    if (_postService.IsCustomerAuthToPost(postId, currentUserId))
                    {
                        model        = _commentService.GetCommentByCommentIdAndCustomerId(CommentId, currentUserId);
                        commentOwner = model.Customer.Username;
                    }
                    else
                    {
                        return(Forbid());
                    }
                }
                else
                {
                    return(Unauthorized());
                }
            }
            else
            {
                model        = _commentService.GetComment(CommentId);
                commentOwner = (model.Customer == null) ? model.Consultant.Username : model.Customer.Username;
            }

            var modelToReturn = model.ToCommentModel();

            modelToReturn.CommentOwner = commentOwner;

            return(PartialView("~/Themes/Pavilion/Views/Consultant/Comment/_CommentTemplatePartial.cshtml", modelToReturn));
        }