public async Task <JsonResult> AddSubcription(string subscribedProduct) { SubscribedProductDto subscribedProductDto = JsonConvert.DeserializeObject <SubscribedProductDto>(subscribedProduct); try { var subscrib = await _productService.AddSubscription(subscribedProductDto); return(Json(new { success = true, result = subscrib })); } catch (Exception ex) { return(Json(new { success = false, result = ex.Message })); } }
public async Task <SubscribedProduct> AddSubscription(SubscribedProductDto subscribedProductDto) { var product = await _db.Products.FirstOrDefaultAsync(p => p.Id == subscribedProductDto.ProductId); var newSubscribedProduct = new SubscribedProduct() { UserId = subscribedProductDto.UserId, ProductId = subscribedProductDto.ProductId }; await _db.SubscribedProducts.AddAsync(newSubscribedProduct); await _db.SaveChangesAsync(); return(newSubscribedProduct); }