public ActionResult StaffPortal(Employee employee, int?id)
        {
            DisplayBags();

            id = Convert.ToInt32(Session["EmpId"]);
            var        pm = db.AssignedPMs.ToList();
            AssignedPM a  = new AssignedPM();

            foreach (var item in pm)
            {
                if (item.EmpId.Equals(id))
                {
                    a.EmpId = item.EmpId;
                    Session["ProjectManager"] = "true";
                }
            }
            Session["Path"] = "/Staff/AuthenticatePM";

            DataTable dt = new DataTable();

            try
            {
                using (SqlConnection con = new SqlConnection())
                {
                    con.ConnectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=IdaDB;Integrated Security=True";

                    SqlCommand cmd = new SqlCommand("select distinct Project.ProjectName, Assignment.ProjectId from Project,Employee,Assignment where Assignment.ProjectId = Project.ProjectId and Assignment.EmpId =" + id + "", con);

                    cmd.CommandType = CommandType.Text;
                    con.Open();


                    using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                    {
                        sda.Fill(dt);
                    }
                    con.Close();
                }
            }
            catch (SqlException ex)
            {
                ModelState.AddModelError("", "Too many records will be returned, please try to minimize your selection and try again." + ex);
            }
            return(View(dt));
        }
        public ActionResult AuthenticatePM(int?id, AssignedPM pM)
        {
            DataTable dt = new DataTable();

            id = Convert.ToInt32(Session["EmpId"]);
            try
            {
                //var GetPM = db.AssignedPMs.SqlQuery("select e.[Name] , apm.EmpId from [IdaDB].[dbo].[Employee] e, [IdaDB].[dbo].[AssignedPM] apm where e.EmpId = apm.EmpId and apm.EmpId =" + id);

                var        pm = db.AssignedPMs.ToList();
                AssignedPM a  = new AssignedPM();
                foreach (var item in pm)
                {
                    if (item.EmpId.Equals(id))
                    {
                        a.EmpId = item.EmpId;
                    }
                }

                if (a.EmpId == id)
                {
                    return(RedirectToAction("Dashboard", "Manager"));
                }
                else
                {
                    TempData["AlertMessage"] = "You are not assigned as Project Manager to any project";
                    return(RedirectToAction("StaffPortal", "Staff"));
                }
            }

            catch (SqlException ex)
            {
                ModelState.AddModelError("", "Too many records will be returned, please try to minimize your selection and try again." + ex);
            }
            return(View(dt));
        }
Esempio n. 3
0
        public ActionResult ProjectAssigne(User user, Project project, Employee employee, Models.Task task, SubTask sub, Assignment assignment, AssignedPM pM)
        {
            try
            {
                var GetUser = db.Employees.Where(c => c.Position.Equals("CEO") && !db.AssignedPMs.Select(b => b.EmpId).Contains(c.EmpId));
                ViewBag.ChooseUser = new SelectList(GetUser, "EmpId", "Email");

                var ProjectsNames = db.Projects.Where(c => !db.AssignedPMs.Select(b => b.ProjectId).Contains(c.ProjectId));
                ViewBag.ProjectName = new SelectList(ProjectsNames, "ProjectId", "ProjectName");


                var UserId = db.Employees.Find(employee.EmpId);
                var ProId  = db.Projects.Find(project.ProjectId);

                if (UserId == null || ProId == null)
                {
                    ViewBag.ErrorBox = "All field are required!!!";
                }
                else
                {
                    pM.DateAssigned = DateTime.Now;
                    pM.EmpPosition  = "Project Manager";
                    db.AssignedPMs.Add(pM);
                    db.SaveChanges();
                    TempData["AlertMessage"] = "Assigned Succefully!!!";
                }
            }
            catch
            {
            }
            return(View(assignment));
        }