public async Task <IActionResult> Create([Bind("GameTypeId,GenreName")] GameType gameType) { if (ModelState.IsValid) { _context.Add(gameType); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(gameType)); }
public async Task <IActionResult> Create([Bind("IngredientId,Name,Price")] Ingredient ingredient) { if (ModelState.IsValid) { _context.Add(ingredient); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(ingredient)); }
public async Task <IActionResult> Create([Bind("PublisherId,PublisherName")] Publisher publisher) { if (ModelState.IsValid) { _context.Add(publisher); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(publisher)); }
public async Task <IActionResult> Create([Bind("PlatformId,PlatformName")] GamePlatform gamePlatform) { if (ModelState.IsValid) { _context.Add(gamePlatform); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(gamePlatform)); }
public async Task <IActionResult> Create([Bind("CategoryId,Name,Active")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("PGRatingId,Rating")] PGRating pGRating) { if (ModelState.IsValid) { _context.Add(pGRating); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(pGRating)); }
public async Task <IActionResult> Create([Bind("ImageId,URL,ProductId")] Image image) { if (ModelState.IsValid) { _context.Add(image); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ProductId"] = new SelectList(_context.Product, "ProductId", "Name", image.ProductId); return(View(image)); }
public async Task <IActionResult> Create([Bind("InventoryId,Stock,Price,ProductId,PlatformId")] Inventory inventory) { if (ModelState.IsValid) { _db.Add(inventory); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["PlatformId"] = new SelectList(_db.GamePlatform, "PlatformId", "PlatformName", inventory.PlatformId); ViewData["ProductId"] = new SelectList(_db.Product, "ProductId", "Name", inventory.ProductId); return(View(inventory)); }
public async Task <IActionResult> Post([FromBody] User user) { if (!string.IsNullOrEmpty(user.Name)) { _context.Add(user); await _context.SaveChangesAsync(); return(CreatedAtAction("Post", user)); } else { return(BadRequest("User's name was not given")); } }
public async Task SendEmailNotification(Order order) { var queue = await GetQueue(); var orderReceivedMessage = new OrderReceivedMessage { OrderId = order.Id, Amount = order.Amount }; var queueMessage = new CloudQueueMessage(JsonConvert.SerializeObject(orderReceivedMessage)); try { _logger.LogInformation("Sending email request to MailerService"); await queue.AddMessageAsync(queueMessage); } catch (Exception e) { _logger.LogError(e, "Couldn't send email request, saving to outbox for later retry"); // save to outbox so we can try sending later! _db.Outbox.Add(new PendingOrderNotification { OrderId = order.Id }); await _db.SaveChangesAsync(); } }
public async Task UpdateDishAsync(Dish dish, List <DishIngredient> dishIngredients = null) { _context.Update(dish); await _context.SaveChangesAsync(); if (dishIngredients != null) { //remove old DishIngredients List <DishIngredient> oldDishIngredients = _context.DishIngredients.Where(di => di.DishId == dish.DishId).ToList(); _context.DishIngredients.RemoveRange(oldDishIngredients); await _context.SaveChangesAsync(); //add new DishIngredients _context.DishIngredients.AddRange(dishIngredients); await _context.SaveChangesAsync(); } }
public async Task <IActionResult> Create([Bind("DishId,Name,Description,Price,CategoryId,Active")] Dish dish) { if (ModelState.IsValid) { _context.Add(dish); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(dish)); }
public async Task <IActionResult> Register([Bind("UserId,Name,Surname,Street,PostalCode,Password,Birthdate,Email,CityId,RoleId")] User user) { if (ModelState.IsValid) { user.UserId = Guid.NewGuid(); user.Password = Hashing.HashPassword(user.Password); _db.Add(user); await _db.SaveChangesAsync(); return(Redirect("/Login")); } ViewData["CityId"] = new SelectList(_db.City, "CityId", "CityName", user.CityId); ViewData["RoleId"] = new SelectList(_db.UserRole, "RoleId", "RoleName", user.RoleId); return(View(user)); }
public async Task <int> Handle(ProcessOrderCommand command) { Order order = null; using (var tx = await _db.Database.BeginTransactionAsync()) { try { order = CreateOrder(command.Amount); await _db.SaveChangesAsync(); // req/resp model for payment service // http or queues await _paymentClient.Process(order); tx.Commit(); } catch (PaymentServiceException) { order.Status = OrderStatus.PaymentPending; tx.Commit(); throw new Exception("Couldn't process the payment, please check your credit card provider and try again"); } catch (Exception e) { _logger.LogError(e, $"Error processing order {order?.Id}"); tx.Rollback(); // log and bubble up throw; } } // fire and forget to downstream systems // pub/sub model await _mailerClient.SendEmailNotification(order); _logger.LogInformation($"Order {order.Id} processed successfully"); return(order.Id); }
public async Task <Address> AddAddressAsync(Address address) { Address dbAddress = _context.Addresses.FirstOrDefault( x => x.City == address.City && x.PostalCode == address.PostalCode && x.StreetAddress == address.StreetAddress && x.FirstName == address.FirstName && x.Surname == address.Surname); if (dbAddress != null) { return(dbAddress); } else { _context.Addresses.Add(address); await _context.SaveChangesAsync(); return(address); } }
public async Task CreateOrderAsync(List <CartItem> cart, Address dbAddress, bool paidByCard) { //create a new order and add it to the db Order order = new Order() { AddressId = dbAddress.AddressId, PaidByCard = paidByCard, OrderPlaced = DateTime.Now, Active = true, PhoneNumber = GetPhoneNumberFromSession(), DishOrders = new List <DishOrder>() }; _context.Orders.Add(order); await _context.SaveChangesAsync(); //create dishOrders and attach to order List <DishOrder> dishOrders = new List <DishOrder>(); foreach (CartItem ci in cart) { Dish dish = _context.Dishes.Include(x => x.DishIngredients).ThenInclude(x => x.Ingredient).FirstOrDefault(x => x.DishId == ci.Dish.DishId); if (dish != null) { DishOrder dishOrder = new DishOrder() { Amount = 1, DishId = ci.Dish.DishId, OrderId = order.OrderId, DishOrderIngredients = new List <DishOrderIngredient>() }; //create dishorderingredients List <Ingredient> originalIngredients = new List <Ingredient>(); foreach (DishIngredient di in dish.DishIngredients) { originalIngredients.Add(di.Ingredient); } //compare original dish's ingredients with cartItem's List <Ingredient> added = ci.Ingredients.Where(cii => !originalIngredients.Any(oii => cii.IngredientId == oii.IngredientId)).ToList(); List <Ingredient> removed = originalIngredients.Where(oii => !ci.Ingredients.Any(cii => oii.IngredientId == cii.IngredientId)).ToList(); removed.ForEach(x => dishOrder.DishOrderIngredients.Add(new DishOrderIngredient() { IngredientId = x.IngredientId, IsAdded = false })); added.ForEach(x => dishOrder.DishOrderIngredients.Add(new DishOrderIngredient() { IngredientId = x.IngredientId, IsAdded = true })); //find if there already is an identical dishOrder. If so, increase its count DishOrder identical = dishOrders.FirstOrDefault(dshOrds => dshOrds.DishId == dish.DishId && !dshOrds.DishOrderIngredients.Where(cii => !dishOrder.DishOrderIngredients.Any(di => cii.IngredientId == di.IngredientId)).Any() && !dishOrder.DishOrderIngredients.Where(cii => !dshOrds.DishOrderIngredients.Any(di => cii.IngredientId == di.IngredientId)).Any() ); if (identical != null) { identical.Amount++; } else { dishOrders.Add(dishOrder); } } } dishOrders.ForEach(x => order.DishOrders.Add(x)); await _context.SaveChangesAsync(); }