public void CreateTask(CreateTaskBindingModel createTaskBindingModel) { Task task = new Task { Title = createTaskBindingModel.Title, Description = createTaskBindingModel.Description, DueDate = createTaskBindingModel.DueDate, ParticipantsString = createTaskBindingModel.Participants, IsReported = false, }; if (createTaskBindingModel.AffectedSectors != null) { foreach (var affectedSector in createTaskBindingModel.AffectedSectors) { task.AffectedSectors.Add(new TaskSector { Sector = this.context.Sectors.SingleOrDefault(s => s.Name == affectedSector), Task = task }); } } this.context.Tasks.Add(task); this.context.SaveChanges(); }
public IActionResult Create(CreateTaskBindingModel bindingModel) { if (this.ModelState.IsValid != true) { return(this.View()); } this.tasksService.CreateTask(bindingModel); return(this.RedirectToAction("/Home/Index")); }
public IActionResult Create(CreateTaskBindingModel bindingModel) { var task = new Task() { Title = bindingModel.title, DueDate = DateTime.Parse(bindingModel.dueDate), IsReported = false, Description = bindingModel.description, Participants = bindingModel.participants, }; this.context.Tasks.Add(task); context.SaveChanges(); return(RedirectToAction("/")); }