public ActionResult AssignEmployees(long empId, long caseId)
        {
            unitOfWork = (GenericUnitOfWork)Session["UNITOFWORK"];
            GenericRepository <Employee_Case> empRepository = unitOfWork.GetRepoInstance <Employee_Case>();
            List <Employee_Case> allAssingedEmps            = empRepository.GetBy(ec => ec.EmployeeID == empId && ec.CaseID == caseId).ToList();

            if (allAssingedEmps == null)
            {
                Employee_Case assignEmp = new Employee_Case();
                assignEmp.EmployeeID = empId;
                assignEmp.CaseID     = caseId;
                assignEmp.AssignDate = DateTime.Now;
                empRepository.Add(assignEmp);

                GenericRepository <Case> empCase = unitOfWork.GetRepoInstance <Case>();
                Case currentCase = empCase.GetBy(c => c.CaseID == caseId).FirstOrDefault();
                currentCase.StatusID = 2;
                empCase.Edit(currentCase);
            }
            else
            {
                Employee_Case currentEmpCase = empRepository.GetBy(ec => ec.EmployeeID == empId && ec.CaseID == caseId).FirstOrDefault();
                currentEmpCase.IsDeleted = false;
                if (currentEmpCase.Case.StatusID == 3)
                {
                    currentEmpCase.Case.StatusID = 2;
                }
                empRepository.Edit(currentEmpCase);
            }

            unitOfWork.SaveChanges();
            return(RedirectToAction("CaseDetails", new { caseId = caseId }));
        }
Пример #2
0
        // Take The new Case
        public ActionResult TakeNewCase(long caseId)
        {
            long userId;

            if (Session["USER"] != null)
            {
                userId = ((User)Session["USER"]).UserID;
            }
            else
            {
                userId = 2;
            }
            unitOfWork = (GenericUnitOfWork)Session["UNITOFWORK"];
            GenericRepository <Case>          caseRepository    = unitOfWork.GetRepoInstance <Case>();
            GenericRepository <Employee_Case> empCaseRepository = unitOfWork.GetRepoInstance <Employee_Case>();

            Employee_Case newRecord = new Employee_Case()
            {
                EmployeeID = userId,
                CaseID     = caseId
            };

            empCaseRepository.Add(newRecord);

            Case updatedCase = caseRepository.GetBy(c => c.CaseID == caseId).FirstOrDefault();

            updatedCase.StatusID = 2;
            caseRepository.Edit(updatedCase);
            unitOfWork.SaveChanges();

            return(RedirectToAction("CaseDetails", new { caseId = caseId }));
        }
Пример #3
0
        // Return Details of a Certain Case
        public ActionResult CaseDetails(long caseId)
        {
            long userId;

            if (Session["USER"] != null)
            {
                userId = ((User)Session["USER"]).UserID;
            }
            else
            {
                userId = 2;
            }
            unitOfWork = (GenericUnitOfWork)Session["UNITOFWORK"];
            GenericRepository <Case>   caseRepository   = unitOfWork.GetRepoInstance <Case>();
            GenericRepository <Status> statusRepository = unitOfWork.GetRepoInstance <Status>();
            Case userCase = caseRepository.GetBy(c => c.CaseID == caseId).FirstOrDefault();

            userCase.Status = statusRepository.GetBy(st => st.StatusID == userCase.StatusID).FirstOrDefault();
            GenericRepository <File> fileRepository = unitOfWork.GetRepoInstance <File>();
            File userFile = fileRepository.GetBy(c => c.CaseID == caseId).FirstOrDefault();

            DateTime End = userCase.SubmissionDate.AddDays(3);

            ViewBag.Timer = End.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;

            CaseDetailsVM caseDetailsVM = new CaseDetailsVM();

            caseDetailsVM.Case = userCase;

            if (userFile != null)
            {
                caseDetailsVM.FileID        = userFile.FileID;
                caseDetailsVM.FileName      = userFile.FileName;
                caseDetailsVM.Content       = userFile.Content;
                caseDetailsVM.SavedFileName = userFile.SavedFileName;
            }
            GenericRepository <Employee_Case> empCaseRepository = unitOfWork.GetRepoInstance <Employee_Case>();

            if (userCase.StatusID == 2)
            {
                Employee_Case empCase = empCaseRepository.GetBy(ec => ec.CaseID == caseId && ec.EmployeeID == userId).FirstOrDefault();
                if (empCase.OpenedAt == null)
                {
                    empCase.OpenedAt = DateTime.Now;
                    empCaseRepository.Edit(empCase);
                    unitOfWork.SaveChanges();
                }
            }
            if (userCase.StatusID == 2 || userCase.StatusID == 3)
            {
                Employee_Case empCase = empCaseRepository.GetBy(ec => ec.CaseID == caseId && ec.EmployeeID == userId).FirstOrDefault();
                if (empCase.OpenedAt != null)
                {
                    DateTime timer2 = (DateTime)empCase.OpenedAt;
                    ViewBag.Timer2 = timer2.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
                }
            }

            return(View(caseDetailsVM));
        }
Пример #4
0
        public ActionResult RemoveAssignedEmployee(long empId, long caseId)
        {
            unitOfWork = (GenericUnitOfWork)Session["UNITOFWORK"];
            GenericRepository <Employee_Case> empRepository = unitOfWork.GetRepoInstance <Employee_Case>();
            Employee_Case empCase = empRepository.GetBy(ec => ec.CaseID == caseId && ec.EmployeeID == empId).FirstOrDefault();

            empCase.IsDeleted = true;
            empRepository.Edit(empCase);
            unitOfWork.SaveChanges();

            return(RedirectToAction("CaseDetails", new { caseId = caseId }));
        }
Пример #5
0
        public ActionResult SubmitRating(Employee_Case empCase)
        {
            unitOfWork = (GenericUnitOfWork)Session["UNITOFWORK"];
            GenericRepository <Employee_Case> empCaseRepository = unitOfWork.GetRepoInstance <Employee_Case>();
            //double? x = empCase.Rating;
            Employee_Case updatedRecord = empCaseRepository.GetBy(ec => ec.CaseID == empCase.CaseID).FirstOrDefault();

            if (updatedRecord != null)
            {
                updatedRecord.Rating = empCase.Rating;
                empCaseRepository.Edit(updatedRecord);

                unitOfWork.SaveChanges();
            }
            return(RedirectToAction("CaseDetails", new { caseId = empCase.CaseID }));
        }
Пример #6
0
        // Save Message
        public ActionResult SendMessage(Message message)
        {
            unitOfWork = (GenericUnitOfWork)Session["UNITOFWORK"];
            GenericRepository <Employee_Case> emp_caseRepository = unitOfWork.GetRepoInstance <Employee_Case>();
            GenericRepository <Message>       messageRepository  = unitOfWork.GetRepoInstance <Message>();

            Employee_Case result = emp_caseRepository.GetBy(ec => ec.CaseID == message.CaseID).LastOrDefault();

            if (result != null)
            {
                message.SenderID       = result.EmployeeID;
                message.SubmissionDate = DateTime.Now;
                messageRepository.Add(message);
            }
            unitOfWork.SaveChanges();
            return(RedirectToAction("CaseDetails", new { caseId = message.CaseID }));
        }
Пример #7
0
        public ActionResult AssignEmployees(long empId, long caseId)
        {
            unitOfWork = (GenericUnitOfWork)Session["UNITOFWORK"];
            GenericRepository <Employee_Case> empRepository = unitOfWork.GetRepoInstance <Employee_Case>();
            Employee_Case assignEmp = new Employee_Case();

            assignEmp.EmployeeID = empId;
            assignEmp.CaseID     = caseId;
            assignEmp.AssignDate = DateTime.Now;
            empRepository.Add(assignEmp);

            GenericRepository <Case> empCase = unitOfWork.GetRepoInstance <Case>();
            Case currentCase = empCase.GetBy(c => c.CaseID == caseId).FirstOrDefault();

            currentCase.StatusID = 2;
            empCase.Edit(currentCase);
            unitOfWork.SaveChanges();
            return(RedirectToAction("CaseDetails", new { caseId = caseId }));
        }
Пример #8
0
        // Given The status of the cases , return List of cases assigned to current employee with the same status
        public List <Case> GetEmpCaseList(bool flag)
        {
            long userId;

            if (Session["USER"] != null)
            {
                userId = ((User)Session["USER"]).UserID;
            }
            else
            {
                userId = 10;
            }
            unitOfWork = (GenericUnitOfWork)Session["UNITOFWORK"];
            GenericRepository <Case>          caseRepository    = unitOfWork.GetRepoInstance <Case>();
            GenericRepository <Employee_Case> empCaseRepository = unitOfWork.GetRepoInstance <Employee_Case>();
            GenericRepository <Employee>      empRepository     = unitOfWork.GetRepoInstance <Employee>();
            Employee currentEmp = empRepository.GetBy(emp => emp.EmployeeID == userId).FirstOrDefault();

            List <Case> assignedCases = caseRepository.GetBy(ac => ac.StatusID == 2 && ac.CategoryID == currentEmp.CategoryID).ToList();
            List <Case> empCases      = new List <Case>();

            foreach (Case assignedCase in assignedCases)
            {
                Employee_Case temp = empCaseRepository.GetBy(c => c.CaseID == assignedCase.CaseID).FirstOrDefault();
                if (flag == true)
                {
                    if (temp.OpenedAt != null)
                    {
                        empCases.Add(assignedCase);
                    }
                }
                else
                {
                    if (temp.OpenedAt == null)
                    {
                        empCases.Add(assignedCase);
                    }
                }
            }
            return(empCases);
        }
Пример #9
0
        // Return Details of a Certain Case
        public ActionResult CaseDetails(long caseId)
        {
            long userId;

            if (Session["USER"] != null)
            {
                userId = ((User)Session["USER"]).UserID;
            }
            else
            {
                return(RedirectToAction("Login", "Login", new { area = "Admin" }));
            }

            unitOfWork = (GenericUnitOfWork)Session["UNITOFWORK"];

            GenericRepository <Case> caseRepository = unitOfWork.GetRepoInstance <Case>();
            Case userCase = caseRepository.GetBy(c => c.CaseID == caseId).FirstOrDefault();

            GenericRepository <File> fileRepository = unitOfWork.GetRepoInstance <File>();
            File userFile = fileRepository.GetBy(c => c.CaseID == caseId).FirstOrDefault();

            CaseDetailsVM caseDetailsVM = new CaseDetailsVM();

            caseDetailsVM.Case = userCase;

            if (userFile != null)
            {
                caseDetailsVM.FileID        = userFile.FileID;
                caseDetailsVM.FileName      = userFile.FileName;
                caseDetailsVM.Content       = userFile.Content;
                caseDetailsVM.SavedFileName = userFile.SavedFileName;
            }

            //if (userCase.StatusID == 4)
            //{
            GenericRepository <Employee> empRepository = unitOfWork.GetRepoInstance <Employee>();
            List <Employee> allEmp = empRepository.GetBy(c => c.CategoryID == userCase.CategoryID && c.RoleID == 3).ToList();

            caseDetailsVM.AllEmployees = allEmp;
            //}

            if (userCase.StatusID == 2)
            {
                GenericRepository <Employee_Case> empCaseRepo = unitOfWork.GetRepoInstance <Employee_Case>();
                Employee_Case assignedEmp = empCaseRepo.GetBy(ec => ec.CaseID == userCase.CaseID).FirstOrDefault();
                //GenericRepository<Employee> empRepository = unitOfWork.GetRepoInstance<Employee>();
                //Employee emp = empRepository.GetBy(e => e.EmployeeID == assignedEmp.EmployeeID).FirstOrDefault();
                GenericRepository <User> userRepository = unitOfWork.GetRepoInstance <User>();
                User assignedUser = userRepository.GetBy(u => u.UserID == assignedEmp.EmployeeID).FirstOrDefault();

                List <Employee_Case> allEmpCases = empCaseRepo.GetBy(ec => ec.CaseID == userCase.CaseID).ToList();
                //List<Employee> allEmp = new List<Employee>();
                List <User> allAssignedEmps = new List <User>();
                foreach (Employee_Case empc in allEmpCases)
                {
                    //Employee temp = empRepository.GetBy(e => e.EmployeeID == empc.EmployeeID).FirstOrDefault();
                    User temp2 = userRepository.GetBy(u => u.UserID == empc.EmployeeID).FirstOrDefault();
                    //allEmp.Add(temp);
                    allAssignedEmps.Add(temp2);
                }
                caseDetailsVM.AllEmployeeCases     = allEmpCases;
                caseDetailsVM.AllAssignedEmployees = allAssignedEmps;
            }

            return(View("CategoryAdminCaseDetails", caseDetailsVM));
        }
Пример #10
0
        // Return Details of a Certain Case
        public ActionResult CaseDetails(long caseId)
        {
            long userId;

            if (Session["USER"] != null)
            {
                userId = ((User)Session["USER"]).UserID;
            }
            else
            {
                userId = 2;
            }
            unitOfWork = (GenericUnitOfWork)Session["UNITOFWORK"];
            GenericRepository <Case>   caseRepository   = unitOfWork.GetRepoInstance <Case>();
            GenericRepository <Status> statusRepository = unitOfWork.GetRepoInstance <Status>();
            Case userCase = caseRepository.GetBy(c => c.CaseID == caseId).FirstOrDefault();

            userCase.Status = statusRepository.GetBy(st => st.StatusID == userCase.StatusID).FirstOrDefault();
            GenericRepository <File> fileRepository = unitOfWork.GetRepoInstance <File>();
            File     userFile   = fileRepository.GetBy(c => c.CaseID == caseId).FirstOrDefault();
            DateTime ServerTime = DateTime.Now;

            ViewBag.ServerTime = ServerTime.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
            DateTime End = userCase.SubmissionDate.AddDays(3);

            ViewBag.Timer = End.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;

            CaseDetailsVM caseDetailsVM = new CaseDetailsVM();

            caseDetailsVM.Case = userCase;

            if (userFile != null)
            {
                caseDetailsVM.FileID        = userFile.FileID;
                caseDetailsVM.FileName      = userFile.FileName;
                caseDetailsVM.Content       = userFile.Content;
                caseDetailsVM.SavedFileName = userFile.SavedFileName;
            }
            GenericRepository <Employee_Case> empCaseRepository = unitOfWork.GetRepoInstance <Employee_Case>();

            if (userCase.StatusID == 2)
            {
                Employee_Case empCase = empCaseRepository.GetBy(ec => ec.CaseID == caseId && ec.EmployeeID == userId).FirstOrDefault();
                if (empCase.OpenedAt == null)
                {
                    empCase.OpenedAt = DateTime.Now;
                    empCaseRepository.Edit(empCase);
                    unitOfWork.SaveChanges();
                }
            }
            if (userCase.StatusID == 2 || userCase.StatusID == 3)
            {
                Employee_Case empCase = empCaseRepository.GetBy(ec => ec.CaseID == caseId && ec.EmployeeID == userId).FirstOrDefault();
                if (empCase.OpenedAt != null)
                {
                    DateTime timer2 = (DateTime)empCase.OpenedAt;
                    ViewBag.Timer2 = timer2.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
                }
            }
            caseDetailsVM.MessagesModel          = new MessagesVM();
            caseDetailsVM.MessagesModel.Messages = new List <Message>();

            unitOfWork = (GenericUnitOfWork)Session["UNITOFWORK"];
            GenericRepository <Message> messageRepository = unitOfWork.GetRepoInstance <Message>();

            var result = messageRepository.GetBy(m => m.CaseID == caseId && (m.ReceiverID == userId || m.SenderID == userId)).OrderByDescending(m => m.SubmissionDate);

            if (result != null)
            {
                foreach (Message message in result)
                {
                    caseDetailsVM.MessagesModel.Messages.Add(message);
                }
            }
            int page       = 1;
            int pageSize   = 3;
            int pageNumber = 1;

            caseDetailsVM.MessagesModel.Messages.ToPagedList(pageNumber, pageSize);
            return(View(caseDetailsVM));
        }
        // Return Details of a Certain Case
        public ActionResult CaseDetails(long caseId)
        {
            long userId;

            if (Session["USER"] != null)
            {
                userId = ((User)Session["USER"]).UserID;
            }
            else
            {
                return(RedirectToAction("Login", "Login", new { area = "Admin" }));
            }

            unitOfWork = (GenericUnitOfWork)Session["UNITOFWORK"];

            GenericRepository <Case> caseRepository = unitOfWork.GetRepoInstance <Case>();
            Case userCase = caseRepository.GetBy(c => c.CaseID == caseId).FirstOrDefault();

            GenericRepository <File> fileRepository = unitOfWork.GetRepoInstance <File>();
            File userFile = fileRepository.GetBy(c => c.CaseID == caseId).FirstOrDefault();

            CaseDetailsVM caseDetailsVM = new CaseDetailsVM();

            caseDetailsVM.Case = userCase;

            if (userFile != null)
            {
                caseDetailsVM.FileID        = userFile.FileID;
                caseDetailsVM.FileName      = userFile.FileName;
                caseDetailsVM.Content       = userFile.Content;
                caseDetailsVM.SavedFileName = userFile.SavedFileName;
            }

            //if (userCase.StatusID == 4)
            //{
            GenericRepository <Employee> empRepository = unitOfWork.GetRepoInstance <Employee>();
            List <Employee> allEmp = empRepository.GetBy(c => c.CategoryID == userCase.CategoryID && c.RoleID == 3).ToList();

            caseDetailsVM.AllEmployees = allEmp;
            //}

            if (userCase.StatusID != 4)
            {
                GenericRepository <Employee_Case> empCaseRepo = unitOfWork.GetRepoInstance <Employee_Case>();
                Employee_Case assignedEmp = empCaseRepo.GetBy(ec => ec.CaseID == userCase.CaseID).FirstOrDefault();
                //GenericRepository<Employee> empRepository = unitOfWork.GetRepoInstance<Employee>();
                //Employee emp = empRepository.GetBy(e => e.EmployeeID == assignedEmp.EmployeeID).FirstOrDefault();
                GenericRepository <User> userRepository = unitOfWork.GetRepoInstance <User>();
                if (userCase.StatusID == 2)
                {
                    User assignedUser = userRepository.GetBy(u => u.UserID == assignedEmp.EmployeeID).FirstOrDefault();
                }


                List <Employee_Case> allEmpCases = empCaseRepo.GetBy(ec => ec.CaseID == userCase.CaseID).ToList();
                //List<Employee> allEmp = new List<Employee>();
                List <User> allAssignedEmps = new List <User>();
                foreach (Employee_Case empc in allEmpCases)
                {
                    //Employee temp = empRepository.GetBy(e => e.EmployeeID == empc.EmployeeID).FirstOrDefault();
                    User temp2 = userRepository.GetBy(u => u.UserID == empc.EmployeeID).FirstOrDefault();
                    //allEmp.Add(temp);
                    allAssignedEmps.Add(temp2);
                }
                caseDetailsVM.AllEmployeeCases       = allEmpCases;
                caseDetailsVM.AllAssignedEmployees   = allAssignedEmps;
                caseDetailsVM.MessagesModel          = new MessagesVM();
                caseDetailsVM.MessagesModel.Messages = new List <Message>();

                unitOfWork = (GenericUnitOfWork)Session["UNITOFWORK"];
                GenericRepository <Message> messageRepository = unitOfWork.GetRepoInstance <Message>();

                var result = messageRepository.GetBy(m => m.CaseID == caseId).OrderByDescending(m => m.SubmissionDate);
                if (result != null)
                {
                    foreach (Message message in result)
                    {
                        caseDetailsVM.MessagesModel.Messages.Add(message);
                    }
                }
                int page       = 1;
                int pageSize   = 3;
                int pageNumber = 1;
                caseDetailsVM.MessagesModel.Messages.ToPagedList(pageNumber, pageSize);
            }

            return(View("CategoryAdminCaseDetails", caseDetailsVM));
        }