Example #1
0
        public async Task <IActionResult> Create(CodeViewModel model)
        {
            if (ModelState.IsValid)
            {
                var code = model.Code;
                var tags = new List <Tag>();
                if (!string.IsNullOrEmpty(model.SelectedTags))
                {
                    tags = (await tagsService.ParseTags(model.SelectedTags)).ToList();
                }

                code.CodeTags = tags.Select(t => new CodeTag
                {
                    TagId = t.Id
                }).ToList();
                code.User = await userManager.GetUserAsync(User);

                code.Created = DateTime.Now;

                await codeRepository.CreateAsync(code);

                return(RedirectToAction("Detail", new { id = code.Id }));
            }
            Console.WriteLine(ModelState.ErrorCount);

            ModelState.AddModelError("", "Vyplňte všechna povinná pole prosím.");

            return(View(model));
        }