コード例 #1
0
        public ActionResult Create(TemplateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var property = new TemplatePropCreate()
            {
                TemplateId   = model.TemplateId,
                PropertyName = model.PropertyName,
                PropertyType = model.PropertyType
            };

            var service = new TemplateService();

            if (service.CreateTemplateProperty(property))
            {
                TempData["SaveResult"] = "Property Added";
                return(RedirectToAction("Create", new { templateId = model.TemplateId }));
            }
            ;

            ModelState.AddModelError("", "Template Property could not be created.");

            return(View(model));
        }
コード例 #2
0
        public bool SeedNameProperty(int templateId)
        {
            var seedNameProp = new TemplatePropCreate()
            {
                TemplateId   = templateId,
                PropertyName = "Name",
                PropertyType = PropertyType.Text
            };

            return(CreateTemplateProperty(seedNameProp));
        }
コード例 #3
0
        public bool CreateTemplateProperty(TemplatePropCreate model)
        {
            var entity = new TemplateProperty()
            {
                TemplateId   = model.TemplateId,
                PropertyName = model.PropertyName,
                PropertyType = model.PropertyType,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.TemplateProperties.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }