Exemplo n.º 1
0
        public async Task <IActionResult> AddTask(Taskz task)
        {
            if ((task.ChooseStartDate < DateTime.Now) || (task.ChooseEndDate < DateTime.Now) || (task.ChooseStartDate >= task.ChooseEndDate))
            {
                var emp1 = new SelectEmployees()
                {
                    StartDate = task.StartDate,
                    EndDate   = task.EndDate
                };
                var ids1 = await _repo2.SelectEmployees(emp1);

                return(RedirectToAction(nameof(AddTask), new { invalid = true, idss = ids1, start = emp1.StartDate, end = emp1.EndDate }));
            }

            if (ModelState.IsValid)
            {
                int id = await _repo2.AddTask(task);

                if (id > 0)
                {
                    var emp = new SelectEmployees()
                    {
                        StartDate        = task.ChooseStartDate,
                        EndDate          = task.ChooseEndDate,
                        ProjectManagerId = task.ProjectManagerId
                    };
                    var ids = await _repo2.SelectEmployees(emp);

                    return(RedirectToAction(nameof(AddTask), new { Id = id, idss = ids, start = emp.StartDate, end = emp.EndDate, success = true, managerId = task.ProjectManagerId }));
                }
            }

            var emp2 = new SelectEmployees()
            {
                StartDate        = task.ChooseStartDate,
                EndDate          = task.ChooseEndDate,
                ProjectManagerId = task.ProjectManagerId
            };
            var ids2 = await _repo2.SelectEmployees(emp2);

            ViewBag.Employees = (new SelectList(_repo2.GetEmployeesDropdown(ids2), "Id", "Name"));
            ViewBag.Projects  = new SelectList(await _repo.GetCurrentProjects(), "Id", "Name");
            return(View());
        }