public async Task <PostViewModel> Post([FromBody] PostInputModel model) { var post = new Models.Post { Content = model.Description, Title = model.Title, OwnerId = CurrentUserId, OwnerName = User.Identity.Name }; await _postRepo.AddAsync(post); var response = new PostViewModel() { Id = post.Id, Title = post.Title, Description = post.Content, OwnerName = post.OwnerName, CreatedDate = post.Created }; await _postMessageHubContext.Clients.All.InvokeAsync("AddPostSuccess", response); return(response); }
public async Task <CreateCommentResponse> CreatePostComment(Guid postId, [FromBody] CreateCommentRequest model) { var comment = new Models.PostComment { Comment = model.Comment, OwnerId = CurrentUserId, OwnerName = User.Identity.Name, PostId = postId }; await _postCommentRepo.AddAsync(comment); var response = new CreateCommentResponse { Id = comment.Id, Comment = comment.Comment, PostId = comment.PostId, OwnerName = comment.OwnerName, CreatedDate = comment.Created }; await _postMessageHubContext.Clients.All.InvokeAsync("AddCommentSuccess", response); return(response); }
public async Task <AddTaskResponse> Add([FromBody] AddTaskRequest request) { var response = await _taskRepository.AddAsync( Domain.Task.CreateInstance( request.Name, request.AssignedTo )); return(new AddTaskResponse()); }
public async Task <GetCartByIdResponse> InsertItemToCartAsync(InsertItemToNewCartRequest request) { var cart = new Domain.Cart(); cart.InsertItemToCart(new CartItem { Product = new Product(request.ProductId), PromoSavings = 0.0D, Quantity = request.Quantity }); cart = await InitCart(cart, populatePrice : true); cart = PriceCalculatorContext.Execute(cart); await _mutateRepository.AddAsync(cart); return(GetCartByIdResponse(cart)); }
public async Task <GetCartByIdResponse> UpdateItemInCartAsync(UpdateItemInCartRequest request) { var isNewItem = false; var cart = await GetCart(request.CartId); cart = await InitCart(cart); var item = cart.CartItems.FirstOrDefault(x => x.Product.ProductId == request.ProductId); // if not exists then it should be a new item if (item == null) { isNewItem = true; item = new CartItem() { Quantity = request.Quantity, Product = new Product(request.ProductId) }; cart.CartItems.Add(item); } else { // otherwise is updating the current item in the cart item.Quantity = request.Quantity; } cart = PriceCalculatorContext.Execute(cart); var result = await _mutateRepository.UpdateAsync(cart); // Todo: refactor to unit of work later if (!isNewItem) { await _cartItemMutateRepository.UpdateAsync(item); } else { await _cartItemMutateRepository.AddAsync(item); } return(GetCartByIdResponse(cart)); }
public async Task <GetClapResponse> Clap([FromBody] CreateClapRequest model) { var clap = new Models.Clap { EntityId = model.EntityId, Type = model.Type, OwnerId = CurrentUserId, OwnerName = User.Identity.Name }; await _clapRepo.AddAsync(clap); var response = new GetClapResponse() { EntityId = clap.EntityId, Id = clap.Id, OwnerName = clap.OwnerName }; await _postMessageHubContext.Clients.All.InvokeAsync("AddClapSuccess", response); return(response); }