public override async Task <CreateReply> Create(CreateRequest request, ServerCallContext context) { Comment c = await commentsService.CreateAsync(new Comment { PhotoId = request.PhotoId, Subject = request.Subject, Body = request.Body }); return(new CreateReply() { Id = c.Id, PhotoId = c.PhotoId, Body = c.Body, Subject = c.Subject, SubmittedOn = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(c.SubmittedOn.ToUniversalTime()), UserName = c.UserName }); }
public async Task <IActionResult> Create([FromBody] CommentDetail model) { var result = await _commentsService.CreateAsync(model); if (result.IsSuccess) { return(Ok(result)); } return(BadRequest(result)); }
public override async Task <CreateReply> Create(CreateRequest request, ServerCallContext context) { try { Comment c = await commentsService.CreateAsync(new Comment { PhotoId = request.PhotoId, Subject = request.Subject, Body = request.Body }); return(new CreateReply() { Id = c.Id, PhotoId = c.PhotoId, Body = c.Body, Subject = c.Subject, SubmittedOn = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(c.SubmittedOn.ToUniversalTime()), UserName = c.UserName }); } catch (Exception ex) { throw new RpcException(new Status(StatusCode.Internal, ex.Message)); } }
public async Task <IActionResult> Create(string slug, [FromBody] CreateOrEditCommentDto model) { if (!ModelState.IsValid) { return(StatusCodeAndDtoWrapper.BuilBadRequest(ModelState)); } long userId = Convert.ToInt64(User.FindFirst(ClaimTypes.NameIdentifier).Value); ApplicationUser user = await _usersService.GetCurrentUserAsync(); Comment comment = await _commentService.CreateAsync(user, slug, model, userId); return(StatusCodeAndDtoWrapper.BuildSuccess(CommentDetailsDto.Build(comment))); }
public override async Task <CreateReply> Create(CreateRequest request, ServerCallContext context) { _logger.LogInformation("Create invoked"); var user = context.GetHttpContext().User; //user.Identity.Name works because: // 1) on the Identity Server Project Config I added the JwtClaimTypes.Name in the UserClaims of the "photos" ApiResource // 2) in this startup I added options.TokenValidationParameters.NameClaimType = JwtClaimTypes.Name; in the AddJwtBearer("Bearer", options =>{ ... }) Comment co = await commentsService.CreateAsync(request.PhotoId, user.Identity.Name, request.Subject, request.Body); return(new CreateReply() { Id = co.Id, PhotoId = co.PhotoId, Body = co.Body, Subject = co.Subject, SubmittedOn = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(co.SubmittedOn.ToUniversalTime()), UserName = co.UserName }); }
public async Task <IActionResult> Create(AllCommentsViewModel model) { if (!ModelState.IsValid) { return(AllWithInputModel(model.InputModel)); } var defaultCvId = _cvService.GetId(); var user = await _userManager.GetUserAsync(User); await _commentsService.CreateAsync(model.InputModel.Content, defaultCvId, user.Id); return(RedirectToAction(nameof(All))); }
public async Task <ActionResult <Comment> > CreateAsync([FromBody] CreateCommentModel model) { var author = await userProvider.GetByIdAsync(model.AuthorId); var(domainResult, id) = await commentService .CreateAsync(model.Key, model.Content, model.ReplyCommentId, author); if (domainResult.Successed) { return(Created(Url.Action("GetById", new { id }), await commentService.GetByIdAsync(id))); } return(BadRequest(domainResult.ToProblemDetails())); }
public override async Task <CreateReply> Create(CreateRequest request, ServerCallContext context) { var user = context.GetHttpContext().User; try { Comment c = await commentsService.CreateAsync(new Comment { PhotoId = request.PhotoId, Subject = request.Subject, Body = request.Body, UserName = user.Identity.Name }); return(new CreateReply() { Id = c.Id, PhotoId = c.PhotoId, Body = c.Body, Subject = c.Subject, SubmittedOn = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(c.SubmittedOn.ToUniversalTime()), UserName = c.UserName }); } catch (UnauthorizedCreateAttemptException <Comment> ) { //found on https://docs.microsoft.com/en-us/dotnet/architecture/grpc-for-wcf-developers/error-handling var metadata = new Metadata { { "User", user.Identity.Name } }; throw new RpcException(new Status(StatusCode.PermissionDenied, "Permission denied"), metadata); } }
public async Task AddComent(CompositionCommentsViewModel comment) { await commentsService.CreateAsync(mapper.Map <CompositionComments>(comment)).ConfigureAwait(false); }