Example #1
0
        public ActionResult Create(FactoryTemplateViewModel factoryTemplateViewModel)
        {
            if (ModelState.IsValid)
            {
                var factoryTemplate = Mapper.Map <FactoryTemplate>(factoryTemplateViewModel);
                Data.FactoryTemplates.Add(factoryTemplate);
                Data.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(factoryTemplateViewModel));
        }
Example #2
0
        public ActionResult Edit(FactoryTemplateViewModel factoryTemplateViewModel)
        {
            if (ModelState.IsValid)
            {
                FactoryTemplate factoryTemplate = this.Mapper.Map <FactoryTemplate>(factoryTemplateViewModel);
                if (factoryTemplateViewModel.ImageFromView == null)
                {
                    factoryTemplate.Image = (byte[])TempData["image"];
                }

                if (TempData.ContainsKey("image"))
                {
                    TempData.Remove("image");
                }

                this.Data.FactoryTemplates.Update(factoryTemplate);
                this.Data.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ImageId = new SelectList(this.Data.FactoryTemplates.All(), "Id", "Name", factoryTemplateViewModel.Id);
            return(View(factoryTemplateViewModel));
        }