public IActionResult Create() { var viewModel = new CreatePlannedTaskInputModel(); viewModel.CategoriesItems = this.categoriesService.GetAllAsKeyValuePairs(); return(this.View(viewModel)); }
public async Task CreateAsync(CreatePlannedTaskInputModel input, string userId) { var plannedTask = new PlannedTask { Title = input.Title, Date = input.Date, StartTime = input.StartTime, EndTime = input.EndTime, Description = input.Description, CategoryId = input.CategoryId, CreatedByUserId = userId, }; await this.plannedTasksRepository.AddAsync(plannedTask); await this.plannedTasksRepository.SaveChangesAsync(); }
public async Task <IActionResult> Create(CreatePlannedTaskInputModel input) { if (!this.ModelState.IsValid) { input.CategoriesItems = this.categoriesService.GetAllAsKeyValuePairs(); return(this.View(input)); } var user = await this.userManager.GetUserAsync(this.User); try { await this.plannedTasksService.CreateAsync(input, user.Id); } catch (Exception ex) { this.ModelState.AddModelError(string.Empty, ex.Message); input.CategoriesItems = this.categoriesService.GetAllAsKeyValuePairs(); return(this.View(input)); } return(this.Redirect("/PlannedTasks/Schedule")); }