public IActionResult CreateTask(CreateTaskPostData createTaskPostData) { if (!ModelState.IsValid) { return(RedirectToAction(nameof(Index), new { message = "Please fill all fields to create task" })); } TestTaskDb testTaskDb = new TestTaskDb { Title = createTaskPostData.Title, Description = createTaskPostData.Decription, Status = (int)TaskStatus.New }; TestTaskDb createdTask = _testTaskContext.Add(testTaskDb).Entity; _testTaskContext.SaveChanges(); return(RedirectToAction(nameof(Index), new { message = $"Task {createdTask.Id} created" })); }
public async Task <IActionResult> CreateTask(DayModel dayModel) { if (!ModelState.IsValid) { return(RedirectToAction("ShowDay", new { dayDate = dayModel.CurrentDate })); } var time = dayModel.Date; var date = DateTime.Parse(dayModel.CurrentDate); dayModel.Date = new DateTime(date.Year, date.Month, date.Day, time.Hour, time.Minute, time.Second); var task = new Task { Text = dayModel.Text, Date = dayModel.Date }; _context.Add(task); await _context.SaveChangesAsync(); return(RedirectToAction("ShowDay", new { dayDate = dayModel.Date.ToShortDateString() })); }