public static List <Response> insertOrUpdate(User requester, Task[] listOfTasks) { try { nova_ataEntities db = new nova_ataEntities(); List <Response> listOfResponses = new List <Response>(); int projectId = listOfTasks[0].getProjectId(); var tasks = from t in db.tasks where t.projectId == projectId where t.activityOrigin.ToUpper().Equals("PROJECT") select t; var result = tasks.ToList().Where(x => !listOfTasks.Any(y => x.idProjectTask == y.getIdProjectTask())); if (result.Count() > 0) { foreach (var task in result) { listOfResponses.Add(delete(requester, task.taskId)); } } foreach (Task task in listOfTasks) { listOfResponses.Add(insertOrUpdate(requester, task)); } return(listOfResponses); } catch (Exception ex) { throw new Exception(ex.Message); } }
public static bool isLeaderOrSubmitter(User user, Project project) { try { nova_ataEntities db = new nova_ataEntities(); int projectId = project.getProjectId(); int userId = user.getUserId(); string userArea = user.getArea(); var leader = from p in db.projects where p.leaderOrSubmitter == userId && p.projectId == projectId && userArea == "GP" select new { p.leaderOrSubmitter }; if (leader.ToList().Count > 0) { return(true); } else { return(false); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public static bool isResponsibleForTask(User user, Task task) { try { nova_ataEntities db = new nova_ataEntities(); int taskId = task.getTaskId(); string userArea = user.getArea(); var responsible = from t in db.tasks where t.taskId == taskId where task.getResponsibleList().Contains(t.responsible) select new { t.responsible }; if (responsible.ToList().Count > 0) { return(true); } else { return(false); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public static bool isPMO(User user, Project project) { try { nova_ataEntities db = new nova_ataEntities(); int projectId = project.getProjectId(); string userAlias = user.getAlias(); var pmo = from ta in db.team_allocation join p in db.projects on ta.projectId equals p.projectId where ta.users.alias == userAlias && p.projectId == projectId && ta.users.area == "GP" select new { ta.userId }; if (pmo.ToList().Count > 0) { return(true); } else { return(false); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public static User instanceByName(string name) { nova_ataEntities db = new nova_ataEntities(); name = string.Format("%{0}%", name.Replace(' ', '%')); StringBuilder sb = new StringBuilder(); var arrayText = name.Normalize(NormalizationForm.FormD).ToCharArray(); foreach (char letter in arrayText) { if (CharUnicodeInfo.GetUnicodeCategory(letter) != UnicodeCategory.NonSpacingMark) { sb.Append(letter); } } name = sb.ToString(); var usr = db.users.Where(x => SqlFunctions.PatIndex(name, x.name) > 0); if (usr.Count() > 0) { User user = new User(usr.ToList()[0].userId, usr.ToList()[0].alias, usr.ToList()[0].name, usr.ToList()[0].exchangeName, usr.ToList()[0].email, usr.ToList()[0].area, usr.ToList()[0].managerName, usr.ToList()[0].managerLogin, usr.ToList()[0].managerEmail, usr.ToList()[0].type); return(user); } else { return(null); } }
public static List <Task> select(User requester, int projectId) { try { nova_ataEntities db = new nova_ataEntities(); List <Task> listOfTasks = new List <Task>(); var tasks = from t in db.tasks where t.projectId == projectId && t.wasDeleted == "false" select t; foreach (var t in tasks) { Task task = new Task(t.taskId, t.projectId, t.notifyMe, t.meetingDate, t.product, t.pWork, t.criticalActivity, t.activityTitle, t.activityDescription, t.parent, t.grandParent, t.responsible, t.start, t.finish, t.status, CommentDAO.selectLastComment(t.taskId), t.activityOrigin, t.idProjectTask, t.idParentProjectTask, t.ident, t.hash, t.delayReason, t.delayDescription, UserDAO.instanceById((int)t.createdBy), (int)t.reworkCount, t.actualFinishDate, t.newStart, t.newFinish, t.isFreezed, t.wasDeleted, t.wasInsertedAfterFreezing); listOfTasks.Add(task); } return(listOfTasks); } catch (Exception ex) { throw new Exception(ex.Message); } }
public static Response insert(User requester, Comment comment) { var c = (dynamic)null; try { nova_ataEntities db = new nova_ataEntities(); c = db.comments.Create(); c.taskId = comment.getTaskId(); c.comment = comment.getComment(); c.owner = requester.getUserId(); DateTime dateTime = DateTime.Now; c.creationDate = string.Format("{0:dd/MM/yyyy}", dateTime); c.creationTime = string.Format("{0:hh:mm:ss}", dateTime); db.comments.Add(c); db.SaveChanges(); return(new Response(c.taskId, "Created", "")); } catch (DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } }
public static List <Project> select() { try { nova_ataEntities db = new nova_ataEntities(); List <Project> lp = new List <Project>(); var projects = from pr in db.projects select pr; foreach (var p in projects.ToList()) { Project project = new Project(p.projectId, p.name, p.leaderOrSubmitter, p.meaningLevel, p.projectStatus, p.scheduleStatus, p.businessUnit, p.category, p.subBrand, p.archetype, p.productProjectStage, (int)p.totalSkus, (int)p.newSkus, p.originalPBFGateAppDate, p.originalBFGateAppDate, p.originalPTGateAppDate, p.originalVLGateAppDate, p.originalDLGateAppDate, p.originalEXGateAppDate, p.originalEVGateAppDate, p.originalLaunchYear, p.displayPBFGateAppDate, p.displayBFGateAppDate, p.displayPTGateAppDate, p.displayVLGateAppDate, p.displayDLGateAppDate, p.displayEXGateAppDate, p.displayEVGateAppDate, p.displayLaunchCycle, p.displayLaunchYear, p.actualPBFGateAppDate, p.actualBFGateAppDate, p.actualPTGateAppDate, p.actualVLGateAppDate, p.actualDLGateAppDate, p.actualEXGateAppDate, p.actualEVGateAppDate, p.lastEstimatedPBFGateAppDate, p.lastEstimatedBFGateAppDate, p.lastEstimatedPTGateAppDate, p.lastEstimatedVLGateAppDate, p.lastEstimatedDLGateAppDate, p.lastEstimatedEXGateAppDate, p.lastEstimatedEVGateAppDate, p.creationDate, p.dateLastUpdated, p.operatingCostCenter, p.prototypePBFGateAppDate, p.prototypeBFGateAppDate, p.prototypePTGateAppDate, p.prototypeVLGateAppDate, p.prototypeDLGateAppDate, p.prototypeEXGateAppDate, p.prototypeEVGateAppDate, p.scoreSharedGoalsPBF, p.scoreSharedGoalsBF, p.scoreSharedGoalsPT, p.scoreSharedGoalsVL, p.scoreSharedGoalsDL, p.scoreSharedGoalsEX, p.scoreSharedGoalsEV, p.parentProgramIDNumber, p.parentProgramName, p.launchOrMaintenance, p.targetRegions, p.commemorationDate, p.first12MonthsGrossRevenue, p.first12MonthsIncrementalGrossRevenue, p.description, p.itemType, p.projectOrganization, p.timeToDelivery, p.timeToMarket, (int)p.consumerSafetyComplexity, (int)p.dlComplexity, (int)p.fillingComplexity, (int)p.formulationComplexity, (int)p.packagingComplexity, (int)p.marketingComplexity, (int)p.processComplexity, (int)p.qualityComplexity); int projectId = project.getProjectId(); var team = from ta in db.team_allocation where ta.projectId == projectId select new { ta.users }; foreach (var usr in team.ToList()) { User user = new User(usr.users.userId, usr.users.alias, usr.users.name, usr.users.exchangeName, usr.users.email, usr.users.area, usr.users.managerName, usr.users.managerLogin, usr.users.managerEmail, usr.users.type); project.addTeamMember(user); } lp.Add(project); } return(lp); } catch (DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } }
public static User instanceById(int userId) { nova_ataEntities db = new nova_ataEntities(); var usr = (from u in db.users where u.userId == userId select u).First(); if (usr == null) { throw new Exception("No register was found"); } User user = new User(usr.userId, usr.alias, usr.name, usr.exchangeName, usr.email, usr.area, usr.managerName, usr.managerLogin, usr.managerEmail, usr.type); return(user); }
public static List <User> instanceByBusinessUnit(string businessUnit) { nova_ataEntities db = new nova_ataEntities(); List <User> listOfUsers = new List <User>(); var users = from u in db.users where u.type == businessUnit select u; foreach (var u in users) { User user = new User(u.userId, u.alias, u.name, u.exchangeName, u.email, u.area, u.managerName, u.managerLogin, u.managerEmail, u.type); listOfUsers.Add(user); } return(listOfUsers); }
public static List <CockpitSAP> select(User requester, int[] projectIdList) { try { List <CockpitSAP> listOfCockpitSAPs = new List <CockpitSAP>(); nova_ataEntities db = new nova_ataEntities(); var data = from cp in db.cockpit join p in db.projects on cp.projectId equals p.projectId from cps in db.cockpit_sap .Where(cps => cps.material == cp.code) .DefaultIfEmpty() where projectIdList.Contains(cp.projectId) select new { cp.cockpitId, cp.projectId, p.name, cp.description, cp.type, cp.code, cp.dummyCode, cp.parentSellCode, cp.parentZpac, cp.hash, cps.sm, cps.workItemText, cps.currentResponsible, cps.generationDate, cps.realInDate, cps.finished, cps.deadline, cps.sellCode }; foreach (var t in data) { CockpitSAP cockpitSAP = new CockpitSAP(t.cockpitId, t.projectId, t.name, t.description, t.type, t.code, t.dummyCode, t.parentSellCode, t.parentZpac, t.hash, t.sm, t.workItemText, t.currentResponsible, t.generationDate, t.realInDate, t.finished, t.deadline, t.sellCode); listOfCockpitSAPs.Add(cockpitSAP); } return(listOfCockpitSAPs); } catch (Exception ex) { throw new Exception(ex.Message); } }
public static Response delete(User requester, Cockpit cockpit) { try { nova_ataEntities db = new nova_ataEntities(); var cp = db.cockpit.Find(cockpit.getCockpitId()); if (cp != null) { db.cockpit.Remove(cp); db.SaveChanges(); } return(new Response(cockpit.getCockpitId(), "Deleted", cockpit.getHash())); } catch { return(new Response(cockpit.getCockpitId(), "Fail", cockpit.getHash())); } }
public static Response delete(User requester, Task task) { try { nova_ataEntities db = new nova_ataEntities(); var t = db.tasks.Find(task.getTaskId()); if (t != null) { t.wasDeleted = "true"; db.SaveChanges(); } return(new Response(task.getTaskId(), "Deleted", task.getHash())); } catch { return(new Response(task.getTaskId(), "Fail", task.getHash())); } }
public static Task instanceById(int taskId) { try { nova_ataEntities db = new nova_ataEntities(); var t = db.tasks.Find(taskId); Task task = new Task(t.taskId, t.projectId, t.notifyMe, t.meetingDate, t.product, t.pWork, t.criticalActivity, t.activityTitle, t.activityDescription, t.parent, t.grandParent, t.responsible, t.start, t.finish, t.status, CommentDAO.selectLastComment(t.taskId), t.activityOrigin, t.idProjectTask, t.idParentProjectTask, t.ident, t.hash, t.delayDescription, t.delayDescription, UserDAO.instanceById((int)t.createdBy), (int)t.reworkCount, t.actualFinishDate, t.newStart, t.newFinish, t.isFreezed, t.wasDeleted, t.wasInsertedAfterFreezing); return(task); } catch (Exception ex) { throw new Exception(ex.Message); } }
public static bool isCreatorOfTask(User user, Task task) { nova_ataEntities db = new nova_ataEntities(); int taskId = task.getTaskId(); int userId = user.getUserId(); var creator = from t in db.tasks where t.taskId == taskId where t.createdBy == userId select new { t.responsible }; if (creator.ToList().Count > 0) { return(true); } else { return(false); } }
public static Response finishTask(User requester, Task task) { try { nova_ataEntities db = new nova_ataEntities(); var t = db.tasks.Find(task.getTaskId()); if (t != null) { t.status = "Completo"; t.pWork = "100"; t.actualFinishDate = string.Format("{0:dd/MM/yyyy}", DateTime.Now); db.SaveChanges(); } return(new Response(task.getTaskId(), "Edited", task.getHash())); } catch { return(new Response(task.getTaskId(), "Fail", task.getHash())); } }
public static List <Update> select(int projectId) { try { nova_ataEntities db = new nova_ataEntities(); List <Update> listOfUpdates = new List <Update>(); var tasks = from t in db.tasks where t.projectId == projectId where t.activityOrigin.ToUpper() == "PROJECT" && t.idParentProjectTask != "" select new { t.taskId, t.pWork }; foreach (var t in tasks) { listOfUpdates.Add(new Update(t.taskId, t.pWork)); } return(listOfUpdates); } catch (Exception ex) { throw new Exception(ex.Message); } }
public static List <Comment> select(int taskId) { try { nova_ataEntities db = new nova_ataEntities(); List <Comment> lc = new List <Comment>(); var com = from c in db.comments where c.taskId == taskId select new { c.commentId, c.taskId, c.comment, owner = c.users.exchangeName, c.creationDate, c.creationTime }; foreach (var c in com.ToList()) { Comment comment = new Comment(c.commentId, c.taskId, c.comment, c.owner, c.creationDate, c.creationTime); lc.Add(comment); } return(lc); } catch (Exception ex) { throw new Exception(ex.Message); } }
public static void insert(Log log) { try { nova_ataEntities db = new nova_ataEntities(); var l = db.logs.Create(); l.controller = log.getController(); l.requestType = log.getRequestType(); l.requester = log.getRequester().getUserId(); l.date = log.getDate(); l.time = log.getTime(); l.attribute1 = log.getAttribute1(); l.attribute2 = log.getAttribute2(); l.body = log.getBody(); db.logs.Add(l); db.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.Message); } }
public static string selectLastComment(int taskId) { try { nova_ataEntities db = new nova_ataEntities(); try { var uc = (from c in db.comments where c.taskId == taskId orderby c.commentId descending select c).First(); return(uc.comment); } catch { return(null); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public static User instanceByAlias(string alias) { if (alias.Contains('\\')) { alias = alias.Split('\\')[1].ToUpper(); } if (alias.ToUpper().Equals("RESOURCE")) { /* * Felipe Maranzato * alias = "FMARAZAT"; * Hannah Ralha * alias = "38861097"; * Nelis Ortiz * alias = "BR91688"; * Clissia Postale * alias = "BR88822"; * Emerson Tosco * alias = "ETOSCO"; */ alias = "81971095"; } nova_ataEntities db = new nova_ataEntities(); var usr = (from u in db.users where u.alias == alias select u).First(); if (usr == null) { throw new Exception("No register was found"); } User user = new User(usr.userId, usr.alias, usr.name, usr.exchangeName, usr.email, usr.area, usr.managerName, usr.managerLogin, usr.managerEmail, usr.type); return(user); }
public static List <Response> insertOrUpdate(User requester, Cockpit[] listOfCockpits) { try { List <Response> listOfResponses = new List <Response>(); nova_ataEntities db = new nova_ataEntities(); foreach (Cockpit cockpit in listOfCockpits) { if (cockpit.getCockpitId() < 0) { int cockpitId = Math.Abs(cockpit.getCockpitId()); cockpit.setCockpitId(cockpitId); listOfResponses.Add(CockpitDAO.delete(requester, cockpit)); continue; } bool isNew = false; var cp = (dynamic)null; if (cockpit.getCockpitId() == 0) { isNew = true; cp = db.cockpit.Create(); } else { isNew = false; cp = db.cockpit.Find(cockpit.getCockpitId()); if (cp == null) { listOfResponses.Add(new Response(cockpit.getCockpitId(), "Fail. Result not found", cockpit.getHash())); } } cp.projectId = cockpit.getProjectId(); cp.description = cockpit.getDescription(); cp.type = cockpit.getType(); cp.code = cockpit.getCode(); cp.dummyCode = cockpit.getDummyCode(); cp.parentSellCode = cockpit.getParentSellCode(); cp.parentZpac = cockpit.getParentZpac(); cp.hash = cockpit.getHash(); if (isNew) { db.cockpit.Add(cp); } db.SaveChanges(); if (isNew) { listOfResponses.Add(new Response(cp.cockpitId, "Created", cockpit.getHash())); } else { listOfResponses.Add(new Response(cockpit.getCockpitId(), "Edited", cockpit.getHash())); } } return(listOfResponses); } catch (DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } }
public static List <Minute> select(User requester, int projectStatus) { try { nova_ataEntities db = new nova_ataEntities(); List <Minute> lm = new List <Minute>(); var proj = (dynamic)null; int userId = requester.getUserId(); string userAlias = requester.getAlias(); switch (projectStatus) { //Retorna todos os projetos case 0: proj = from ta in db.team_allocation join p in db.projects on ta.projectId equals p.projectId join u in db.users on ta.userId equals u.userId where (u.alias == userAlias && ta.userId == u.userId) || (p.leaderOrSubmitter == userId) group ta by new { p.projectId, p.name, p.projectStatus, p.productProjectStage, p.parentProgramIDNumber } into g orderby g.Key.projectId ascending select new { idProjetoGensight = g.Key.projectId, nomeProjetoGensight = g.Key.name, statusProjeto = g.Key.projectStatus, estagio = g.Key.productProjectStage, programa = g.Key.parentProgramIDNumber }; break; //Retorna apenas projetos ativos ou programas case 1: proj = from ta in db.team_allocation join p in db.projects on ta.projectId equals p.projectId join u in db.users on ta.userId equals u.userId where p.projectStatus == "ACTIVE" || p.productProjectStage == "LAUNCH EXECUTION" || p.productProjectStage == "PROGRAMA" where (u.alias == userAlias && ta.userId == u.userId) || (p.leaderOrSubmitter == userId) group ta by new { p.projectId, p.name, p.projectStatus, p.productProjectStage, p.parentProgramIDNumber } into g orderby g.Key.projectId ascending select new { idProjetoGensight = g.Key.projectId, nomeProjetoGensight = g.Key.name, statusProjeto = g.Key.projectStatus, estagio = g.Key.productProjectStage, programa = g.Key.parentProgramIDNumber }; break; default: throw new Exception("Invalid option selected"); } List <int> listAll = new List <int>(); foreach (var p in proj) { try { if (!listAll.Any(y => y == p.idProjetoGensight)) { listAll.Add(p.idProjetoGensight); } if (p.programa != "0" && !listAll.Any(x => x == Convert.ToInt32(p.programa))) { listAll.Add(Convert.ToInt32(p.programa)); } } catch { continue; } } proj = from p in db.projects where listAll.Contains(p.projectId) select new { p.projectId, p.name, p.projectStatus, p.productProjectStage, p.parentProgramIDNumber }; foreach (var p in proj) { Minute minute = new Minute(p.projectId, p.name, p.projectStatus, p.productProjectStage); lm.Add(minute); } return(lm); } catch (Exception ex) { throw new Exception(ex.Message); } }
public static Response insertOrUpdate(User requester, Task task) { try { nova_ataEntities db = new nova_ataEntities(); if (task.getTaskId() < 0) { if (!task.getCriticalActivity().Equals("5000")) { int taskId = Math.Abs(task.getTaskId()); task.setTaskId(taskId); return(TaskDAO.delete(requester, task)); } else { return(new Response(task.getTaskId(), "Failed. Launch Exetution activity can't be deleted", task.getHash())); } } bool isNew = false; bool isChangeAllowed = false; int projectId = task.getProjectId(); var project = (from p in db.projects where p.projectId == projectId select p).First(); if (ProjectDAO.stageCorrespondence(project.productProjectStage) <= 3) { isChangeAllowed = true; } var t = (dynamic)null; if (task.getTaskId() == 0) { isNew = true; t = db.tasks.Create(); t.createdBy = requester.getUserId(); t.creationDate = string.Format("{0:dd/MM/yyyy}", DateTime.Now); t.wasDeleted = "false"; t.reworkCount = 0; if (!isChangeAllowed) { t.wasInsertedAfterFreezing = "true"; t.isFreezed = "true"; } else { t.wasInsertedAfterFreezing = "false"; t.isFreezed = "false"; } } else { isNew = false; t = db.tasks.Find(task.getTaskId()); if (t == null) { return(new Response(task.getTaskId(), "Fail. Result not found", task.getHash())); } if (!isChangeAllowed && t.wasInsertedAfterFreezing.Equals("false")) { t.pWork = task.getPWork(); t.status = task.getStatus(); t.hash = task.getHash(); if (!task.getStart().Equals(t.start)) { t.newStart = task.getStart(); } if (!task.getFinish().Equals(t.finish)) { t.newFinish = task.getFinish(); } t.criticalActivity = task.getCriticalActivity(); t.activityTitle = task.getActivityTitle(); t.activityDescription = task.getActivityDescription(); t.parent = task.getParent(); t.grandParent = task.getGrandParent(); t.responsible = task.getResponsible(); t.ident = task.getIdent(); db.SaveChanges(); return(new Response(task.getTaskId(), "Edited", task.getHash())); } } t.projectId = task.getProjectId(); t.notifyMe = task.getNotifyMe(); t.meetingDate = task.getMeetingDate(); t.product = task.getProduct(); /*if (task.getPWork().Equals("100") || task.getStatus().ToUpper().Equals("COMPLETO")) * { * t.status = "Completo"; * t.pWork = "100"; * t.actualFinishDate = string.Format("{0:dd/MM/yyyy}", DateTime.Now); * } * else * { * if (!isNew) * { * if (!task.getStatus().ToUpper().Equals("COMPLETO") && t.status.ToUpper().Equals("COMPLETO")) * { * t.reworkCount = Convert.ToInt32(t.reworkCount) + 1; * } * } * else * { * t.reworkCount = task.getReworkCount(); * } * t.status = task.getStatus(); * t.pWork = task.getPWork(); * t.actualFinishDate = task.getActualFinishDate(); * }*/ if (!isNew) { if (!task.getStatus().ToUpper().Equals("COMPLETO") && t.status.ToUpper().Equals("COMPLETO")) { t.reworkCount = Convert.ToInt32(t.reworkCount) + 1; t.status = task.getStatus(); t.pWork = task.getPWork(); } else if (task.getActivityOrigin().ToUpper().Equals("PROJECT")) { t.status = task.getStatus(); t.pWork = task.getPWork(); } } else { t.status = task.getStatus(); t.pWork = task.getPWork(); } t.criticalActivity = task.getCriticalActivity(); t.activityTitle = task.getActivityTitle(); t.activityDescription = task.getActivityDescription(); t.parent = task.getParent(); t.grandParent = task.getGrandParent(); t.responsible = task.getResponsible(); t.start = task.getStart(); t.finish = task.getFinish(); t.activityOrigin = task.getActivityOrigin(); t.idProjectTask = task.getIdProjectTask(); t.idParentProjectTask = task.getIdParentProjectTask(); t.ident = task.getIdent(); t.hash = task.getHash(); t.newStart = task.getNewStart(); t.newFinish = task.getNewFinish(); if (isNew) { db.tasks.Add(t); } db.SaveChanges(); if (isNew) { return(new Response(task.getTaskId(), "Created", task.getHash())); } else { return(new Response(task.getTaskId(), "Edited", task.getHash())); } } catch (DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } }
public static List <Dashboard> select(User requester, int taskStatus) { try { nova_ataEntities db = new nova_ataEntities(); int userId = requester.getUserId(); string userArea = requester.getArea(); string userAlias = requester.getAlias(); List <Dashboard> listOfDashboards = new List <Dashboard>(); var projects = from ta in db.team_allocation join p in db.projects on ta.projectId equals p.projectId join u in db.users on ta.userId equals u.userId where (u.alias == userAlias && ta.userId == u.userId) || (p.leaderOrSubmitter == userId) group ta by new { p.projectId, p.name, p.projectStatus, p.productProjectStage, p.parentProgramIDNumber, p.parentProgramName } into g orderby g.Key.projectId ascending select new { g.Key.projectId, g.Key.name, g.Key.projectStatus, g.Key.productProjectStage, g.Key.parentProgramIDNumber, g.Key.parentProgramName }; List <string> listOfIds = new List <string>(); foreach (var project in projects) { try { if (!listOfIds.Any(y => y == string.Format("{0}?{1}", project.projectId, project.name))) { listOfIds.Add(string.Format("{0}?{1}", project.projectId, project.name)); } if (project.parentProgramIDNumber != "0" && !listOfIds.Any(x => x == string.Format("{0}?{1}", project.parentProgramIDNumber, project.parentProgramName))) { listOfIds.Add(string.Format("{0}?{1}", project.parentProgramIDNumber, project.parentProgramName)); } } catch { continue; } } var tasks = (dynamic)null; foreach (string project in listOfIds) { Dashboard dashboard = new Dashboard(project); int projectId = dashboard.getProjectId(); //Somente atividades em andamento ou atrasadas if (taskStatus == 1) { tasks = from t in db.tasks join p in db.projects on t.projectId equals p.projectId where t.projectId == projectId where t.status.ToUpper() == "ANDAMENTO" || t.status.ToUpper() == "ATRASADO" where t.responsible.Contains(userArea) orderby t.finish ascending select new { tarefas = t, projeto = p }; } //Todas as atividades else if (taskStatus == 0) { tasks = from t in db.tasks join p in db.projects on t.projectId equals p.projectId where t.projectId == projectId where t.responsible.Contains(userArea) orderby t.finish ascending select new { tarefas = t, projeto = p }; } //Somente atividades completas else { tasks = from t in db.tasks join p in db.projects on t.projectId equals p.projectId where t.projectId == projectId where t.status.ToUpper() == "COMPLETO" where t.responsible.Contains(userArea) orderby t.finish ascending select new { tarefas = t, projeto = p }; } foreach (var task in tasks) { Task t = new Task(task.tarefas.taskId, task.tarefas.projectId, task.tarefas.notifyMe, task.tarefas.meetingDate, task.tarefas.product, task.tarefas.pWork, task.tarefas.criticalActivity, task.tarefas.activityTitle, task.tarefas.activityDescription, task.tarefas.parent, task.tarefas.grandParent, task.tarefas.responsible, task.tarefas.start, task.tarefas.finish, task.tarefas.status, CommentDAO.selectLastComment(task.tarefas.taskId), task.tarefas.activityOrigin, task.tarefas.idProjectTask, task.tarefas.idParentProjectTask, task.tarefas.ident, task.tarefas.hash, task.tarefas.delayReason, task.tarefas.delayDescription, requester, task.tarefas.reworkCount, task.tarefas.actualFinishDate); dashboard.addTaskToList(t); } if (dashboard.listOfTasks.Count() > 0) { listOfDashboards.Add(dashboard); } } return(listOfDashboards); } catch (Exception ex) { throw new Exception(ex.Message); } }
public static void checkIfNotificationIsNecessary(int projectId) { try { nova_ataEntities db = new nova_ataEntities(); string projectName = string.Empty; string businessUnit = string.Empty; bool isAllCompleted = true; bool needsNotification = false; var tasks = from t in db.tasks where t.criticalActivity == "5000" where t.projectId == projectId select new { t.status, t.projects.businessUnit, t.projects.name }; if (tasks.ToList().Count() > 0) { businessUnit = tasks.ToList()[0].businessUnit; projectName = tasks.ToList()[0].name; foreach (var t in tasks) { if (!t.status.ToUpper().Equals("COMPLETO")) { isAllCompleted = false; } } } else { isAllCompleted = false; } var notification = (dynamic)null; notification = db.notifications.Find(projectId); if (notification == null) { needsNotification = true; notification = db.notifications.Create(); notification.projectId = projectId; notification.status = "NOT SENT"; db.notifications.Add(notification); db.SaveChanges(); } else { if (notification.status.Equals("NOT SENT")) { needsNotification = true; } } if (isAllCompleted && needsNotification) { notification.status = "SENT"; db.SaveChanges(); Mail.sendMail(0, UserDAO.instanceByBusinessUnit(businessUnit), projectId, projectName); } if (!isAllCompleted && !needsNotification) { notification.status = "NOT SENT"; db.SaveChanges(); Mail.sendMail(1, UserDAO.instanceByBusinessUnit(businessUnit), projectId, projectName); } } catch (Exception ex) { throw new Exception(ex.Message); } }