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)); }
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)); } }
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)); } }
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)); }