public SaleHistoryList(SaleHistoryDto dto) { RestaurantId = dto.RestaurantId; Value = dto.Value; Dishes = dto.DishesCount; Date = dto.SaleDate; }
public async Task <ActionResult> Create(SalesHistoryCreate model) { if (!ModelState.IsValid) { return(RedirectToAction("Create", model)); } model.Date = DateTime.Now; FillSelectedRecipes(model); var dto = new SaleHistoryDto(model); var restaurant = await _restaurantsService.GetAsync(model.RestaurantId); if (restaurant == null) { return(HttpNotFound()); } var selectedDishes = model.AllDishes.Where(d => d.IsSelected).ToList(); var dishesFromDb = await _recipesService.GetAllAsync(); foreach (var dish in selectedDishes) { dish.Ingredients = dishesFromDb.Single(d => d.Id == dish.Id).Ingredients; } //if (!DishesCanBePrepared( // selectedDishes, // restaurant.IngredientsCountDictionary)) //{ // model.Message = Properties.Resources.LackOfIngredients; // return View(model); //} try { SubtractIngredientsFromRestaurant(restaurant, selectedDishes); } catch (Exception e) { model.Message = e.Message; model.Restaurants = await _restaurantsService.GetAllAsync(); return(View(model)); } await _restaurantsService.UpdateAsync(restaurant); await _salesHistorysService.AddAsync(dto); return(RedirectToAction("Index")); }