public static void GetOrgApprovalUser(int orgPos, int orgPosId, UserInfo nfo) { AskrindoMVCEntities db = new AskrindoMVCEntities(); GetOrgApprovalUser(orgPos, orgPosId, nfo, db); db.SaveChanges(); }
public static void IncrementSerialNumber(AskrindoMVCEntities db) { var sn = db.SerialNumbers.First(); sn.SN++; db.SaveChanges(); }
public static void CreateFirstMitigationApprovalSchedule(int mitigationId) { AskrindoMVCEntities db = new AskrindoMVCEntities(); CreateFirstMitigationApprovalSchedule(mitigationId, db); db.SaveChanges(); }
//public static void CreateApprovalSchedule(int riskId) //{ // AskrindoMVCEntities db = new AskrindoMVCEntities(); // var risk = db.Risks.Single(p => p.RiskId == riskId); // if (risk == null) // return; // int nextPos; // switch (risk.OrgPos) // { // case ORGPOS_DIVISION // } //} public static void CreateFirstApprovalSchedule(int riskId) { AskrindoMVCEntities db = new AskrindoMVCEntities(); CreateFirstApprovalSchedule(riskId, db); db.SaveChanges(); }
public static void CancelMitigationApproval(int approvalId, AskrindoMVCEntities db) { using (TransactionScope trans = new TransactionScope()) { UserData data = Utils.LoadUserDataFromSession(); MitigationApproval apr = db.MitigationApprovals.Where(p => p.ApprovalId == approvalId).FirstOrDefault(); MitigationApproval nextApr = db.MitigationApprovals .Where(p => p.MitigationId == apr.MitigationId && p.ApprovalDate == null && p.ApprovalId != apr.ApprovalId) .FirstOrDefault(); if (nextApr != null) db.MitigationApprovals.DeleteObject(nextApr); apr.UserId = null; apr.JobTitle = null; apr.ApprovalDate = null; db.SaveChanges(); if (apr.LastApproval) { apr.RiskMitigation.ApprovalDate = null; RiskState rs = db.RiskStates.Where(p => p.RiskId == apr.RiskMitigation.RiskId && p.MitigationId == apr.MitigationId).FirstOrDefault(); if (rs != null) { db.RiskStates.DeleteObject(rs); db.SaveChanges(); } } MitigationApproval prevApr = db.MitigationApprovals .Where(p => p.MitigationId == apr.MitigationId && p.ApprovalDate != null && p.ApprovalId != apr.ApprovalId) .FirstOrDefault(); if (prevApr == null) apr.RiskMitigation.IsReadOnly = false; else prevApr.IsReadOnly = false; db.SaveChanges(); trans.Complete(); } }
//public static void ApproveMitigation(int mitigationId, AskrindoMVCEntities db) //{ // UserData data = Utils.LoadUserDataFromSession(); // RiskMitigation mitigation = db.RiskMitigations.Where(p => p.MitigationId == mitigationId).FirstOrDefault(); // using (TransactionScope trans = new TransactionScope()) // { // mitigation.ApprovalDate = DateTime.Now; // mitigation.UserId = data.UserId; // mitigation.JobTitle = data.JobTitle; // RiskState rs = new RiskState(); // rs.RiskId = mitigation.RiskId; // rs.MitigationId = mitigation.MitigationId; // rs.StateDate = (DateTime)mitigation.ApprovalDate; // rs.ProbLevelId = (int)mitigation.ProbLevelId; // rs.ImpactLevelId = (int)mitigation.ImpactLevelId; // rs.RiskLevel = (int)mitigation.RiskLevel; // db.RiskStates.AddObject(rs); // db.SaveChanges(); // trans.Complete(); // } //} //public static void CancelMitigationApproval(int mitigationId, AskrindoMVCEntities db) //{ // UserData data = Utils.LoadUserDataFromSession(); // RiskMitigation mitigation = db.RiskMitigations.Where(p => p.MitigationId == mitigationId).FirstOrDefault(); // using (TransactionScope trans = new TransactionScope()) // { // mitigation.ApprovalDate = null; // mitigation.UserId = null; // mitigation.JobTitle = null; // RiskState rs = db.RiskStates.Where(p => p.RiskId == mitigation.RiskId && p.MitigationId == mitigation.MitigationId).FirstOrDefault(); // if (rs != null) // db.RiskStates.DeleteObject(rs); // db.SaveChanges(); // trans.Complete(); // } //} public static void ApproveMitigation(int approvalId, AskrindoMVCEntities db) { using (TransactionScope trans = new TransactionScope()) { UserData data = LoadUserDataFromSession(); MitigationApproval apr = db.MitigationApprovals.Where(p => p.ApprovalId == approvalId).FirstOrDefault(); apr.ApprovalDate = DateTime.Now; apr.UserId = data.UserId; apr.JobTitle = data.JobTitle; db.SaveChanges(); apr.RiskMitigation.IsReadOnly = true; db.SaveChanges(); if (apr.LastApproval) { // mitigation approval complete apr.RiskMitigation.ApprovalDate = apr.ApprovalDate; db.SaveChanges(); MitigationApproval prevApr = db.MitigationApprovals .Where(p => p.MitigationId == apr.MitigationId && p.ApprovalId != apr.ApprovalId && p.ApprovalDate != null) .FirstOrDefault(); if (prevApr != null) prevApr.IsReadOnly = true; db.SaveChanges(); RiskState rs = new RiskState(); rs.RiskId = apr.RiskMitigation.RiskId; rs.MitigationId = apr.MitigationId; rs.StateDate = (DateTime)apr.ApprovalDate; rs.ProbLevelId = (int)apr.RiskMitigation.ProbLevelId; rs.ImpactLevelId = (int)apr.RiskMitigation.ImpactLevelId; rs.RiskLevel = (int)apr.RiskMitigation.RiskLevel; db.RiskStates.AddObject(rs); db.SaveChanges(); } else { // create next approval schedule MitigationApproval nextApr = new MitigationApproval(); nextApr.MitigationId = apr.MitigationId; nextApr.LimitDate = DateTime.Now.AddDays(Utils.MAX_LIMIT_APPROVAL_DAYS); nextApr.LastApproval = true; switch (apr.OrgPos) { case Utils.ORGPOS_SUBDIV: SubDiv subDiv = db.SubDivs.Single(p => p.SubDivId == apr.SubDivId); nextApr.OrgPos = Utils.ORGPOS_DIVISION; nextApr.DivisionId = subDiv.DivisionId; break; case Utils.ORGPOS_SUBBRANCH: SubBranch subBranch = db.SubBranches.Single(p => p.SubBranchId == apr.SubBranchId); nextApr.OrgPos = Utils.ORGPOS_BRANCH; nextApr.BranchId = subBranch.BranchId; break; case Utils.ORGPOS_BIZUNIT: BizUnit bizUnit = db.BizUnits.Single(p => p.BizUnitId == apr.BizUnitId); nextApr.OrgPos = Utils.ORGPOS_BRANCH; nextApr.BranchId = bizUnit.BranchId; break; } db.MitigationApprovals.AddObject(nextApr); db.SaveChanges(); } trans.Complete(); } }
private static void ValidateSerialNumber() { AskrindoMVCEntities db = new AskrindoMVCEntities(); SerialNumber sn = null; if (db.SerialNumbers.Count() == 0) { sn = new SerialNumber(); sn.Year = DateTime.Now.Year; sn.SN = 1; db.SerialNumbers.AddObject(sn); db.SaveChanges(); } else { sn = db.SerialNumbers.First(); if (sn.Year != DateTime.Now.Year) { sn.Year = DateTime.Now.Year; sn.SN = 1; db.SaveChanges(); } } }