public ActionResult Dish(DishModel dishModel) { TimPartyDbEntities ORM = new TimPartyDbEntities(); string userEmail = User.Identity.Name; Guest currentUser = ORM.Guests.FirstOrDefault(i => i.Email == userEmail); dishModel.Email = currentUser.Email; dishModel.PersonName = currentUser.FirstName + " " + currentUser.LastName; if (ModelState.IsValid) { Dish newDish = new Dish(); newDish.PersonName = dishModel.PersonName; newDish.DishName = dishModel.DishName; newDish.DishDescription = dishModel.DishDescription; newDish.FoodOption = dishModel.FoodOption; newDish.Email = dishModel.Email; newDish.PhoneNumber = dishModel.PhoneNumber; ORM.Dishes.Add(newDish); ORM.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(View()); }
public async Task <AOResult> CreateAsync(DishModel dish) { var result = new AOResult(); try { var content = new { Name = dish.Name, DishCategory = dish.CategoryType }; var response = await _baseService.PostAsync <ResponseModel>(NameController, content); if (response != null) { if (response.IsSuccess) { result.SetSuccess(); } else { result.SetFailure(); } } } catch (Exception ex) { result.SetError(nameof(CreateAsync), ex.Message, ex); } return(result); }
public IActionResult Put(DishModel model) { try { _dishService.EditDish(ConvertDishModelToDishDTO(model)); string currentEmail = this.User.FindFirst(ClaimTypes.Name).Value; string userId = _userHelper.GetUserId(currentEmail); if (userId == null) { return(NotFound("User not found")); } _logger.LogInformation($"[{DateTime.Now.ToString()}]:[dish/put]:[info:edit dish {model.Id}]:[user:{userId}]"); return(Ok(model)); } catch (ValidationException ex) { _logger.LogError($"[{DateTime.Now.ToString()}]:[dish/put]:[error:{ex.Property}, {ex.Message}]"); return(BadRequest(ex.Message)); } catch (Exception ex) { _logger.LogError($"[{DateTime.Now.ToString()}]:[dish/put]:[error:{ex}]"); return(BadRequest()); } }
public ActionResult AddDishes(int id, string quanity) { int IdTable = (int)Session["table"]; DishModel dishModel = new DishModel(); if (Session[$"order{IdTable}"] == null) { List <Item> order = new List <Item>(); order.Add(new Item { Dish = dishModel.find(id), Quantity = 1 }); Session[$"order{IdTable}"] = order; } else { List <Item> order = (List <Item>)Session[$"order{IdTable}"]; int index = isExist(id); if (index != -1) { order[index].Quantity++; } else { order.Add(new Item { Dish = dishModel.find(id), Quantity = 1 }); } Session[$"order{IdTable}"] = order; } return(RedirectToAction("Index")); }
public DishModel GetDish(int idPeriod, int idDishType) { var modelReturn = new DishModel(); var resultDish = _dishService.Get().Where(x => x.PeriodId == idPeriod && x.DishTypeId == idDishType && x.Active).FirstOrDefault(); var resultDishType = _dishTypeService.Get(idDishType); if (resultDishType == null) { throw new System.Exception("Dish Type Invalid"); } if (resultDish != null) { modelReturn.Description = resultDish.Description; modelReturn.Order = resultDishType.Order; modelReturn.Quantity = 1; } else { modelReturn.Description = "error"; modelReturn.Order = resultDishType.Order; } return(modelReturn); }
public async Task <IActionResult> AddDish([FromBody] DishModel dishModel) { if (!ModelState.IsValid) { return(BadRequest()); } List <DishRecipe> recipes = new List <DishRecipe>(); var Id = Guid.NewGuid(); var image = await _imageRepository.GetById(Guid.Parse(dishModel.File)); foreach (RecipeModel recipe in dishModel.Recipes) { recipes.Add(new DishRecipe() { DishId = Id, RecipeId = Guid.Parse(recipe.Id) }); } Dish dish = new Dish() { Id = Id, DishImage = image, DishPrice = dishModel.Price, Name = dishModel.Dish, Recipes = recipes }; _dishRepository.Create(dish); return(Ok()); }
private void addDishToCard() { DishModel tmp = SelectedDish; dishesNames.Add(tmp.Name); Card.Add(tmp); }
public void SaveDish(byte[] image, DishModel model) { var entity = _dishRepo.GetSingle(model.dishId); if (entity == null) { _dishRepo.Add(new TblDish { MENU_ID = model.menuId, IMAGE = image, DESCRIPTION = model.description, IS_SPECIAL = model.isSpecial, NAME = model.name, PRICE = model.price }); } else { entity.IMAGE = image; entity.DESCRIPTION = model.description; entity.IS_SPECIAL = model.isSpecial; entity.NAME = model.name; entity.PRICE = model.price; _dishRepo.Edit(entity); } _dishRepo.Commit(); }
public async Task <IActionResult> Put(int id, [FromBody] DishModel model) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var oldDish = _repo.GetDish(id); if (oldDish == null) { return(NotFound($"Couldn't find a dish of {id}")); } _mapper.Map(model, oldDish); if (await _repo.SaveAllAsync()) { return(Ok(_mapper.Map <DishModel>(oldDish))); } } catch (Exception) { } return(BadRequest("Could not update dish")); }
public async Task OnSaveDishCommandAsync() { if (string.IsNullOrWhiteSpace(_dishName)) { await _userDialog.AlertAsync(DishNameMustNotBeEmpty); return; } if (string.IsNullOrWhiteSpace(_categoryType)) { await _userDialog.AlertAsync(CategoryDishMustBeSelected); return; } DishModel dish = new DishModel() { Name = _dishName, CategoryType = GetCategoryFromPicker(_categoryType) }; var result = await _dishService.CreateAsync(dish); if (result.IsSuccess) { await OnDishCommandAsync(); } else { await _userDialog.AlertAsync(ServerError); } }
// GET: Dish public ActionResult Index() { DishModel dishModel = new DishModel(); ViewBag.dishes = dishModel.findAll(); return(View()); }
private void clearAddRecipePage() { this.newDishModel = new DishModel(); this.newRecipeIngredients = new List <IngredientModel>(); this.newRecipeNameTextField.Text = string.Empty; this.newRecipeDescriptionRichTextField.Text = string.Empty; this.newRecipeImageLabel.Image = imageHelper.GetDishDefaultImage(); }
public ActionResult AddOrderToTable(int id) { Session["table"] = id; DishModel dishModel = new DishModel(); ViewBag.dishes = dishModel.findAll(); return(RedirectToAction("Index")); }
public void AddDish(DishModel model) { var newDishId = dishProvider.AddDish(model); foreach (var ingredient in model.Ingredients) { ingredient.DishId = newDishId; ingredientProvider.AddIngredient(ingredient); } }
private DishModel CreateNewModel(DishModel model) => new DishModel() { CategoryType = model.CategoryType, IsHightPrice = model.IsHightPrice, Id = model.Id, Name = model.Name, IsSelected = false };
private void InitializeRecipeAdding() { ingredientsTableView.AutoScroll = true; ingredientsTableView.Padding = commonTablePadding; this.newRecipeImageLabel.Image = imageHelper.GetDishDefaultImage(); this.newDishModel = new DishModel(); this.firstDishDeleteIconLabel.Image = Resources.DeleteIcon; this.secondDishDeleteIconLabel.Image = Resources.DeleteIcon; }
/// <summary> /// Adds new user model to DB /// </summary> /// <param name="dish">Dish model to add</param> /// <returns>Id of new dish</returns> public int AddDish(DishModel dish) { try { return(_dishRepository.AddDish(dish)); } catch (Exception ex) { throw new Exception("Error while adding dish: " + ex.Message, ex); } }
public IActionResult Update(string id, DishModel dishIn) { var dish = _dishManagementService.Get(id); if (dish == null) { return(NotFound()); } _dishManagementService.Update(id, dishIn); return(NoContent()); }
public static DishModel MakeBuildingResult(SqlDataReader reader) { var model = new DishModel(); model.Id = reader.Get <int>(ColumnNames.DishId); model.Name = reader.Get <string>(ColumnNames.Name); model.CookingInstructions = reader.Get <string>(ColumnNames.CookingInstructions); model.SmallPhotoLink = reader.Get <string>(ColumnNames.SmallPhotoLink); model.BigPhotoLink = reader.Get <string>(ColumnNames.BigPhotoLink); return(model); }
public Task SaveDishesAsync(DishModel dish) { var data = database.Table <DishModel>().Where(x => x.Id == dish.Id).FirstOrDefaultAsync().Result; if (data != null) { return(database.UpdateAsync(dish)); } else { return(database.InsertAsync(dish)); } }
private DishDTO ConvertDishModelToDishDTO(DishModel model) { return(new DishDTO() { Id = model.Id, Info = model.Info, CatalogId = model.CatalogId, Name = model.Name, Price = model.Price, Weight = model.Weight, Path = model.Path.Replace(_path, "") }); }
public int OrderDish(DishModel dish) { var dishEntity = _unit.DishRepository.FindByCondition(d => d.Id == dish.Id).SingleOrDefault(); var dishIngredients = dishEntity.Ingredients.Select(d => d.Ingredient); foreach (var ingredient in dishIngredients) { ingredient.Quantity -= 1; } _unit.DishRepository.Update(dishEntity); return(dish.PrepareTimeInMinutes); }
public async Task <bool> UpdateDishAsync(int restaurantId, int id, DishModel dish) { dish.Id = id; await GetDishAsync(restaurantId, id); repository.UpdateDish(mapper.Map <DishEntity>(dish)); var res = await repository.SaveChangesAsync(); if (res) { return(true); } throw new Exception("Database Exception"); }
public async Task <JsonResult> Edit( [Bind(Include = "Id, Name, Description, Price, CategoryId, RestaurantId, KeywordIds")] DishModel model) { var returnUrl = "/Dishes"; if (!ModelState.IsValid) { return(Json(MessageAlertCenter.GetMessageAlert(MessageAlertType.Invalid, message: "Please enter all fields are required!"))); } var categoryId = await _unitOfWork.Categories.SingleOrDefault(c => c.Id == model.CategoryId); var restaurantId = await _unitOfWork.Restaurants.SingleOrDefault(r => r.Id == model.RestaurantId); var dish = await _unitOfWork.Dishes.Get(model.Id); if (categoryId == null || restaurantId == null || dish == null) { return(Json(MessageAlertCenter.GetMessageAlert(MessageAlertType.BadRequest, returnUrl))); } dish.Keywords = new List <Keyword>(); if (model.KeywordIds.Any()) { foreach (var kw in model.KeywordIds) { var findKeyword = await _unitOfWork.Keywords.SingleOrDefault(k => kw == k.Id); dish.Keywords.Add(findKeyword); } } dish.CategoryId = model.CategoryId; dish.RestaurantId = model.RestaurantId; dish.Name = model.Name; dish.Price = model.Price; dish.Description = model.Description; _unitOfWork.Dishes.Update(dish); await _unitOfWork.Completed(); return(Json(MessageAlertCenter.GetMessageAlert(MessageAlertType.Success, message: "This dish has been updated successfully!", returnUrl: $"/Dishes/Detail/{dish.Id}"))); }
public ActionResult <DishModel> Post(DishModel model) { try { var dish = _mapper.Map <Dish>(model); _repository.Add(dish); if (_repository.Save()) { return(Created($"/api/dishes/{dish.Id}", _mapper.Map <DishModel>(dish))); } } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } return(BadRequest()); }
public async Task <DishModel> CreateDishAsync(int RestaurantId, DishModel newDish) { await ValidateRestaurantAsync(RestaurantId); newDish.RestaurantId = RestaurantId; var dishEntity = mapper.Map <DishEntity>(newDish); repository.CreateDish(dishEntity); var res = await repository.SaveChangesAsync(); if (res) { return(mapper.Map <DishModel>(dishEntity)); } throw new Exception("Database Exception"); }
bool isConfirmedDishRemoving(DishModel dishToDelete) { StringBuilder confirmMessage = new StringBuilder(); confirmMessage.Append("Do you really want to delete \""); confirmMessage.Append(dishToDelete.Name); confirmMessage.Append("\" recipe?"); DialogResult confirmResult = MessageBox.Show( confirmMessage.ToString(), "Confirm deleting", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { return(true); } return(false); }
public IActionResult AddDish(DishModel model) { using (TransactionScope scope = new TransactionScope()) { var newDishId = dishProvider.AddDish(model); foreach (var ingredient in model.Ingredients) { ingredient.DishId = newDishId; ingredientProvider.AddIngredient(ingredient); } // The Complete method commits the transaction. If an exception has been thrown, // Complete is not called and the transaction is rolled back. scope.Complete(); } return(Ok()); }
public async Task <JsonResult> Create( [Bind(Include = "Name, Description, Price, CategoryId, RestaurantId, KeywordIds")] DishModel model) { var returnUrl = "/Dishes/Create"; if (!ModelState.IsValid) { return(Json(MessageAlertCenter.GetMessageAlert(MessageAlertType.Invalid, message: "Please enter all fields are required!"))); } var categoryId = await _unitOfWork.Categories.SingleOrDefault(c => c.Id == model.CategoryId); var restaurantId = await _unitOfWork.Restaurants.SingleOrDefault(r => r.Id == model.RestaurantId); if (categoryId == null || restaurantId == null) { return(Json(MessageAlertCenter.GetMessageAlert(MessageAlertType.BadRequest, returnUrl))); } var dish = Mapper.Map <DishModel, Dish>(model); if (model.KeywordIds.Any()) { foreach (var kw in model.KeywordIds) { var findKeyword = await _unitOfWork.Keywords.SingleOrDefault(k => kw == k.Id); dish.Keywords.Add(findKeyword); } } _unitOfWork.Dishes.Add(dish); await _unitOfWork.Completed(); return(Json(MessageAlertCenter.GetMessageAlert(MessageAlertType.Success, message: "This dish has been added successfully! You will be moved to next page to add some images.", returnUrl: $"/Images/Create/{dish.Id}"))); }
public async Task <IActionResult> SaveDish(IFormFile dishImage, int dishId, string name, bool isSpecial, string description, double price, int menuId) { var model = new DishModel { dishId = dishId, name = name, isSpecial = isSpecial, description = description, price = price, menuId = menuId }; if (dishImage != null && dishImage.Length > 0) { var readStream = dishImage.OpenReadStream(); byte[] image = new byte[dishImage.Length]; await readStream.ReadAsync(image, 0, (int)dishImage.Length); _adminService.SaveDish(image, model); return(Ok(new { response = "dish has been successfully updated" })); } return(BadRequest(new { response = "dish update failed" })); }