Example #1
0
        public ApprovalModel UpdateApproval(ApprovalModel approvalModel)
        {
            var resultSP = DB.UpdateApproval(approvalModel.approvalCode, approvalModel.approvalFrom, approvalModel.approvalUntil, approvalModel.approvalPersonId, approvalModel.approvalNumber).Select(a => new ApprovalModel
            {
                approvalCode     = a.approvalCode,
                approvalFrom     = a.approvalFrom,
                approvalUntil    = a.approvalUntil,
                approvalPersonId = a.approvalPersonId,
                approvalNumber   = a.approvalNumber
            });

            if (GlobalVariable.queryType == 0)
            {
                APPROVAL approval = DB.APPROVALS.Where(a => a.approvalPersonId == approvalModel.approvalPersonId).SingleOrDefault();
                if (approval == null)
                {
                    return(null);
                }
                approval.approvalCode     = approvalModel.approvalCode;
                approval.approvalFrom     = approvalModel.approvalFrom;
                approval.approvalUntil    = approvalModel.approvalUntil;
                approval.approvalPersonId = approvalModel.approvalPersonId;
                approval.approvalNumber   = approvalModel.approvalNumber;
                DB.SaveChanges();
                return(GetOneApprovalByNumber(approval.approvalNumber));
            }
            else
            {
                return(resultSP.SingleOrDefault());
            }
        }
Example #2
0
        public string ApproveDF(int id)
        {
            try
            {
                STNServiceCaller serviceCaller = STNServiceCaller.Instance;
                var request = new RestRequest(Method.POST);

                string thisid = id.ToString();
                //post this request to approval
                request.Resource = "DataFiles/{dataFileId}/Approve";
                request.AddParameter("dataFileId", id, ParameterType.UrlSegment);
                request.RequestFormat = DataFormat.Xml;
                request.AddHeader("Content-type", "application/xml");
                APPROVAL anApproval = serviceCaller.Execute <APPROVAL>(request);

                string memUsername = string.Empty;
                //now get the approving member
                if (anApproval != null)
                {
                    request             = new RestRequest();
                    request.Resource    = "Members/{entityId}";
                    request.RootElement = "MEMBER";
                    request.AddParameter("entityId", anApproval.MEMBER_ID, ParameterType.UrlSegment);
                    memUsername = serviceCaller.Execute <MEMBER>(request).USERNAME;

                    ViewData["ApprovalSummary"] = memUsername;
                }
                return(memUsername);
            }
            catch (Exception e)
            {
                return(e.ToString());
            }
        }
Example #3
0
        public ApprovalModel AddApproval(ApprovalModel approvalModel)
        {
            var resultSP = DB.AddApproval(approvalModel.approvalCode, approvalModel.approvalFrom, approvalModel.approvalUntil, approvalModel.approvalPersonId).Select(a => new ApprovalModel
            {
                approvalCode     = a.approvalCode,
                approvalFrom     = a.approvalFrom,
                approvalUntil    = a.approvalUntil,
                approvalPersonId = a.approvalPersonId,
                approvalNumber   = a.approvalNumber
            });

            if (GlobalVariable.queryType == 0)
            {
                APPROVAL approval = new APPROVAL
                {
                    approvalCode     = approvalModel.approvalCode,
                    approvalFrom     = approvalModel.approvalFrom,
                    approvalUntil    = approvalModel.approvalUntil,
                    approvalPersonId = approvalModel.approvalPersonId
                };
                DB.APPROVALS.Add(approval);
                DB.SaveChanges();
                return(GetOneApprovalByNumber(approval.approvalNumber));
            }
            else
            {
                return(resultSP.SingleOrDefault());
            }
        }
Example #4
0
        public int DeleteApprovalById(string approvalPersonId)
        {
            var resultSP = DB.DeleteApprovalByPerson(approvalPersonId);

            if (GlobalVariable.queryType == 0)
            {
                APPROVAL approval = DB.APPROVALS.Where(a => a.approvalPersonId.Equals(approvalPersonId)).SingleOrDefault();
                DB.APPROVALS.Attach(approval);
                if (approval == null)
                {
                    return(0);
                }
                DB.APPROVALS.Remove(approval);
                DB.SaveChanges();
                return(1);
            }
            else
            {
                return(resultSP);
            }
        }
Example #5
0
        public int DeleteApproval(int approvalNumber)
        {
            var resultSP = DB.DeleteApprovalByNumber(approvalNumber);

            if (GlobalVariable.queryType == 0)
            {
                APPROVAL approval = DB.APPROVALS.Where(a => a.approvalNumber == approvalNumber).SingleOrDefault();
                DB.APPROVALS.Attach(approval);
                if (approval == null)
                {
                    return(0);
                }
                DB.APPROVALS.Remove(approval);
                DB.SaveChanges();
                return(1);
            }
            else
            {
                return(resultSP);
            }
        }
Example #6
0
        public string Approve(int id, string FROM)
        {
            try
            {
                STNServiceCaller serviceCaller = STNServiceCaller.Instance;
                var      request    = new RestRequest(Method.POST);
                APPROVAL anApproval = new APPROVAL();

                //Determine which is getting approved - a hwm or datafile
                if (FROM == "HWM")
                {
                    //approve it
                    request.Resource = "HWMs/{hwmId}/Approve";
                    request.AddParameter("hwmId", id, ParameterType.UrlSegment);
                    request.RequestFormat = DataFormat.Xml;
                    request.AddHeader("Content-type", "application/xml");
                    anApproval = serviceCaller.Execute <APPROVAL>(request);
                }
                else if (FROM == "DF")
                {
                    request.Resource = "DataFiles/{dataFileId}/Approve";
                    request.AddParameter("dataFileId", id, ParameterType.UrlSegment);
                    request.RequestFormat = DataFormat.Xml;
                    request.AddHeader("Content-type", "application/xml");
                    anApproval = serviceCaller.Execute <APPROVAL>(request);
                }

                string memUsername = string.Empty;
                //now get the approving member
                if (anApproval.APPROVAL_ID != 0)
                {
                    request             = new RestRequest();
                    request.Resource    = "Members/{entityId}";
                    request.RootElement = "MEMBER";
                    request.AddParameter("entityId", anApproval.MEMBER_ID, ParameterType.UrlSegment);
                    memUsername = serviceCaller.Execute <MEMBER>(request).USERNAME;

                    ViewData["ApprovalSummary"] = memUsername;
                }

                //get member logged in's role
                request             = new RestRequest();
                request.Resource    = "/Members?username={userName}";
                request.RootElement = "MEMBER";
                request.AddParameter("userName", User.Identity.Name, ParameterType.UrlSegment);
                MEMBER thisMember = serviceCaller.Execute <MEMBER>(request);
                if (thisMember.ROLE_ID == 1)
                {
                    ViewData["Role"] = "Admin";
                }
                if (thisMember.ROLE_ID == 2)
                {
                    ViewData["Role"] = "Manager";
                }
                if (thisMember.ROLE_ID == 3)
                {
                    ViewData["Role"] = "Field";
                }

                return(memUsername);
            }
            catch (Exception e)
            {
                return(e.ToString());
            }
        }
Example #7
0
        //GET approvalInfoBox/id
        public PartialViewResult ApprovalInfoBox(int id, string FROM)
        {
            try
            {
                STNServiceCaller serviceCaller = STNServiceCaller.Instance;
                var      request    = new RestRequest();
                APPROVAL anApproval = new APPROVAL();
                ViewData["FROM"] = FROM;
                ViewData["ID"]   = id;

                //which approval are we interested in
                if (FROM == "HWM")
                {
                    request.Resource    = "HWMs/{entityId}";
                    request.RootElement = "HWM";
                    request.AddParameter("entityId", id, ParameterType.UrlSegment);
                    HWM aHWM = serviceCaller.Execute <HWM>(request);

                    request             = new RestRequest();
                    request.Resource    = "/Approvals/{entityId}";
                    request.RootElement = "APPROVAL";
                    request.AddParameter("entityId", aHWM.APPROVAL_ID, ParameterType.UrlSegment);
                    anApproval = serviceCaller.Execute <APPROVAL>(request);
                }
                else if (FROM == "DF")
                {
                    //if it's 0, there is an issue from the uploader not connecting the file to the datafile
                    if (id != 0)
                    {
                        request             = new RestRequest();
                        request.Resource    = "DataFiles/{entityId}";
                        request.RootElement = "DATA_FILE";
                        request.AddParameter("entityId", id, ParameterType.UrlSegment);
                        DATA_FILE aDataFile = serviceCaller.Execute <DATA_FILE>(request);

                        request             = new RestRequest();
                        request.Resource    = "/Approvals/{entityId}";
                        request.RootElement = "APPROVAL";
                        request.AddParameter("entityId", aDataFile.APPROVAL_ID, ParameterType.UrlSegment);
                        anApproval = serviceCaller.Execute <APPROVAL>(request);
                    }
                    else
                    {
                        anApproval = null;
                    }
                }

                if (anApproval != null)
                {
                    //Get Approving Member
                    request             = new RestRequest();
                    request.Resource    = "Members/{entityId}";
                    request.RootElement = "MEMBER";
                    request.AddParameter("entityId", anApproval.MEMBER_ID, ParameterType.UrlSegment);
                    string memUsername = serviceCaller.Execute <MEMBER>(request).USERNAME;

                    ViewData["ApprovalSummary"] = memUsername;
                }

                //get member logged in's role
                request             = new RestRequest();
                request.Resource    = "/Members?username={userName}";
                request.RootElement = "MEMBER";
                request.AddParameter("userName", User.Identity.Name, ParameterType.UrlSegment);
                MEMBER thisMember = serviceCaller.Execute <MEMBER>(request);
                if (thisMember.ROLE_ID == 1)
                {
                    ViewData["Role"] = "Admin";
                }
                if (thisMember.ROLE_ID == 2)
                {
                    ViewData["Role"] = "Manager";
                }
                if (thisMember.ROLE_ID == 3)
                {
                    ViewData["Role"] = "Field";
                }

                return(PartialView());
            }
            catch (Exception e)
            {
                return(PartialView("../Shared/Error", e));
            }
        }