Exemple #1
0
        public ActionResult AssignTask([Bind(Include = "Description, EmployeeId")] GTask task)
        {
            if (User.Identity.IsAuthenticated)
            {
                Guid userId = Guid.Parse(User.Identity.GetUserId());
                var  emp    = db.Employees.Find(userId);

                if (emp.IsManager)
                {
                    if (ModelState.IsValid)
                    {
                        task.DateAssigned = DateTime.Now;
                        task.IsDone       = false;

                        db.Tasks.Add(task);
                        db.SaveChanges();

                        Employee employee = db.Employees.Find(task.EmployeeId);
                        Productivity.TeamProductivity(employee.Team);
                        Productivity.CalculateProductivity(employee);
                        Productivity.TeamProductivity(employee.Team);
                        db.Entry(employee).State = EntityState.Modified;
                        db.SaveChanges();
                        return(RedirectToAction("Edit", employee));
                    }

                    return(View(task));
                }

                return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized));
            }

            return(RedirectToAction("Login", "Account"));
        }
        // GET: Tasks/MarkAsDone
        public ActionResult MarkAsDone(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var task = db.Tasks.Find(id);

            task.IsDone          = true;
            db.Entry(task).State = EntityState.Modified;
            db.SaveChanges();

            Employee employee = db.Employees.Find(task.EmployeeId);

            Productivity.CalculateProductivity(employee);
            Productivity.TeamProductivity(employee.Team);
            db.Entry(employee).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemple #3
0
        // GET: Tasks/RemoveTask/{id}
        public ActionResult RemoveTask(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GTask gTask = db.Tasks.Find(id);

            if (gTask == null)
            {
                return(HttpNotFound());
            }
            db.Tasks.Remove(gTask);
            db.SaveChanges();

            Employee employee = db.Employees.Find(gTask.EmployeeId);

            Productivity.CalculateProductivity(employee);
            Productivity.TeamProductivity(employee.Team);
            db.Entry(employee).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Edit", db.Employees.Find(gTask.EmployeeId)));;
        }