Ejemplo n.º 1
0
Archivo: Utils.cs Proyecto: ryanask/MRK
        private static bool GetUserDataFromDb(string userName, UserData data)
        {
            bool isUserValid = true;
            data.IsRiskOwner = false;
            data.IsAdmin = string.Compare(userName.ToLower(), Utils.S_ADMIN.ToLower()) == 0;
            if (data.IsAdmin)
            {
                data.UserName = userName;
                data.FullName = "Administrator";
            }
            else
            {
                MembershipUser usr = Membership.GetUser(userName);
                if (usr != null)
                {
                    Guid userId = (Guid)usr.ProviderUserKey;
                    AskrindoMVCEntities db = new AskrindoMVCEntities();
                    UserInfo nfo = db.UserInfos.Where(p => p.UserId == userId).FirstOrDefault();
                    isUserValid = nfo != null;
                    if (isUserValid)
                    {
                        data.UserId = userId;
                        data.UserName = nfo.aspnet_User.UserName;
                        data.FullName = nfo.FullName;
                        data.JobTitle = nfo.JobTitle;
                        data.OrgPos = nfo.OrgPos;
                        data.IsRiskOwner = nfo.IsRiskOwner;

                        switch (data.OrgPos)
                        {
                            case ORGPOS_DIVISION:
                                data.OrgPosId = (int)nfo.DivisionId;
                                Division div = db.Divisions.Single(p => p.DivisionId == nfo.DivisionId);
                                data.OrgPosName = string.Format("Direktorat: {0}, Divisi: {1}",
                                    div.Dept.DeptName, div.DivisionName);
                                data.DivisionId = div.DivisionId;
                                data.DeptId = div.DeptId;
                                break;
                            case ORGPOS_SUBDEPT:
                                data.OrgPosId = (int)nfo.SubDeptId;
                                SubDept subDept = db.SubDepts.Single(p => p.SubDeptId == nfo.SubDeptId);
                                data.OrgPosName = string.Format("Direktorat: {0}, Bagian: {1}",
                                    subDept.Dept.DeptName, subDept.SubDeptName);
                                data.SubDeptId = subDept.SubDeptId;
                                data.DeptId = subDept.DeptId;
                                break;
                            case ORGPOS_SUBDIV:
                                data.OrgPosId = (int)nfo.SubDivId;
                                SubDiv subDiv = db.SubDivs.Single(p => p.SubDivId == nfo.SubDivId);
                                data.OrgPosName = string.Format("Divisi: {0}, Bagian: {1}",
                                    subDiv.Division.DivisionName, subDiv.SubDivName);
                                data.SubDivId = subDiv.SubDivId;
                                data.DivisionId = subDiv.DivisionId;
                                data.DeptId = subDiv.Division.DeptId;
                                break;
                            case ORGPOS_BRANCH:
                                data.OrgPosId = (int)nfo.BranchId;
                                Branch branch = db.Branches.Single(p => p.BranchId == nfo.BranchId);
                                data.OrgPosName = string.Format("Cabang: {0}", branch.BranchName);
                                data.BranchId = branch.BranchId;
                                data.BranchClassId = branch.ClassId;
                                break;
                            case ORGPOS_SUBBRANCH:
                                data.OrgPosId = (int)nfo.SubBranchId;
                                SubBranch subBranch = db.SubBranches.Single(p => p.SubBranchId == nfo.SubBranchId);
                                data.OrgPosName = string.Format("Cabang: {0}, Bagian: {1}",
                                    subBranch.Branch.BranchName, subBranch.SubBranchName);
                                data.SubBranchId = subBranch.SubBranchId;
                                data.BranchId = subBranch.BranchId;
                                data.BranchClassId = subBranch.Branch.ClassId;
                                break;
                            case ORGPOS_BIZUNIT:
                                data.OrgPosId = (int)nfo.BizUnitId;
                                BizUnit biz = db.BizUnits.Single(p => p.BizUnitId == nfo.BizUnitId);
                                data.OrgPosName = string.Format("Cabang: {0}, KUP: {1}",
                                    biz.Branch.BranchName, biz.BizUnitName);
                                data.BizUnitId = biz.BizUnitId;
                                data.BranchId = biz.BranchId;
                                data.BranchClassId = biz.Branch.ClassId;
                                break;
                        }
                    }
                }
                else
                    isUserValid = false;
            }
            if (isUserValid)
                HttpContext.Current.Session["Data"] = data;
            else
            {
                FormsAuthentication.SignOut();
                HttpContext.Current.Session["Data"] = null;
            }
            return isUserValid;
        }
Ejemplo n.º 2
0
Archivo: Utils.cs Proyecto: ryanask/MRK
        public static int GetImpactPos(UserData data)
        {
            AskrindoMVCEntities db = new AskrindoMVCEntities();

            switch (data.OrgPos)
            {
                case ORGPOS_SUBDEPT:
                    var subDept = db.SubDepts.Single(p => p.SubDeptId == data.SubDeptId);
                    if (subDept.IsSupporting)
                        return IMPACTPOS_SUPPORTINGHQ;
                    else
                        return IMPACTPOS_HQ;
                case ORGPOS_DIVISION:
                    var div = db.Divisions.Single(p => p.DivisionId == data.DivisionId);
                    if (div.IsSupporting)
                        return IMPACTPOS_SUPPORTINGHQ;
                    else
                        return IMPACTPOS_HQ;
                case ORGPOS_SUBDIV:
                    var subDiv = db.SubDivs.Single(p => p.SubDivId == data.SubDivId);
                    if (subDiv.IsSupporting)
                        return IMPACTPOS_SUPPORTINGHQ;
                    else
                        return IMPACTPOS_HQ;
                case ORGPOS_BRANCH:
                    var branch = db.Branches.Single(p => p.BranchId == data.BranchId);
                    if (branch.IsSupporting)
                        return IMPACTPOS_SUPPORTINGBRANCH;
                    else
                    {
                        if (branch.ClassId == BRANCHCLASS1)
                            return IMPACTPOS_BRANCH1;
                        else if (branch.ClassId == BRANCHCLASS2)
                            return IMPACTPOS_BRANCH2;
                        else
                            return IMPACTPOS_BRANCH3;
                    }
                case ORGPOS_SUBBRANCH:
                    var subBranch = db.SubBranches.Single(p => p.SubBranchId == data.SubBranchId);
                    if (subBranch.IsSupporting)
                        return IMPACTPOS_SUPPORTINGBRANCH;
                    else
                    {
                        if (subBranch.Branch.ClassId == BRANCHCLASS1)
                            return IMPACTPOS_BRANCH1;
                        else if (subBranch.Branch.ClassId == BRANCHCLASS2)
                            return IMPACTPOS_BRANCH2;
                        else
                            return IMPACTPOS_BRANCH3;
                    }
                case ORGPOS_BIZUNIT:
                    var biz = db.BizUnits.Single(p => p.BizUnitId == data.BizUnitId);
                    if (biz.IsSupporting)
                        return IMPACTPOS_SUPPORTINGBIZUNIT;
                    else
                        return IMPACTPOS_BIZUNIT;
                default:
                    return IMPACTPOS_HQ;
            }
        }
Ejemplo n.º 3
0
Archivo: Utils.cs Proyecto: ryanask/MRK
 public static UserData LoadUserDataFromSession()
 {
     UserData data = HttpContext.Current.Session["Data"] as UserData;
     if (data == null)
     {
         data = new UserData();
         GetUserDataFromDb(HttpContext.Current.User.Identity.Name, data);
     }
     return data;
 }
Ejemplo n.º 4
0
Archivo: Utils.cs Proyecto: ryanask/MRK
        public static string GetFormattedSerialNumber(UserData data)
        {
            ValidateSerialNumber();
            AskrindoMVCEntities db = new AskrindoMVCEntities();

            string branchCode = "99";
            string bizCode = "00";

            if (data.BranchClassId != null)
            {
                Branch branch = db.Branches.Single(p => p.BranchId == data.BranchId);
                branchCode = branch.BranchCode.Trim().PadLeft(2, '0');
            }
            if (data.BizUnitId != null)
            {
                BizUnit biz = db.BizUnits.Single(p => p.BizUnitId == data.BizUnitId);
                bizCode = biz.BizUnitCode.Trim().PadLeft(2, '0');
            }

            string year = DateTime.Now.Year.ToString().PadLeft(4, '0');
            string month = DateTime.Now.Month.ToString().PadLeft(2, '0');

            SerialNumber sn = db.SerialNumbers.First();

            return branchCode + "." + bizCode + "." + year + "." + month + "." + sn.SN.ToString().PadLeft(4, '0');
        }