예제 #1
0
        public ActionResult AddComment(CommentDto commentDto)
        {
            var list = new List <CommentViewModel>();

            try
            {
                var userId  = User.Identity.GetUserId();
                var comment = _repository.PostRepository.AddComment(commentDto.PostId, userId, commentDto.Text);
                list.Add(CommentViewModel.Create(comment, userId));
                _repository.Complete();
                list[0].Id = comment.Id;
                CommentsHub.Notify(commentDto.PostId, comment.Id);
            }
            catch (DbEntityValidationException exception)
            {
                list[0].Error = DbEntityValidationExceptionHandler.GetExceptionMessage(exception);
                return(PartialView("_CommentsList", list));
            }
            catch (Exception exception)
            {
                list[0].Error = exception.Message;
                return(PartialView("_CommentsList", list));
            }

            return(PartialView("_CommentsList", list));
        }
예제 #2
0
        public IHttpActionResult UploadMessage(string username, MessageDto messageDto)
        {
            try
            {
                var userId = User.Identity.GetUserId();
                var output = Repository.MessengerRepository.UploadMessage(userId,
                                                                          Repository.ApplicationUserRepository.GetUserByUsername(username).Id, messageDto);
                Repository.Complete();

                Repository.MessengerRepository.Send(userId, username, output.Id + "");

                return(Ok(output.Id));
            }
            catch (AuthenticationException)
            {
                return(Unauthorized());
            }
            catch (DbEntityValidationException exception)
            {
                return(BadRequest(DbEntityValidationExceptionHandler.GetExceptionMessage(exception)));
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.Message));
            }
        }
예제 #3
0
        protected IHttpActionResult Post(Func <string, dynamic> func)
        {
            try
            {
                var userId = User.Identity.GetUserId();
                var output = func(userId);
                Repository.Complete();

                return(Ok(output.Id));
            }
            catch (AuthenticationException)
            {
                return(Unauthorized());
            }
            catch (DbEntityValidationException exception)
            {
                return(BadRequest(DbEntityValidationExceptionHandler.GetExceptionMessage(exception)));
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.Message));
            }
        }
예제 #4
0
        protected IHttpActionResult Put(Action <string> action)
        {
            try
            {
                var userId = User.Identity.GetUserId();
                action(userId);
                Repository.Complete();
            }
            catch (AuthenticationException)
            {
                return(Unauthorized());
            }
            catch (DbEntityValidationException exception)
            {
                return(BadRequest(DbEntityValidationExceptionHandler.GetExceptionMessage(exception)));
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.Message));
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }