Exemplo n.º 1
0
        public ActionResult ViewPassport(string WorkflowID, bool editMode, bool?myEntries, bool?viewMode)
        {
            Session["UserName"] = @User.Identity.Name;
            this._UserName      = Session["UserName"] as string ?? "";

            if (_UserName == null || _UserName.Equals(String.Empty))
            {
                ViewBag.ErrorMessage = "You must be logged in to continue.";
                return(RedirectToAction("AwaitingMyApproval", "AwaitingApproval"));
            }

            //now resolve the user profile from AD and Xceed
            StaffADProfile staffADProfile = new StaffADProfile();

            staffADProfile.user_logon_name = _UserName;

            //AD
            ActiveDirectoryQuery activeDirectoryQuery = new ActiveDirectoryQuery(staffADProfile);

            staffADProfile             = activeDirectoryQuery.GetStaffProfile();
            staffADProfile.branch_code = LINQCalls.getEntryProfile(WorkflowID).branch_code;
            staffADProfile.branch_name = LINQCalls.getEntryProfile(WorkflowID).branch_name;

            if (staffADProfile == null)
            {
                ViewBag.ErrorMessage = "Your profile is not properly setup on the system. Please contact InfoTech.";
                return(RedirectToAction("AwaitingMyApproval", "AwaitingApproval"));
            }

            //Get the request identified by the workflow id
            List <RequestDetails> requestDetails = new List <RequestDetails>();

            if (myEntries != null && myEntries == true)
            {
                string entrykey = staffADProfile.employee_number + "_" + staffADProfile.branch_code;
                requestDetails = LINQCalls.getExistingPassportEntry(WorkflowID, staffADProfile.employee_number, entrykey);
            }
            else
            {
                requestDetails = LINQCalls.getExistingPassportEntry(WorkflowID, staffADProfile.employee_number);
            }

            EntryModel entryModel = new EntryModel();

            entryModel          = LINQCalls.getWorkflowEntry(WorkflowID);
            ViewBag.StaffBranch = entryModel.Branch;
            int      requeststageid  = entryModel.RequestStageId;
            string   requeststage    = entryModel.RequestStage;
            DateTime requestdate     = entryModel.DateSubmitted;
            string   initiatornumber = LINQCalls.getInitiatorNumber(WorkflowID) ?? staffADProfile.employee_number;

            string cansave = (requeststage.Equals(INIT_STAGE) || requeststage.Equals(DENIED)) && initiatornumber.Equals(staffADProfile.employee_number)
                                            ? "true" : "false";

            staffADProfile.appperiod = entryModel.AppraisalPeriod;

            XElement  ApprovalHistory = LINQCalls.getApprovalHistory(WorkflowID);
            XDocument xDocument       = DataHandlers.ToXDocument(ApprovalHistory);

            List <ApprovalDetails> approvalHistory = xDocument.Descendants("Approvals").Select(det => new ApprovalDetails
            {
                ApproverNames        = det.Element("ApproverName").Value,
                ApproverStaffNumbers = det.Element("ApproverStaffNumber").Value,
                ApprovedStages       = det.Element("ApprovedStage").Value,
                ApproverAction       = det.Element("ApproverAction").Value,
                ApprovalDateTime     = det.Element("ApprovalDateTime").Value
            })
                                                     .ToList();

            SuperPassportModel superPassportModel = new SuperPassportModel();

            if (TempData["superPassportModel"] != null)
            {
                superPassportModel = TempData["superPassportModel"] as SuperPassportModel;
            }
            else
            {
                superPassportModel = new SuperPassportModel {
                    WorkflowID        = WorkflowID,
                    RequestStageID    = entryModel.RequestStageId,
                    RequestStage      = entryModel.RequestStage,
                    RequestDate       = entryModel.DateSubmitted,
                    StaffADProfile    = staffADProfile,
                    RequestDetails    = requestDetails,
                    CanSave           = cansave,
                    ApprovalDetails   = approvalHistory,
                    EntryModel        = entryModel,
                    RequestBranch     = entryModel.Branch,
                    RequestBranchCode = entryModel.BranchCode
                };
            }

            Session["requestDetails"] = superPassportModel.RequestDetails;
            TempData["editMode"]      = (editMode == true) ? null : "false";

            if (TempData["ErrorMessage"] != null)
            {
                ViewBag.ErrorMessage = TempData["ErrorMessage"] as string;
            }

            TempData["superPassportModel"] = superPassportModel;
            return(RedirectToAction("PassportInputForm"));
        }