public IActionResult AddItem(int snackId) { var selectedSnack = _snackRepository.GetById(snackId); if (selectedSnack != null) { _shoppingCart.AddCartItem(selectedSnack); } return(RedirectToAction("Index")); }
public object Handle(OrderCommand command) { if (command.Snacks.Count > 0) { var order = new Order(Guid.Empty); foreach (var snackCommand in command.Snacks) { var snackDb = _snackRepository.GetById(snackCommand.Id); var newSnack = new Snack(snackDb.Id, snackDb.Name); if (snackDb != null) { if (snackCommand.Ingredients.Count != 0) { foreach (var item in snackCommand.Ingredients) { var ingredient = _ingredientRepository.GetById(item.IngredientId); newSnack.AddIngredient(ingredient, item.Quantity); } newSnack.CalculatePrice(); order.AddSnack(newSnack); } } } _orderRepository.Save(order); return(order); } return(null); }
public long Add(TicketAddCommand ticket) { var ticketAdd = Mapper.Map <TicketAddCommand, Ticket>(ticket); ticketAdd.DateBuy = DateTime.Now; var session = SessionRepository.GetById(ticket.SessionId); ticketAdd.Session = session; var movie = MovieRepository.GetById(ticket.MovieId); ticketAdd.Movie = movie; var user = UserRepository.GetById(ticket.UserId); ticketAdd.User = user; var snacks = SnackRepository.GetById(ticket.SnacksIds); ticketAdd.Snacks = snacks; var movieTheater = MovieTheaterRepository.GetById(ticket.MovieTheaterId); ticketAdd.MovieTheater = movieTheater; var newTicket = TicketRepository.Add(ticketAdd); return(newTicket.Id); }
public async Task <RegisterAndUpdateOutput> Update(SnackInput snackInput) { var snack = await _snackRepository.GetById(snackInput.Id); if (snack == null) { return(null); } snack.update(snack.Name); foreach (var ingredient in snackInput.Ingredients) { var ingredientSnack = new Ingredient(ingredient.Name, ingredient.Price); ingredientSnack.AddQuantity(ingredient.Quantity); snack.AddIngredient(ingredientSnack); } await _snackRepository.Update(snack); await _snackRepository.UpdateSnackIngredients(snack); return(new RegisterAndUpdateOutput { Success = true, Message = "Snack updated with success.", Data = snack }); }
public IActionResult Details(int id) { var snack = _snackRepository.GetById(id); if (snack == null) { return(View("~/Views/Error/Error.cshtml")); } return(View(snack)); }
public Snack GetById(long Id) { return(SnackRepository.GetById(Id)); }