Пример #1
0
        public UpdateRecipeViewModel GetRecipeToUpdate(int id)
        {
            var recipeToUpdate = this.GetCookingRecipeById(id);

            var updateModel = new UpdateRecipeViewModel()
            {
                Id = recipeToUpdate.Id,
                Title = recipeToUpdate.Title,
                ShortDescription = recipeToUpdate.ShortDescription,
                ExecutingTime = recipeToUpdate.ExecutingTime,
                Content = recipeToUpdate.Content,
                CoverImageFileName = recipeToUpdate.CoverImageFileName
            };

            if (recipeToUpdate.Products != null)
            {
                updateModel.ProductsToUpdate = recipeToUpdate.Products.Split((new[] { ',' }), StringSplitOptions.RemoveEmptyEntries).ToHashSet();
            }

            if (recipeToUpdate.Hashtags != null)
            {
                updateModel.HashtagsToUpdate = recipeToUpdate.Hashtags.Split((new[] { ',' }), StringSplitOptions.RemoveEmptyEntries).ToHashSet();
            }

            return updateModel;
        }
Пример #2
0
        public IActionResult UpdateCookingRecipe(UpdateRecipeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            try
            {
                var editorId = this.userManager
                               .GetUserAsync(HttpContext.User)
                               .GetAwaiter().GetResult()
                               .Id;

                this.cookingRecipeService.UpdateCookingRecipeAsync(editorId, model)
                .GetAwaiter().GetResult();

                TempData["statusMessage"] = "Cooking recipe was updated successfully!";
                return(RedirectToAction("Index", "CookingRecipe"));
            }
            catch (System.Exception exeption)
            {
                ModelState.AddModelError("Action Failed!", exeption.Message);

                model = this.cookingRecipeService.GetRecipeToUpdate(model.Id);
                return(this.View(model));

                // Another approach
                // TempData["statusMessage"] = $"Action Failed! | {exeption.Message}";
                // return RedirectToAction("Index", "CookingRecipe");
            }
        }
Пример #3
0
        public IActionResult UpdateCookingRecipe(int id)
        {
            UpdateRecipeViewModel recipeToUpdate = this.cookingRecipeService.GetRecipeToUpdate(id);

            recipeToUpdate.Cloudinary = this.cloudinaryService.GetCloudinaryInstance();

            return(this.View(recipeToUpdate));
        }
Пример #4
0
        public ActionResult UpdateRecipe(int id)
        {
            //need information about a particular pet
            Recipe      selectedrecipe = db.Recipes.SqlQuery("select * from recipes where RecipeID = @id", new SqlParameter("@id", id)).FirstOrDefault();
            List <Chef> chefs          = db.Chefs.SqlQuery("select * from chefs").ToList();

            UpdateRecipeViewModel UpdateRecipeViewModel = new UpdateRecipeViewModel();

            UpdateRecipeViewModel.Recipe = selectedrecipe;
            UpdateRecipeViewModel.Chefs  = chefs;

            return(View(UpdateRecipeViewModel));
        }
Пример #5
0
        public async Task <ActionResult> Update(long id)
        {
            Recipe recipe = this._recipeService.GetById(id);
            UpdateRecipeViewModel model = this._mapper.Map <UpdateRecipeViewModel>(recipe);

            if (await base.IsAdminOrOwner(model.UserId))
            {
                model.Categories = this.GetCategories();

                return(View(model));
            }

            return(RedirectToAction("Index", "Home"));
        }
        public IActionResult Update([FromBody] UpdateRecipeViewModel recipeViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = _recipeService.Update(recipeViewModel);

            if (result.IsError)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Пример #7
0
        public async Task UpdateCookingRecipeAsync(string editorId, UpdateRecipeViewModel viewModel)
        {
            var updatingModel = this.cookingRecipeRepo.GetCookingRecipeById(viewModel.Id);

            updatingModel.Id = viewModel.Id;
            updatingModel.Title = viewModel.Title;
            updatingModel.ShortDescription = viewModel.ShortDescription;
            updatingModel.Products = viewModel.Products;
            updatingModel.Content = viewModel.Content;
            updatingModel.ExecutingTime = viewModel.ExecutingTime;
            updatingModel.Hashtags = viewModel.Hashtags;
            updatingModel.LastModifiedAt = DateTime.UtcNow;
            updatingModel.CoverImageFileName = viewModel.CoverImageFileName;
            //TODO: improve editorsUsernames handling at all (db too)
            //EditorsUsernames = oldCookingRecipe.EditorsUsernames,

            await this.cookingRecipeRepo.UpdateCookingRecipeAsync(updatingModel);
        }
Пример #8
0
 public IActionResult Update([FromBody] UpdateRecipeViewModel model)
 {
     try
     {
         var recipe = myContext.Recipes.FirstOrDefault(x => x.RecipeId == model.RecipeId);
         recipe.Name        = model.Name;
         recipe.Serving     = model.Serving;
         recipe.Time        = model.Time;
         recipe.Prepare     = model.Prepare;
         recipe.Description = model.Description;
         recipe.Category    = model.Category;
         recipe.Calories    = model.Calories;
         myContext.SaveChanges();
         return(Json(new { status = "Success" }));
     }
     catch (System.Exception)
     {
         throw;
     }
 }
Пример #9
0
        public async Task <ActionResult> Update(long id, UpdateRecipeViewModel recipeViewModel)
        {
            if (ModelState.IsValid)
            {
                if (await base.IsAdminOrOwner(recipeViewModel.UserId))
                {
                    if (recipeViewModel.Image != null)
                    {
                        await this._imgurService.EditImage(recipeViewModel);
                    }

                    this._recipeService.UpdateById(id, this._mapper.Map <Recipe>(recipeViewModel));
                }

                return(RedirectToAction("Index", "Home"));
            }

            recipeViewModel.Id         = id;
            recipeViewModel.Categories = this.GetCategories();

            return(View(recipeViewModel));
        }
Пример #10
0
        public ResultDto <RecipeDto> Update(UpdateRecipeViewModel recipeViewModel)
        {
            var result = new ResultDto <RecipeDto>();

            if (!_recipeRepository.Exist(x => x.Id == recipeViewModel.id))
            {
                result.Errors.Add(_Errors.RecipeDoesNotExist);
            }
            if (result.IsError)
            {
                return(result);
            }
            var recipe = _mapper.Map <Recipe>(recipeViewModel);

            if (_recipeRepository.Update(recipe) == 0)
            {
                result.Errors.Add(_Errors.SaveFail);
                return(result);
            }
            result.SuccessResult = _mapper.Map <RecipeDto>(recipe);

            return(result);
        }
 public UpdateRecipeView(tblRecipe recipe, tblPerson user)
 {
     DataContext = new UpdateRecipeViewModel(this, recipe, user);
     InitializeComponent();
 }
Пример #12
0
 public RecipePackage EditRecipe(IModalDialogService modalDialogService, IServiceFactory serviceFactory,
     RecipePackage recipePackage)
 {
     var viewModel = new UpdateRecipeViewModel(modalDialogService, serviceFactory);
       viewModel.RecipePackage = recipePackage;
       viewModel.DialogMode = DialogMode.Update;
       ModalDialogHelper<UpdateRecipe>.ShowDialog(viewModel);
       return viewModel.RecipePackage;
 }
Пример #13
0
 public RecipePackage CreateRecipe(IModalDialogService modalDialogService, IServiceFactory serviceFactory)
 {
     var viewModel = new UpdateRecipeViewModel(modalDialogService, serviceFactory);
       viewModel.RecipePackage = new RecipePackage();
       viewModel.RecipePackage.Recipe = new RecipePrimitive();
       viewModel.DialogMode = DialogMode.Create;
       ModalDialogHelper<UpdateRecipe>.ShowDialog(viewModel);
       if (!viewModel.IsCanceled)
       {
     return viewModel.RecipePackage;
       }
       return null;
 }
Пример #14
0
        public UpdateRecipePage()
        {
            BindingContext = _vm = TinyIoCContainer.Current.Resolve <UpdateRecipeViewModel>();

            InitializeComponent();
        }