public ActionResult Update([FromBody] DishViewModel dr) { var currentResult = _bo.Read(dr.Id); if (!currentResult.Success) { return(new ObjectResult(HttpStatusCode.InternalServerError)); } var current = currentResult.Result; if (current == null) { return(NotFound()); } if (current.Name == dr.Name && current.DietaryRestrictionId == dr.DietaryRestrictionId) { return(new ObjectResult(HttpStatusCode.NotModified)); } if (current.Name != dr.Name) { current.Name = dr.Name; } if (current.DietaryRestrictionId != dr.DietaryRestrictionId) { current.DietaryRestrictionId = dr.DietaryRestrictionId; } var updateResult = _bo.Update(current); if (!updateResult.Success) { return(new ObjectResult(HttpStatusCode.InternalServerError)); } return(Ok()); }
private void repositoryItemButtonEdit2_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { try { var rowHandle = gridView1.FocusedRowHandle; DishViewModel entity = new DishViewModel(); entity.DishID = Convert.ToInt32(gridView1.GetRowCellValue(rowHandle, "DishID").ToString()); entity.DishName = gridView1.GetRowCellValue(rowHandle, "DishName").ToString(); entity.MealID = Convert.ToInt32(gridView1.GetRowCellValue(rowHandle, "MealID").ToString()); entity.MealName = gridView1.GetRowCellValue(rowHandle, "MealName").ToString(); notSelectedDish.Add(entity); selectedDish.RemoveAll(x => x.DishID.Equals(entity.DishID)); dailyMenuDetails.RemoveAll(x => x.DishID.Equals(entity.DishID)); cbbMealID_SelectedIndexChanged(sender, e); FillGridControlRight(); } catch { } }
public IActionResult DeleteDish(DishViewModel dishViewModel) { var dishDTO = mapper.Map <DishViewModel, DishDTO>(dishViewModel); administrationService.Dish.Delete(dishDTO); return(RedirectToAction("Dishes", "Administration")); }
private void AddAttributesToDish(DishViewModel model, Matratt dish) { dish.MatrattNamn = model.Name; foreach (var ingredient in model.Ingredients) { var dishIngredient = _context.MatrattProdukt. SingleOrDefault(p => p.ProduktId == ingredient.ProduktId && p.MatrattId == model.Id); if (dishIngredient == null) { dish.MatrattProdukt.Add(new MatrattProdukt { MatrattId = dish.MatrattId, ProduktId = ingredient.ProduktId }); } else { dish.MatrattProdukt.Add(dishIngredient); } } dish.MatrattTyp = model.Type; dish.Pris = model.Price; dish.Beskrivning = model.Description; }
private void FormAddDish_Load(object sender, EventArgs e) { if (id.HasValue) { try { DishViewModel view = service.GetElement(id.Value); if (view != null) { textBoxDishName.Text = view.Name; textBoxDishPrice.Text = view.Price.ToString(); textBoxDescription.Text = view.Description; dishProducts = view.DishProducts; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (dishProducts == null) { dishProducts = new List <DishProductViewModel>(); } LoadData(); }
public IActionResult Edit() { DishViewModel model = new DishViewModel(); InitializeModel(model, Consistency.Normal, Models.Type.Lunch); return(View(model)); }
public IActionResult CreateDish(DishViewModel data) { Console.WriteLine(data); Dish dish = new Dish { Name = data.Name, Description = data.Description, Price = data.Price, Starter = data.Starter, MainDish = data.MainDish, Dessert = data.Dessert, Salt = data.Salt, Glutes = data.Glutes, Diabetes = data.Diabetes, }; { using (var ms = new MemoryStream()) { data.Image.CopyTo(ms); dish.Image = ms.ToArray(); } } repository.SaveDish(dish); TempData["message"] = $"{dish.Name} is opgeslagen"; return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> EditDish(DishViewModel dishViewModel) { var user = await userManager.GetUserAsync(HttpContext.User); System.Diagnostics.Debug.WriteLine("Dish image: " + dishViewModel.Image); if (ModelState.IsValid) { if (dishViewModel.Image != null) { MemoryStream ms = new MemoryStream(); dishViewModel.Image.CopyTo(ms); byte[] imageArray = ms.ToArray(); dishViewModel.Dish.Image = imageArray; } dishViewModel.Dish.ChefEmail = user.Email; dishViewModel.Dish.DietaryRestrictions = dishViewModel.DietaryInt; dishViewModel.Dish.DishCategory = dishViewModel.CategorieInt; repository.SaveDish(dishViewModel.Dish); TempData["message"] = $"{dishViewModel.Dish.Name} is opgeslagen"; return(RedirectToAction("Dishes")); } else { return(View(dishViewModel)); } }
// GET: Dishes/Create public ActionResult Create() { var model = new DishViewModel(); model.Category = db.Categories.ToList(); return(View(model)); }
public async Task <IActionResult> Update([FromBody] DishViewModel vm) { var getResult = await _bo.ReadAsync(vm.Id); if (!getResult.Success) { return(InternalServerError(getResult.Exception)); } var item = getResult.Result; if (item == null) { return(NotFound()); } if (vm.CompareToModel(item)) { return(NotModified()); } item = vm.ToModel(item); var updateResult = await _bo.UpdateAsync(item); if (!updateResult.Success) { return(InternalServerError(updateResult.Exception)); } return(Ok()); }
public async Task <IActionResult> Index() { var listOperation = await _bo.ListNonDeletedAsync(); if (!listOperation.Success) { return(OperationErrorBackToIndex(listOperation.Exception)); } var lst = new List <DishViewModel>(); foreach (var item in listOperation.Result) { lst.Add(DishViewModel.Parse(item)); } var drList = await GetDietaryRestrictionViewModels(listOperation.Result.Select(x => x.DietaryRestrictionId).Distinct().ToList()); ViewData["DietaryRestrictions"] = drList; ViewData["Title"] = "Dishes"; ViewData["BreadCrumbs"] = GetCrumbs(); ViewData["DeleteHref"] = GetDeleteRef(); return(View(lst)); }
public ActionResult Update([FromBody] DishViewModel ds) { var currentResult = _bo.Read(ds.Id); if (!currentResult.Success) { return(InternalServerError()); } var current = currentResult.Result; if (current == null) { return(NotFound()); } if (current.Name == ds.Name) { return(NotModified()); } if (current.Name != ds.Name) { current.Name = ds.Name; } var updateResult = _bo.Update(current); if (!updateResult.Success) { return(InternalServerError()); } return(Ok()); }
public ActionResult Create([FromBody] DishViewModel vm) { var rt = vm.ToDish(); var res = _bo.Create(rt); return(res.Success ? Ok() : InternalServerError()); }
public async Task <IActionResult> Edit(Guid id, DishViewModel vm) { if (ModelState.IsValid) { var getOperation = await _bo.ReadAsync(id); if (!getOperation.Success) { return(OperationErrorBackToIndex(getOperation.Exception)); } if (getOperation.Result == null) { return(RecordNotFound()); } var result = getOperation.Result; if (!vm.CompareToModel(result)) { result = vm.ToModel(result); var updateOperation = await _bo.UpdateAsync(result); if (!updateOperation.Success) { TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception); return(View(vm)); } else { return(OperationSuccess("The record was successfuly updated")); } } } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(DishViewModel model) { if (ModelState.IsValid) { if (model.Image != null) { var uploads = Path.Combine(_environment.WebRootPath, "uploads"); if (model.Image.Length > 0) { using (var fileStream = new FileStream(Path.Combine(uploads, model.Image.FileName), FileMode.Create)) { await model.Image.CopyToAsync(fileStream); } } model.ImageSrc = "/uploads/" + model.Image.FileName; } Dish dish = _repository.GetDish(model.Id); if (dish != null) { _repository.UpdateDish(model.MapTo(dish)); } else { _repository.AddDish(model.MapTo(new Dish())); } _repository.Save(); return(RedirectToAction("Index")); } InitializeModel(model, model.Consistency, model.Type); return(View(model)); }
public async Task <IActionResult> Edit(Guid id, [Bind("Id, Name, DietaryRestrictionId")] DishViewModel vm) { if (ModelState.IsValid) { var getOperation = await _bo.ReadAsync((Guid)id); if (!getOperation.Success) { return(View("Error", new ErrorViewModel() { RequestId = getOperation.Exception.Message })); } if (getOperation.Result == null) { return(NotFound()); } var result = getOperation.Result; result.Name = vm.Name; result.DietaryRestrictionId = vm.DietaryRestrictionId; var updateOperation = await _bo.UpdateAsync(result); if (!updateOperation.Success) { return(View("Error", new ErrorViewModel() { RequestId = updateOperation.Exception.Message })); } } return(RedirectToAction(nameof(Index))); }
public ActionResult Create([FromBody] DishViewModel vm) { var d = vm.ToDish(); var res = _bo.Create(d); return(StatusCode(res.Success ? (int)HttpStatusCode.OK : (int)HttpStatusCode.InternalServerError)); }
public IActionResult Create() { DishViewModel model = new DishViewModel(); model.AvailableIngredients = IdentityContext.Ingredients.ToList(); model.DishTypes = IdentityContext.DishTypes.ToList(); return(View(model)); }
public MainFormService(ICategoryAppService service, IUserDisplayMessageService messageService) { _service = service; _messageService = messageService; _fallbackDish = new DishViewModel { Name = "Bolo de Chocolate" }; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.MenuLayout); lst = FindViewById <ListView>(Resource.Id.menuListView); lst.Adapter = new MenuListAdaptor(this, DishViewModel.getAllDishes()); }
public IActionResult Index() { DishViewModel vm = new DishViewModel() { Dishes = _db.Dishes.ToList() }; return(View(vm)); }
public IActionResult Edit(int id) { var dish = _repository.GetDish(id); DishViewModel model = new DishViewModel(); model.Map(dish); InitializeModel(model, model.Consistency, model.Type); return(View(model)); }
public ActionResult Create([FromBody] DishViewModel vm) { var dr = new Dish(vm.Name, vm.DietaryRestrictionId); var res = _bo.Create(dr); var code = res.Success ? HttpStatusCode.OK : HttpStatusCode.InternalServerError; return(new ObjectResult(code)); }
public MealPlanViewModel GetDisplay(int mealPlanId) { MealPlanViewModel mealPlanDisplay = new MealPlanViewModel(); MealPlan mealPlan = Get(mealPlanId); mealPlanDisplay.MealPlanId = mealPlan.MealPlanId; mealPlanDisplay.Description = mealPlan.Description; mealPlanDisplay.PhotoFilePath = mealPlan.PhotoFilePath; mealPlanDisplay.PrepTime = mealPlan.PrepTime; mealPlanDisplay.PrepTimeUnit = mealPlan.PrepTimeUnit; mealPlanDisplay.CostPerServing = mealPlan.CostPerServing; mealPlanDisplay.Active = mealPlan.Active; mealPlanDisplay.Created = (System.DateTime)mealPlan.Created; PreparationRepository preparationRepository = new PreparationRepository(); mealPlanDisplay.Preparations = preparationRepository.GetDisplayList(mealPlanId); MealPlanAssignedCategoryRepository mealPlanAssignedCategoryRepository = new MealPlanAssignedCategoryRepository(); mealPlanDisplay.MealPlanAssignedCategories = mealPlanAssignedCategoryRepository.GetDisplayList(mealPlanId); MealPlanAssignedDietPlanRepository mealPlanAssignedDietPlanRepository = new MealPlanAssignedDietPlanRepository(); mealPlanDisplay.MealPlanAssignedDietPlans = mealPlanAssignedDietPlanRepository.GetDisplayList(mealPlanId); NutrientViewModel nutrientViewModel = new NutrientViewModel(); mealPlanDisplay.NutrientDropDownList = nutrientViewModel.GetDropDownList(); MealPlanAssignedNutrientRepository mealPlanAssignedNutrientRepository = new MealPlanAssignedNutrientRepository(); mealPlanDisplay.MealPlanAssignedNutrients = mealPlanAssignedNutrientRepository.GetDisplayList(mealPlanId); MealPlanAssignedIngredientRepository mealPlanAssignedIngredientRepository = new MealPlanAssignedIngredientRepository(); mealPlanDisplay.MealPlanAssignedIngredients = mealPlanAssignedIngredientRepository.GetDisplayList(mealPlanId); MealPlanAssignedDishRepository mealPlanAssignedDishRepository = new MealPlanAssignedDishRepository(); mealPlanDisplay.MealPlanAssignedDishes = mealPlanAssignedDishRepository.GetDisplayList(mealPlanId); UomViewModel uomViewModel = new UomViewModel(); mealPlanDisplay.UomDropDownList = uomViewModel.GetDropDownList(); DishViewModel dishViewModel = new DishViewModel(); mealPlanDisplay.DishDropDownList = dishViewModel.GetDropDownList(); IngredientViewModel ingredientViewModel = new IngredientViewModel(); mealPlanDisplay.IngredientDropDownList = ingredientViewModel.GetDropDownList(); return(mealPlanDisplay); }
public ActionResult Add(CardTypes activeSection) { try { var service = ServiceCreator.GetManagerService(User.Identity.Name); switch (activeSection) { case CardTypes.Dish: { var model = new DishViewModel(); var allDishes = service.GetAllDishes(); if (allDishes != null && allDishes.Any()) { model.AvailableCategories = allDishes.Where(o => !string.IsNullOrEmpty(o.Category)).Select(o => o.Category).Distinct().ToList(); } return(View("DishCardEdditable", model)); } case CardTypes.Menu: { var model = new MenuViewModel(); var rests = service.GetAllRestaurants(); if (rests != null && rests.Any()) { model.AvailableRests = Mapper.Map <List <RestaurantDropDown> >(rests); } return(View("MenuCardEdditable", model)); } case CardTypes.Restaurant: { return(View("RestaurantCardEdditable", new RestaurantViewModel())); } case CardTypes.Dispatch: { return(View("DispatchCardEdditable", new DispatchViewModel())); } case CardTypes.Mod: { return(View("ModificatorsCardEdditable", new ModificatorViewModel())); } default: throw new Exception("No active section"); } } catch (Exception ex) { return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message })); } }
public string ChangeDish(DishViewModel dishViewModel) { if (ModelState.IsValid) { var dishDTO = mapper.Map <DishViewModel, DishDTO>(dishViewModel); administrationService.Dish.Change(dishDTO); return("Успешно изменено"); } return("Проверьте данные"); }
public IActionResult EditDish(int dishId) { DishViewModel viewModel = new DishViewModel { Dish = repository.GetDishById(dishId) }; viewModel.checkBooleans(); return(View(viewModel)); }
public async Task <IActionResult> CreateAsync([FromBody] DishViewModel vm) { var newItem = vm.ToModel(); var result = await _bo.CreateAsync(newItem); if (!result.Success) { return(InternalServerError(result.Exception)); } return(Created(Request.Path.Value, null)); }
public string AddDish(DishViewModel dishViewModel, int MenuId) { if (ModelState.IsValid) { dishViewModel.MenuId = MenuId; var dishDTO = mapper.Map <DishViewModel, DishDTO>(dishViewModel); administrationService.Dish.Add(dishDTO); return("Успешно добавлено"); } return("Проверьте данные"); }
private void CreateDishMenu_OnClick(object sender, RoutedEventArgs e) { var dishViewModel = new DishViewModel(new Dish()); dishViewModel.Entity.EntitySaved += MainPage.OnEntityChanged; dishViewModel.Entity.EntityDeleted += MainPage.OnEntityChanged; var dishWindow = Factory.CreateEntityWindow(this, dishViewModel); dishWindow.Show(); }
public MainViewModel(DishWindow dishWindow, IngredientsWindow ingredientsWindow, PreparationWindow preparationWindow) { _dinner = new Dinner(); _dishWindow = dishWindow; _ingredientsWindow = ingredientsWindow; _preparationWindow = preparationWindow; _dishViewModel = (DishViewModel) _dishWindow.DataContext; _ingredientsViewModel = (IngredientsViewModel) _ingredientsWindow.DataContext; _preparationViewModel = (PreparationViewModel) _preparationWindow.DataContext; Starters = new ObservableCollection<Dish>(); Mains = new ObservableCollection<Dish>(); Desserts = new ObservableCollection<Dish>(); Menu = new ObservableCollection<Dish>(); _hideErrorTextTimer = new System.Timers.Timer(ErrorTextDisplayTime) {AutoReset = false}; _hideErrorTextTimer.Elapsed += (sender, args) => Application.Current.Dispatcher.Invoke(() => ErrorTextVisible = false); ShowPreparations = new DelegateCommand(o => { _preparationViewModel.Starter = _dinner.GetSelectedDish(DishType.Starter); _preparationViewModel.Main = _dinner.GetSelectedDish(DishType.Main); _preparationViewModel.Dessert = _dinner.GetSelectedDish(DishType.Dessert); _preparationWindow.Show(); }, o => Menu.Any()); ShowIngredients = new DelegateCommand(o => { _ingredientsViewModel.Ingredients = _dinner.AllIngredients; _ingredientsWindow.Show(); }, o => Menu.Any()); _dinner.MenuChanged += OnMenuChanged; _dinner.FilteredDishes += DinnerOnFilteredDishes; _dinner.ErrorGettingFilteredDishes += DinnerOnErrorGettingFilteredDishes; _dinner.DishesChanged += OnDishesChanged; _dinner.NumberOfGuestsChanged += OnNumberOfGuestsChanged; }