Example #1
0
        public IActionResult EditMacroElement(EditMacroElementViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                this.contentService.EditMacroElement(model);
                return(RedirectToAction("Edit_Macro_Elements",
                                        new { currentPage = model.CurrentPage, searchText = model.SearchText, initialOpen = "false" }));
            }

            var reloadModel = this.menuService.GetMenuItems(this.GetType(), typeof(HttpGetAttribute), typeof(AuthorizeAttribute), AreaName, "OpenMacroElementForEditing", model);

            return(View("ContentMenu", reloadModel));
        }
Example #2
0
        public MacroElement EditMacroElement(EditMacroElementViewModel model)
        {
            var macroElement = this.context.MacroElements.FirstOrDefault(me => me.Id == model.Id);

            if (macroElement == null)
            {
                return(null);
            }

            macroElement.Name                  = model.Name;
            macroElement.Description           = model.Description;
            macroElement.CaloricContentPerGram = model.CaloricContentPerGram;

            if (model.NewImage != null)
            {
                string newImageLocation = this.imagesService.RecreateImage(model.NewImage, this.GetType().Name.Replace("Service", string.Empty), model.ImageLocation, model.Id);
                macroElement.ImageLocation = newImageLocation;
            }

            context.SaveChanges();
            return(macroElement);
        }