Exemplo n.º 1
0
        public IActionResult Create()
        {
            var viewModel = new CreatePlannedTaskInputModel();

            viewModel.CategoriesItems = this.categoriesService.GetAllAsKeyValuePairs();
            return(this.View(viewModel));
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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"));
        }