public IActionResult Edit(int?id) { _logger.LogInformation($"{DateTime.Now.ToString()}: Processing request Dish/Edit"); try { DishDTO dishDTO = _dishService.GetDish(id); var provider = new EditDithViewModel() { Info = dishDTO.Info, Id = dishDTO.Id, Name = dishDTO.Name, Path = _path + dishDTO.Path, Price = dishDTO.Price, Weight = dishDTO.Weight, CatalogId = dishDTO.CatalogId }; return(View(provider)); } catch (ValidationException ex) { _logger.LogError($"{DateTime.Now.ToString()}: {ex.Property}, {ex.Message}"); return(Content(ex.Message)); } }
public ActionResult Edit(int id, IFormCollection collection, IFormFile file) { try { var dto = new DishDTO() { Titile = collection["Dish.Titile"], Ingridients = collection["Dish.Ingridients"], Price = Double.Parse(collection["Dish.Price"]), Serving = collection["Dish.Serving"], CategoryId = Int32.Parse(collection["Dish.CategoryId"]) }; if (file != null) { var dish = _dishService.GetById(id); _imageService.DeleteImage(dish.Image); var path = _imageService.UploadImage(file); dto.Image = path; } _dishService.Update(dto, id); return(RedirectToAction(nameof(Index))); } catch (Exception e) { return(View()); } }
public IActionResult CopyMenu(MenuViewModel menuViewModel, IEnumerable <CopyDishViewModel> copyDishViewModels) { if (ModelState.IsValid) { var menuDTO = mapper.Map <MenuViewModel, MenuDTO>(menuViewModel); menuDTO.IsActive = true; var menuId = administrationService.Menu.Add(menuDTO); var dishesDTO = new List <DishDTO>(); foreach (var dish in copyDishViewModels) { if (dish.IsSelected) { var dishDTO = new DishDTO { Name = dish.Name, Price = dish.Price, Weight = dish.Weight, MenuId = menuId }; administrationService.Dish.Add(dishDTO); } } return(RedirectToAction("Menus", "Administration")); } return(Content("Проверьте введенные данные")); }
public bool Remove(IngredientDTO ingredient, DishDTO dish) { DBConnection conn = new(); if (conn.Open()) { string cmd = "DELETE " + "ingredientdishrelation.* " + "FROM " + "ingredientdishrelation " + "JOIN " + "dish " + "ON " + "dish.id = ingredientdishrelation.dishID " + "JOIN " + "ingredient " + "ON " + "ingredient.id = ingredientdishrelation.ingredientID " + "WHERE " + $"ingredient.name = '{ingredient.Name}' " + "AND " + $"dish.name = '{dish.Name}'"; conn.RunCommand(cmd); conn.Close(); return(true); } return(false); }
public TimeSpan MakeOrder(DishDTO dishDTO, ICookerService cookerSv, ICookService cookSv, IDishService dishSv) { if (dishDTO == null) { throw new NullReferenceException(); } DateTime orderTime = DateTime.Now; Dish dish = dishSv.Find(dishDTO.Id); Cooker cooker = cookerSv.FindCooker(dish); Cook cook = cookSv.FindCook(); TimeSpan cookerTimeToCook = cookerSv.TimeToCook(dish, cooker, orderTime); TimeSpan cookTimeToCook = cookSv.TimeToCook(dish, cook, orderTime); TimeSpan maxCookingTime = cookerTimeToCook >= cookTimeToCook ? cookerTimeToCook : cookTimeToCook; DateTime finishTime = orderTime.Add(maxCookingTime); cookerSv.Update(cooker, finishTime); cookSv.Update(cook, finishTime); AddOrder(orderTime, finishTime, dish, cook, cooker); _db.Save(); return(maxCookingTime); }
public void AddDish(DishDTO newDish) { this.dbContext.Ingredients.AddRange(AutoMapper.Mapper.Map <IEnumerable <Ingredient> >(newDish.Ingredients)); this.dbContext.Dishes.Add(AutoMapper.Mapper.Map <Dish>(newDish)); this.dbContext.SaveChanges(); }
public void Change(DishDTO dishDTO) { var dish = Map(dishDTO); db.Dishes.Update(dish); db.Save(); }
public void Delete(DishDTO dishDTO) { var dish = Map(dishDTO); db.Dishes.Delete(dish); db.Save(); }
public void Add(DishDTO dishDTO) { var dish = Map(dishDTO); db.Dishes.Add(dish); db.Save(); }
private void UpdateDish() { if (string.IsNullOrEmpty(txtboxDishID.Text) || string.IsNullOrEmpty(txtboxDishName.Text) || string.IsNullOrEmpty(txtboxDishPrice.Text)) { MessageBox.Show("Xin hãy nhập những trường thông tin cần thiết", "!!!", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (MessageBox.Show("Bạn có chắc chắn muốn cập nhật không?", "!!!", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { try { DishDTO dishDTO = new DishDTO(txtboxDishID.Text, txtboxDishName.Text, decimal.Parse(txtboxDishPrice.Text), txtboxDishImage.Text); DishBUS.Instance.UpdateDish(dishDTO); MessageBox.Show("Cập nhật thực đơn thành công", "Thành công", MessageBoxButton.OK, MessageBoxImage.Information); txtboxDishID.Text = StaffBUS.Instance.GetNewStaffID(); DisplayAllDishes(); } catch (BUSException ex) { MessageBox.Show(ex.ToString(), "!!!", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void txtDishID_TextChanged(object sender, TextChangedEventArgs e) { if (btnAction.Content.ToString() == "Đồng ý sửa") { DishDTO dishDTO = DishBUS.Instance.FindDishByID(txtboxDishID.Text); if (dishDTO != null) { txtboxDishName.Text = dishDTO.Name; txtboxDishImage.Text = dishDTO.ImagePath; txtboxDishPrice.Text = dishDTO.UnitPrice.ToString(); if (File.Exists(dishDTO.ImagePath)) { dishImage.Source = new BitmapImage(new Uri(dishDTO.ImagePath, UriKind.RelativeOrAbsolute)); } dishImage.Visibility = Visibility.Visible; gridImage.Visibility = Visibility.Hidden; } else { txtboxDishName.Text = ""; txtboxDishImage.Text = ""; txtboxDishPrice.Text = ""; dishImage.Visibility = Visibility.Hidden; gridImage.Visibility = Visibility.Visible; } } }
public IActionResult UpdateDish(int id, [FromBody] PostDishDTO dishDTO) { _requestLogService.SaveRequest(User.Identity.GetUserId(), "PUT", "api/v1/dishes/{id}", "UpdateDish"); if (!ModelState.IsValid) { return(BadRequest("Invalid fields provided, please double check the parameters")); } if (dishDTO.RestaurantId.Equals(null)) { return(BadRequest("Dish is not related any Restaurant")); } if (!IsRestaurantUserOrAdmin(dishDTO.RestaurantId)) { return(StatusCode(403, "Dish can only be updated by admin or by restaurant user")); } var d = _dishService.GetDishById(id); if (d == null) { return(NotFound()); } if (!(User.IsInRole("premiumUser") && !User.IsInRole("admin")) && dishDTO.PromotionId != null && dishDTO.PromotionId != d.PromotionId) { return(BadRequest("Promotions to dishes can only be added by admin or premium user")); } DishDTO updatedDish = _dishService.UpdateDish(id, dishDTO); return(Ok(updatedDish)); }
public IActionResult PutDish(int id, DishDTO dishDTO) { if (id != dishDTO.DishId) { return(BadRequest()); } Dish dish = _mapper.Map <Dish>(dishDTO); _dishItemRepository.Update(dish); try { _dishItemRepository.Save(); } catch (DbUpdateConcurrencyException) { if (!DishExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public AddEditDishForm(DishDTO dish, DishesForm main) { this.main = main; _Dish = dish; InitializeComponent(); InitializeTextBoxes(); InitializeListBoxes(); }
public void UpdateDish(DishDTO dishtDto) { var mapper = new MapperConfiguration(c => c.CreateMap <DishDTO, Dish>()).CreateMapper(); Dish dish = mapper.Map <DishDTO, Dish>(dishtDto); Database.Dishes.Update(dish); Database.Save(); }
public void Create(DishDTO item) { if (item.Price == 0 || item.Time == 0 || item.Weight == 0) { throw new AbsentDataException("Parameters like time, weight or price cannot be 0"); } _data.Dishes.Create(Mapper.Map <Dish>(item)); _data.Save(); }
public void EditDish(DishDTO dish) { if (!IsTitleUnique(dish.Title, GetDishes()) || !IsTitleChanged(dish.Title, dish.Id, GetDishes())) { throw new BLValidationException("Такое название уже существует", "Title"); } Database.Dishes.Update(DTOtoDish(dish)); Database.Save(); }
public bool Update(string oldName, string newName, double price, List <IngredientDTO> ingredients) { DBConnection conn = new(); if (conn.Open()) { string updateDish = $"UPDATE dish SET NAME='{newName}', PRICE='{price}' WHERE NAME='{oldName}';"; conn.RunCommand(updateDish); conn.Close(); List <IngredientDTO> oldIngredients = FindByName(oldName).Ingredients; // Remove all identical entries // Everything left in oldIngredients should be removed after, // Everything left in ingredients should be added List <IngredientDTO> temp = new(); temp.AddRange(ingredients); foreach (IngredientDTO i in temp) { if (oldIngredients == null || oldIngredients.Count == 0) { break; } if (oldIngredients.Exists(oldIngredient => oldIngredient.Name == i.Name)) { oldIngredients.RemoveAll(oldIngredient => oldIngredient.Name == i.Name); ingredients.Remove(i); } } DishDTO curr = FindByName(newName); if (ingredients != null && ingredients.Count > 0) { foreach (IngredientDTO i in ingredients) { //add new DishIngredientRelationDAL().Add(i, curr); } } if (oldIngredients != null && oldIngredients.Count > 0) { foreach (IngredientDTO i in oldIngredients) { new DishIngredientRelationDAL().Remove(i, curr); } } return(true); } return(false); }
public void UpdateDish(DishDTO dish) { try { DishDAO.Instance.UpdateDish(dish); } catch (MySqlException ex) { throw new BUSException(ex.Message); } }
public IActionResult Post([FromBody] DishDTO dishDTO) { try { return(new OkObjectResult(_appService.Insert(dishDTO))); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public void UpdateDish(DishDTO modifiedDish) { var entry = AutoMapper.Mapper.Map <Dish>(modifiedDish); var attachedentry = this.dbContext.Dishes.Find(entry.Id); if (attachedentry != null) { ((DbContext)this.dbContext).Entry(attachedentry).CurrentValues.SetValues(entry); this.dbContext.SaveChanges(); } }
public void EditDishName(int id, DishDTO dish) { if (dish.Name == "") { throw new AbsentDataException("Name of dish cannot be empty"); } var newDish = _data.Dishes.Get(id); newDish.Name = dish.Name; _data.Dishes.Update(newDish); _data.Save(); }
public void EditDishTime(int id, DishDTO dish) { if (dish.Time == 0) { throw new AbsentDataException("Parameters like time, weight or price cannot be 0"); } var newDish = _data.Dishes.Get(id); newDish.Time = dish.Time; _data.Dishes.Update(newDish); _data.Save(); }
public IActionResult Put([FromBody] DishDTO dishDTO) { try { _appService.Update(dishDTO); return(new OkResult()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <ActionResult> Edit(IFormFile uploadedFile, [FromForm] EditDithViewModel model) { if (ModelState.IsValid) { try { DishDTO dishDTO = null; string path = null; // сохранение картинки if (uploadedFile != null) { path = uploadedFile.FileName; // сохраняем файл в папку files/provider/ в каталоге wwwroot using (var fileStream = new FileStream(_appEnvironment.WebRootPath + _path + path, FileMode.Create)) { await uploadedFile.CopyToAsync(fileStream); _logger.LogInformation($"{DateTime.Now.ToString()}: Save image {path}"); } } else { path = model.Path; } dishDTO = new DishDTO { Id = model.Id, Info = model.Info, Name = model.Name, Path = path.Replace(_path, ""), Price = model.Price, Weight = model.Weight, CatalogId = model.CatalogId }; _dishService.EditDish(dishDTO); string currentUserId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; _logger.LogInformation($"{DateTime.Now.ToString()}: User {currentUserId} edit dish {model.Id}"); return(RedirectToAction("Index", new { dishDTO.CatalogId })); } catch (ValidationException ex) { ModelState.AddModelError(ex.Property, ex.Message); _logger.LogError($"{DateTime.Now.ToString()}: {ex.Property}, {ex.Message}"); } } return(View(model)); }
public void MakeDish(DishDTO dishDto) { if (!IsTitleUnique(dishDto.Title, GetDishes())) { throw new BLValidationException("Название уже существует", "Title"); } dishDto.CreationDate = DateTime.Now; Dish dish = DTOtoDish(dishDto); Database.Dishes.Create(dish); Database.Save(); }
public AddDishForm(DishDTO dishDTO, Utils.Operation operation) { InitializeComponent(); this.operation = operation; dishBS.DataSource = Item = dishDTO; textDishName.DataBindings.Add("EditValue", dishBS, "Name", true, DataSourceUpdateMode.OnPropertyChanged); textDishDescription.DataBindings.Add("EditValue", dishBS, "Description", true, DataSourceUpdateMode.OnPropertyChanged); textDishPrice.DataBindings.Add("EditValue", dishBS, "Price", true, DataSourceUpdateMode.OnPropertyChanged); switch (operation) { case Utils.Operation.Add: break; case Utils.Operation.Update: if (((DishDTO)Item).Photo != null && ((DishDTO)Item).Photo.Length > 0) { int stratIndex = ((DishDTO)Item).Filename.IndexOf('.'); string typeFile = ((DishDTO)Item).Filename.Substring(stratIndex); switch (typeFile) { default: //Bitmap bitmap = new Bitmap(drawingScanDTO.Scan); ImageConverter ic = new ImageConverter(); Image img = (Image)ic.ConvertFrom(((DishDTO)Item).Photo); Bitmap bitmap1 = new Bitmap(img); scanPictureEdit.Properties.SizeMode = PictureSizeMode.Zoom; scanPictureEdit.EditValue = bitmap1; //fileNameTbox.EditValue = drawingScanDTO.FileName; break; } } break; default: break; } //this.dishDTO = dishDTO; }
private DishModel ConvertDishDTOToDishModel(DishDTO dto) { return(new DishModel() { Id = dto.Id, Info = dto.Info, AddMenu = dto.AddMenu, CatalogId = dto.CatalogId, Name = dto.Name, Path = _path + dto.Path, Price = dto.Price, Weight = dto.Weight }); }
private Dish DTOtoDish(DishDTO dishDTO) { return(new Dish { Title = dishDTO.Title, Id = dishDTO.Id, TimeToMake = dishDTO.TimeToMake, Description = dishDTO.Description, Ingredients = dishDTO.Ingredients, CreationDate = dishDTO.CreationDate, Calories = dishDTO.Calories, Price = dishDTO.Price, Weight = dishDTO.Weight }); }
public MySqlDataReader UpdateDish(DishDTO dish) { try { //ExcuteQuery MySqlDataReader reader = MySqlConnectionDAO.Instance.ExcuteProcedure("UpdateDish", new MySqlParameter("@_ID", dish.ID), new MySqlParameter("@_DishName", dish.Name), new MySqlParameter("@_UnitPrice", dish.UnitPrice), new MySqlParameter("@_ImagePath", dish.ImagePath)); return(reader); } finally { } }