Пример #1
0
        public ActionResult Create(CreateTemplateViewModel model)
        {
            using (var repository = new HeadlineRepository())
            {
                if (!repository.GroupIdIsAvailable(model.GroupId))
                {
                    ModelState.AddModelError("GroupId", "Detta grupp id är redan taget.");
                }

                if (ModelState.IsValid)
                {
                    var headlineModels = new List<HeadlineModel>();

                    foreach (var headline in model.Headlines)
                    {
                        HeadlineModel headlineModel = Mapper.Map<HeadlineModel>(headline);
                        headlineModel.GroupId = model.GroupId;
                        headlineModels.Add(headlineModel);
                    }

                    repository.AddHeadlines(headlineModels);
                    repository.Save();
                    return RedirectToAction("Create");
                }
                else
                {
                    return View(model);
                }
            }
        }
Пример #2
0
        public ActionResult Create()
        {
            var model = new CreateTemplateViewModel();

            return View(model);
        }