Beispiel #1
0
        public async Task <IActionResult> Create(ProjectCreateViewModel model)
        {
            if (!TryValidateModel(model))
            {
                return(View());
            }

            Project project = new Project()
            {
                Titel        = model.Titel,
                Beschrijving = model.Beschrijving,
                Status       = _context.Status.SingleOrDefault(s => s.Id == model.Status)
            };

            using (var memoryStream = new MemoryStream())
            {
                await model.Image.CopyToAsync(memoryStream);

                project.Image = memoryStream.ToArray();
            }

            List <string> newTags = new List <string>();

            foreach (var tag in model.Tags.Split(' '))
            {
                newTags.Add(tag.Trim());
            }

            _context.Insert(project);
            _context.AssignTags(newTags, project.Id);

            return(RedirectToAction("Project", new { id = project.Id }));
        }