Beispiel #1
0
        public ResponseModel <string> AddPhotoComment(PhotoCommentModel model)
        {
            ResponseModel <string> response = new ResponseModel <string> {
                Data = ""
            };

            try
            {
                PhotoComment _comment = new PhotoComment();
                _comment.PhotoId   = model.PhotoId;
                _comment.IsActive  = true;
                _comment.CreatedOn = DateTime.Now;
                _comment.Comment   = model.Comment;
                acmContext.PhotoComment.Add(_comment);
                acmContext.SaveChanges();
                response.Status  = true;
                response.Message = "success";
            }
            catch (Exception ex)
            {
                response.Status  = false;
                response.Message = ex.Message;
            }
            return(response);
        }
Beispiel #2
0
        public void SomeoneRepliedToCommentEvent(PhotoCommentModel mcomment)
        {
            SomeoneRepliedToCommentHandler handler = SomeoneRepliedToComment;

            if (handler != null)
            {
                handler(mcomment);
            }
        }
Beispiel #3
0
        public void PushCommentAddedEvent(PhotoCommentModel mComment)
        {
            CommentAddedHandler handler = CommentAdded;

            if (handler != null)
            {
                handler(mComment);
            }
        }
        public IActionResult AddProfile([FromBody] PhotoCommentModel model)
        {
            var result = _commentManager.AddPhotoComment(model);

            if (result.Status)
            {
                return(Ok(result));
            }
            else
            {
                return(StatusCode(404, result));
            }
        }
        public void SomeoneRepliedToComment(PhotoCommentModel mComment)
        {
            var mWhoseComment = _userService.GetUser(mComment.UserId);

            var mParentComment = _commentService.GetPhotoComment(mComment.Reply);

            var mParentCommentOwner = _userService.GetUser(mParentComment.UserId);

            mParentCommentOwner.Email = mParentCommentOwner.Email.ToLower(); // todo: remove and refactor, when id to cookies will be added

            var noty = String.Format("Пользователь <span class='highlight_from'>{0} {1}</span> " +
                                     "ответил на ваш комментарий к фотографии."
                                     , mWhoseComment.FirstName, mWhoseComment.LastName);

            _hubNotify.Clients.Group(mParentCommentOwner.Email)
            .SendNotification(NotificationTitles.CommentAdded, noty, _urlUtil.BuildCommentUrl(mComment.PhotoId, mComment.Id));
        }
        public void PhotoCommentAddedNotify(PhotoCommentModel mComment)
        {
            // TODO by Mikhail: mComment.UserId and mUser.Id are the same always
            var mUser  = _userService.GetUser(mComment.UserId); // TODO this is a redundant line
            var mPhoto = _photoService.GetPhoto(mUser.Id, mComment.PhotoId);

            if (mPhoto.OwnerId != mComment.UserId)
            {
                var mPhotoOwner = _userService.GetUser(mPhoto.OwnerId);

                mPhotoOwner.Email = mPhotoOwner.Email.ToLower(); // todo: remove and refactor, when id to cookies will be added

                var noty = String.Format("Пользователь <span class='highlight_from'>{0} {1}</span> " +
                                         "добавил комментарий к вашей фотографии."
                                         , mUser.FirstName, mUser.LastName);
                _hubNotify.Clients.Group(mPhotoOwner.Email).SendNotification(NotificationTitles.CommentAdded, noty, _urlUtil.BuildPhotoViewUrl(mPhoto.Id));
            }
        }
Beispiel #7
0
        public void AddPhotoComment(int userId, PhotoCommentModel newPhotoCommentModel)
        {
            using (var unitOfWork = WorkFactory.GetUnitOfWork())
            {
                var albumId = unitOfWork.Photos.Find(newPhotoCommentModel.PhotoId).AlbumId;

                if (secureService.CanUserAddComment(userId, albumId))
                {
                    unitOfWork.PhotoComments.Add(newPhotoCommentModel);
                    unitOfWork.SaveChanges();
                    eventsAggregator.PushCommentAddedEvent(newPhotoCommentModel);
                }
                else
                {
                    throw new NoEnoughPrivilegesException("User can't get access to comments");
                }
            }
        }
Beispiel #8
0
        public static PhotoCommentViewModel ToPhotoCommentViewModel(this PhotoCommentModel photoComment, UserModel user)
        {
            var userInfo = new UserInfoViewModel
            {
                OwnerFirstName = user.FirstName,
                OwnerLastName  = user.LastName
            };

            var photoCommentViewModel = new PhotoCommentViewModel
            {
                UserInfo       = userInfo,
                Rating         = photoComment.Rating,
                DateOfCreating = photoComment.DateOfCreating,
                Reply          = photoComment.Reply,
                Text           = photoComment.Text
            };

            return(photoCommentViewModel);
        }
        public HttpResponseMessage AddPhotoComment(NewCommentViewModel viewModel)
        {
            var photoCommentModel = new PhotoCommentModel(
                User.Id,
                viewModel.PhotoId,
                viewModel.CommentText,
                viewModel.Reply);

            try
            {
                _photoCommentService.AddPhotoComment(User.Id, photoCommentModel);
            }
            catch (NoEnoughPrivilegesException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }

            return(Request.CreateResponse(HttpStatusCode.Created));
        }
Beispiel #10
0
 public void SomeoneRepliedToCommentCaused(PhotoCommentModel mComment)
 {
     _notyEventManager.SomeoneRepliedToComment(mComment);
 }
Beispiel #11
0
 public void PhotoCommentAddedCaused(PhotoCommentModel mComment)
 {
     _notyEventManager.PhotoCommentAddedNotify(mComment);
 }
Beispiel #12
0
 private int CalculateRelevanceByText(IEnumerable <string> searchWords, PhotoCommentModel photoCommentModel)
 {
     return(searchWords.Sum(searchWord => Regex.Matches(photoCommentModel.Text.ToLower(), searchWord.ShieldString()).Count));
 }