public async Task <IActionResult> OnPostUploadAsync(string clothingName, string category, bool isClean = false) { if (ModelState.IsValid) { string imageUri = null; if (Upload != null) { try { imageUri = await _awsS3Service.UploadFile(Upload); } catch (Exception e) { ModelState.AddModelError("S3 Upload", e.Message); } } //get UserId string userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; var categoryId = category switch { "Top" => 1, "Bottom" => 2, _ => 1, }; // Create new clothing object and save it to database Clothing = new Clothing(userId, clothingName, isClean, imageUri, categoryId); db.Clothes.Add(Clothing); db.SaveChanges(); return(RedirectToPage("/Dashboard", Clothing)); } return(Page()); }
public void CreateOrder(IOrder order) { Order _order = (Order)order; _order.DatePlaced = DateTime.Now; var shoppingCartItems = _shoppingCart.Items; foreach (var item in shoppingCartItems) { //Cloth cloth = (Cloth)item.Cloth; var orderDetail = new OrderDetail() { Quantity = item.Quantity, ClothId = item.Cloth.Id,//cloth.Id, OrderId = _order.Id, Price = item.Cloth.Price }; _DbContext.OrderDetails.Add(orderDetail); } _DbContext.SaveChanges(); }
public int Commit() { return(context.SaveChanges());// 0; }