コード例 #1
0
        public ActionResult Create(CardViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Create", new { id = model.CardId }));
            }

            var tempService  = new TemplateService();
            var tempPropList = tempService.GetTemplateProperties(model.TemplateId);

            var cardService = new CardService();

            cardService.ClearProperties(model.CardId);

            for (var i = 0; i < model.Values.Count(); i++)
            {
                var cardProperty = new CardPropCreate()
                {
                    TemplatePropId = tempPropList[i].Id,
                    Value          = model.Values[i],
                    CardId         = model.CardId
                };
                bool isCreated = cardService.CreateCardProperty(cardProperty);
                if (!isCreated)
                {
                    ModelState.AddModelError("", "Property could not be created.");

                    return(RedirectToAction("Create", new { id = model.CardId }));
                }
            }

            TempData["SaveResult"] = "Card Created";
            return(RedirectToAction("Details", "Card", new { id = model.CardId }));
        }
コード例 #2
0
        public bool CreateCardProperty(CardPropCreate model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                TemplateProperty tempProp = ctx.TemplateProperties.Find(model.TemplatePropId);
                var entity = new CardProperty(tempProp)
                {
                    CardId = model.CardId,
                    Value  = model.Value
                };

                ctx.CardProperties.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #3
0
        public void SeedValues(int cardId, IList <TemplatePropDetail> tempPropList)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Cards.Single(e => e.Id == cardId);

                foreach (var property in tempPropList)
                {
                    var cardProp = new CardPropCreate
                    {
                        TemplatePropId = property.Id,
                        CardId         = cardId,
                        Value          = "x"
                    };
                    CreateCardProperty(cardProp);
                }
            }
        }