Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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());
            }
        }
Esempio n. 4
0
        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"));
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 8
0
        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"));
        }
Esempio n. 10
0
        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);
            }
        }
Esempio n. 11
0
        // GET: Dish
        public ActionResult Index()
        {
            DishModel dishModel = new DishModel();

            ViewBag.dishes = dishModel.findAll();
            return(View());
        }
Esempio n. 12
0
 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();
 }
Esempio n. 13
0
        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);
     }
 }
Esempio n. 15
0
 private DishModel CreateNewModel(DishModel model)
 => new DishModel()
 {
     CategoryType = model.CategoryType,
     IsHightPrice = model.IsHightPrice,
     Id           = model.Id,
     Name         = model.Name,
     IsSelected   = false
 };
Esempio n. 16
0
        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;
        }
Esempio n. 17
0
 /// <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);
     }
 }
Esempio n. 18
0
        public IActionResult Update(string id, DishModel dishIn)
        {
            var dish = _dishManagementService.Get(id);

            if (dish == null)
            {
                return(NotFound());
            }
            _dishManagementService.Update(id, dishIn);

            return(NoContent());
        }
Esempio n. 19
0
        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);
        }
Esempio n. 20
0
        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));
            }
        }
Esempio n. 21
0
 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, "")
     });
 }
Esempio n. 22
0
        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);
        }
Esempio n. 23
0
        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}")));
        }
Esempio n. 25
0
 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());
 }
Esempio n. 26
0
        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");
        }
Esempio n. 27
0
        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);
        }
Esempio n. 28
0
        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}")));
        }
Esempio n. 30
0
        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" }));
        }