Ejemplo n.º 1
0
        public IActionResult EditTask(int id)
        {
            Zadanie          task    = _context.Zadania.Find(id);
            List <EmpInTask> eitList = _context.ZadaniaInTasks.Where(f => f.ZadanieID == id).ToList();
            TaskWithEmpsList twel    = new TaskWithEmpsList();
            List <Employee>  empList = _context.Employees.ToList();

            foreach (var empInTask in eitList)
            {
                foreach (var emp in empList)
                {
                    if (empInTask.EmployeeID == emp.EmployeeID)
                    {
                        emp.checkBoxEmp = true;
                    }
                }
            }

            twel.ID            = task.ID;
            twel.StartDate     = task.StartDate;
            twel.StartTime     = task.StartTime;
            twel.EndDate       = task.EndDate;
            twel.EndTime       = task.EndTime;
            twel.Title         = task.Title;
            twel.Description   = task.Description;
            twel.IsEnd         = task.IsEnd;
            twel.EmployeesList = empList;

            return(View(twel));
        }
Ejemplo n.º 2
0
        public ViewResult AddTask()
        {
            var empl = _context.Employees.ToList();
            TaskWithEmpsList twel = new TaskWithEmpsList();

            twel.EmployeesList = empl;
            twel.StartDate     = DateTime.Now;
            twel.StartTime     = DateTime.Now;
            twel.EndDate       = DateTime.Now;
            twel.EndTime       = DateTime.Now;
            return(View(twel));
        }
Ejemplo n.º 3
0
        public IActionResult AddTask([Bind("ID, StartDate, StartTime, EndDate, EndTime, Title, Description, IsEnd, EmployeesList")] TaskWithEmpsList taskEmp)
        {
            taskEmp.IsEnd = false;
            EmpInTask eit;
            Zadanie   task = new Zadanie();
            Employee  empl;

            task.ID          = taskEmp.ID;
            task.StartTime   = taskEmp.StartTime;
            task.StartDate   = taskEmp.StartDate;
            task.EndTime     = taskEmp.EndTime;
            task.EndDate     = taskEmp.EndDate;
            task.Title       = taskEmp.Title;
            task.Description = taskEmp.Description;
            task.IsEnd       = taskEmp.IsEnd;

            if (ModelState.IsValid)
            {
                foreach (var emp in taskEmp.EmployeesList.Where(e => e.checkBoxEmp == true))
                {
                    empl               = new Employee();
                    empl.EmployeeID    = emp.EmployeeID;
                    empl.Name          = emp.Name;
                    empl.Surname       = emp.Surname;
                    empl.DayOfBirthday = emp.DayOfBirthday;
                    empl.EmailAddress  = emp.EmailAddress;
                    empl.PhoneNumber   = emp.PhoneNumber;
                    empl.DeptID        = emp.DeptID;

                    eit         = new EmpInTask();
                    eit.Zadanie = task;
                    // Nie dodawać pracownika do relacji jako obiekt tylko dodawać jako ID :)
                    // Gdy pracownik już istnieje, a nie jest dodawany razem z zadaniem.
                    // Wtedy działa...
                    //eit.Employee = empl;
                    eit.EmployeeID = empl.EmployeeID;
                    _context.ZadaniaInTasks.Add(eit);
                }
                _context.SaveChanges();
                return(RedirectToAction("Main"));
            }
            return(View(taskEmp));
        }
Ejemplo n.º 4
0
        public IActionResult DetailTask(int id)
        {
            var task = _context.Zadania.Include(z => z.Employees).ThenInclude(e => e.Employee).Where(z => z.ID == id).FirstOrDefault();
            TaskWithEmpsList twel = new TaskWithEmpsList();

            twel.ID            = task.ID;
            twel.StartTime     = task.StartTime;
            twel.EndTime       = task.EndTime;
            twel.StartDate     = task.StartDate;
            twel.EndDate       = task.EndDate;
            twel.Title         = task.Title;
            twel.Description   = task.Description;
            twel.EmployeesList = new List <Employee>();
            foreach (EmpInTask item in task.Employees)
            {
                twel.EmployeesList.Add(item.Employee);
            }
            return(View(twel));
        }
Ejemplo n.º 5
0
        public IActionResult EditTask(int id, [Bind("ID, StartDate, StartTime, EndDate, EndTime, Title, Description, IsEnd, EmployeesList")] TaskWithEmpsList taskEmp)
        {
            taskEmp.IsEnd = false;
            EmpInTask eit;
            Zadanie   task = new Zadanie();
            Employee  empl;

            task.ID          = taskEmp.ID;
            task.StartTime   = taskEmp.StartTime;
            task.StartDate   = taskEmp.StartDate;
            task.EndTime     = taskEmp.EndTime;
            task.EndDate     = taskEmp.EndDate;
            task.Title       = taskEmp.Title;
            task.Description = taskEmp.Description;
            task.IsEnd       = taskEmp.IsEnd;

            foreach (var emp in taskEmp.EmployeesList.Where(e => e.checkBoxEmp == true))
            {
                empl               = new Employee();
                empl.EmployeeID    = emp.EmployeeID;
                empl.Name          = emp.Name;
                empl.Surname       = emp.Surname;
                empl.DayOfBirthday = emp.DayOfBirthday;
                empl.EmailAddress  = emp.EmailAddress;
                empl.PhoneNumber   = emp.PhoneNumber;
                empl.DeptID        = emp.DeptID;

                eit           = new EmpInTask();
                eit.ZadanieID = task.ID;
                // Nie dodawać pracownika do relacji jako obiekt tylko dodawać jako ID :)
                // Gdy pracownik już istnieje, a nie jest dodawany razem z zadaniem.
                // Wtedy działa...
                //eit.Employee = empl;
                eit.EmployeeID = empl.EmployeeID;
                if (TaskEmp(eit.EmployeeID, eit.ZadanieID) == false)
                {
                    _context.ZadaniaInTasks.Add(eit);
                    _context.SaveChanges();
                }
            }

            foreach (var emp in taskEmp.EmployeesList.Where(e => e.checkBoxEmp == false))
            {
                eit            = new EmpInTask();
                eit.ZadanieID  = task.ID;
                eit.EmployeeID = emp.EmployeeID;
                if (TaskEmp(eit.EmployeeID, eit.ZadanieID) == true)
                {
                    _context.ZadaniaInTasks.Remove(eit);
                    _context.SaveChanges();
                }
            }

            if (id != task.ID)
            {
                return(Content("ID jest nie prawidłowe."));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Zadania.Update(task);
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TaskExist(task.ID))
                    {
                        return(Content("Zadanie nie istnieje"));
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Main)));
            }
            return(View(taskEmp));
        }