Example #1
0
        public MacroElement AddMacroElement(AddMacroElementBindingModel model)
        {
            var newMacroElement = new MacroElement
            {
                Name                  = model.Name,
                Description           = model.Description,
                CaloricContentPerGram = model.CaloricContentPerGram
            };

            this.context.MacroElements.Add(newMacroElement);
            context.SaveChanges();

            if (model.Image != null)
            {
                var macroElementId = this.context.MacroElements.First(mi => mi.Name == model.Name).Id;

                var imageLocation = this.imagesService.CreateImage(model.Image, this.GetType().Name.Replace("Service", string.Empty), macroElementId);

                this.context.MacroElements.First(mi => mi.Id == macroElementId).ImageLocation = imageLocation;
                newMacroElement.ImageLocation = imageLocation;
                context.SaveChanges();
            }

            return(newMacroElement);
        }
Example #2
0
        public IActionResult Add_Macro_Element(AddMacroElementBindingModel model)
        {
            if (this.ModelState.IsValid)
            {
                this.contentService.AddMacroElement(model);
                return(RedirectToAction("ContentMenu"));
            }

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

            return(View("ContentMenu", reloadModel));
        }