public IActionResult Add_Micro_Element(AddMicroElementBindingModel model) { if (this.ModelState.IsValid) { this.contentService.AddMicroElement(model); return(RedirectToAction("ContentMenu")); } var reloadModel = this.menuService.GetMenuItems(this.GetType(), typeof(HttpGetAttribute), typeof(AuthorizeAttribute), AreaName, "Add_Micro_Element", model); return(View("ContentMenu", reloadModel)); }
public MicroElement AddMicroElement(AddMicroElementBindingModel model) { var newMicroElement = new MicroElement { Name = model.Name, Description = model.Description, }; switch (model.Type) { case "Vitamin": newMicroElement.IsVitamin = true; break; case "Mineral": newMicroElement.IsMineral = true; break; case "Other": newMicroElement.IsOther = true; break; } this.context.MicroElements.Add(newMicroElement); this.context.SaveChanges(); if (model.Image != null) { var microElementId = this.context.MicroElements.First(mi => mi.Name == model.Name).Id; var imageLocation = this.imagesService.CreateImage(model.Image, this.GetType().Name.Replace("Service", string.Empty), microElementId); this.context.MicroElements.First(mi => mi.Id == microElementId).ImageLocation = imageLocation; newMicroElement.ImageLocation = imageLocation; context.SaveChanges(); } return(newMicroElement); }