Exemple #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 }));
        }