public async Task <Customer> UpdateCustomerAsync(string email, string address1, string address2, string city, string region, string postalCode, string country, int shippingRegionId) { var customer = await _dbContext .Customer .FirstOrDefaultAsync(c => c.Email == email); customer.Address1 = address1; customer.Address2 = address2; customer.City = city; customer.Region = region; customer.PostalCode = postalCode; customer.Country = country; customer.ShippingRegionId = shippingRegionId; _dbContext.Entry(customer).State = EntityState.Modified; await _dbContext.SaveChangesAsync(); return(customer); }
public async Task AddShoppingCartItemAsync(string cartId, int productId, string attributes) { // Check if we have a product like this and increment the quantity var item = _dbContext .ShoppingCart .FirstOrDefault(c => c.ProductId == productId && c.CartId == cartId); if (item != null) { await UpdateCartItemAsync(item.ItemId, item.Quantity + 1); } else { var newCartItem = new ShoppingCart { CartId = cartId, ProductId = productId, Attributes = attributes, AddedOn = DateTime.Now, Quantity = 1, BuyNow = 1 }; _dbContext.ShoppingCart.Add(newCartItem); await _dbContext.SaveChangesAsync(); } }
public async Task <int> SaveOrderAsync(int customerId, string cartId, int shippingId, int taxId) { var order = new Orders { TotalAmount = await _shoppingCartService.GetCartTotalAmountAsync(cartId), Status = 0, ShippingId = shippingId, TaxId = taxId, CustomerId = customerId, CreatedOn = DateTime.Now }; await _dbContext.Orders.AddAsync(order); await _dbContext.SaveChangesAsync(); // Line items var cartItems = await _shoppingCartService.GetShoppingCartByIdAsync(cartId); foreach (var cartItem in cartItems) { var orderDetail = new OrderDetail { OrderId = order.OrderId, ItemId = cartItem.ItemId, ProductId = cartItem.ProductId, Attributes = cartItem.Attributes, Quantity = cartItem.Quantity, ProductName = cartItem.Name, UnitCost = decimal.Parse(cartItem.Price) }; await _dbContext.OrderDetail.AddAsync(orderDetail); } await _dbContext.SaveChangesAsync(); //Clear the cart await _shoppingCartService.EmptyCartAsync(cartId); return(order.OrderId); }
public async Task PostProductReviewAsync(string customerEmail, int product_id, string review, short rating) { var loggedOnCustomer = await _customerService.GetCustomerByEmailAsync(customerEmail); var productReview = new Review { CustomerId = loggedOnCustomer.CustomerId, ProductId = product_id, Review1 = review, Rating = rating, CreatedOn = DateTime.Now }; _dbContext.Review.Add(productReview); await _dbContext.SaveChangesAsync(); }
public async Task <CustomerReview> PostProductReviewAsync(string customerEmail, int product_id, string review, short rating) { var loggedOnCustomer = await _customerService.GetCustomerByEmailAsync(customerEmail); var productReview = new Review { CustomerId = loggedOnCustomer.CustomerId, ProductId = product_id, Review1 = review, Rating = rating, CreatedOn = DateTime.Now }; _dbContext.Review.Add(productReview); await _dbContext.SaveChangesAsync(); return(new CustomerReview { CreatedOn = productReview.CreatedOn.ToString(CultureInfo.InvariantCulture), Name = loggedOnCustomer.Name, Rating = productReview.Rating, Review = productReview.Review1 }); }