public async Task <IActionResult> Index(string teamName) { var teamId = userSessionHelper.TeamId; var vm = new DashBoardVm { }; if (!string.IsNullOrEmpty(teamName)) { var team = teamManager.GetTeam(teamName); if (team != null) { //If the current user who is accessing is already a member of this team, if (teamManager.DoesCurrentUserBelongsToTeam(this.userSessionHelper.UserId, team.Id)) { vm.IsCurrentUserTeamMember = true; //userSessionHelper.SetTeamId(team.Id); //await userAccountManager.SetDefaultTeam(userSessionHelper.UserId, teamId); } else { // He is either accessing a public dashboard or TRYING to peep into a private dashboard if (team.IsPublic) { teamId = team.Id; vm.TeamKey = teamId.GetHashCode(); } else { return(View("NotFound")); } } } else { return(View("NotFound")); } } vm.TeamId = teamId; if (userSessionHelper.TeamId > 0) { if (teamManager.DoesCurrentUserBelongsToTeam(this.userSessionHelper.UserId, teamId)) { vm.IsCurrentUserTeamMember = true; var myIssues = await issueManager.GetIssuesAssignedToUser(this.userSessionHelper.UserId); vm.IssuesAssignedToMe = myIssues; } } var issues = this.issueManager.GetIssuesGroupedByStatusGroup(teamId, 25).SelectMany(f => f.Issues).OrderByDescending(s => s.CreatedDate).ToList(); vm.RecentIssues = issues; vm.Projects = this.projectManager.GetProjects(teamId).ToList(); return(View(vm)); }
public async Task <IActionResult> Index(string teamName) { tc.TrackEvent("Dashboard view"); var vm = new DashBoardVm { }; try { var teamId = _userSessionHelper.TeamId; if (!string.IsNullOrEmpty(teamName)) { var team = _teamManager.GetTeam(teamName); if (team != null) { //If the current user who is accessing is already a member of this team, if (_teamManager.DoesCurrentUserBelongsToTeam(this._userSessionHelper.UserId, team.Id)) { vm.IsCurrentUserTeamMember = true; //userSessionHelper.SetTeamId(team.Id); //await userAccountManager.SetDefaultTeam(userSessionHelper.UserId, teamId); } else { // He is either accessing a public dashboard or TRYING to peep into a private dashboard if (team.IsPublic) { teamId = team.Id; vm.TeamKey = teamId.GetHashCode(); tc.TrackEvent("Public dashboard view-" + team.Name.ToLower()); } else { return(View("NotFound")); } } } else { return(View("NotFound")); } } vm.TeamId = teamId; if (_userSessionHelper.TeamId > 0) { if (_teamManager.DoesCurrentUserBelongsToTeam(this._userSessionHelper.UserId, teamId)) { vm.IsCurrentUserTeamMember = true; var myIssues = await _issueManager.GetIssuesAssignedToUser(this._userSessionHelper.UserId); vm.OverDueIssuesAssignedToMe = myIssues .Where(d => d.DueDate != null && d.DueDate.Value < DateTime.Now) .Where(c => c.Status.Code != "Completed" || c.Status.Code != "Closed").OrderBy(f => f.DueDate); vm.IssuesAssignedToMe = myIssues; } } var issues = this._issueManager.GetIssuesGroupedByStatusGroup(teamId, 25) .SelectMany(f => f.Issues) .OrderByDescending(s => s.CreatedDate) .ToList(); vm.RecentIssues = issues; vm.Projects = this._projectManager.GetProjects(teamId).ToList(); } catch (Exception ex) { tc.TrackException(ex); } return(View(vm)); }
// GET: Dashboard public ActionResult Index() { try { DateTime startDayOfYear = new DateTime(UTILITY.SINGAPORETIME.Year, 01, 01); if (ROLECODE == UTILITY.ROLE_SUPERADMIN) { using (var dbCntx = new HrDataContext()) { List <Branch> branches = dbCntx.Branches.ToList(); List <EmployeeDataVm> superadminGenderCount = new List <EmployeeDataVm>(); foreach (Branch branch in branches) { var count = dbCntx.EmployeePersonalDetails .Where(x => x.BranchId == branch.BranchID).Count(); if (count > 0) { EmployeeDataVm employeeDataVm = new EmployeeDataVm(); employeeDataVm.genderCount = new List <GenderCount>(); employeeDataVm.branchName = branch.BranchName; GenderCount malecount = new GenderCount(); malecount.name = "Male"; malecount.y = dbCntx.EmployeePersonalDetails .Where(x => x.Gender == 101 && x.BranchId == branch.BranchID).Count(); malecount.custom = malecount.y; employeeDataVm.genderCount.Add(malecount); GenderCount femalecount = new GenderCount(); femalecount.name = "Female"; femalecount.y = dbCntx.EmployeePersonalDetails .Where(x => x.Gender == 102 && x.BranchId == branch.BranchID).Count(); femalecount.custom = femalecount.y; employeeDataVm.genderCount.Add(femalecount); superadminGenderCount.Add(employeeDataVm); } } ViewData["BranchId"] = BRANCHID; return(View("index", superadminGenderCount)); } } else if (ROLECODE == UTILITY.ROLE_ADMIN) { using (var dbCntx = new HrDataContext()) { DashBoardVm obj = new DashBoardVm(); /* * obj.EmployeeCount = dbCntx.EmployeeHeaders * .Where(x => x.BranchId == BRANCHID) * .Count();*/ obj.EmployeeCount = dbCntx.usp_EmployeeDetail(BRANCHID, ROLECODE).Count(); obj.lineChartData = dbCntx.usp_EmployeeDateOfJoiningDate(UTILITY.SINGAPORETIME, BRANCHID) .ToList() .AsEnumerable(); Branch branch = dbCntx.Branches.Where(x => x.BranchID == BRANCHID).FirstOrDefault(); //List<EmployeeDataVm> employeeDataVm = new List<EmployeeDataVm>(); obj.employeeDataVm = new EmployeeDataVm(); obj.employeeDataVm.genderCount = new List <GenderCount>(); obj.employeeDataVm.branchName = branch.BranchName; GenderCount malecount = new GenderCount(); malecount.name = "Male"; malecount.y = dbCntx.EmployeePersonalDetails .Where(x => x.Gender == 101 && x.BranchId == branch.BranchID).Count(); malecount.custom = malecount.y; obj.employeeDataVm.genderCount.Add(malecount); GenderCount femalecount = new GenderCount(); femalecount.name = "Female"; femalecount.y = dbCntx.EmployeePersonalDetails .Where(x => x.Gender == 102 && x.BranchId == branch.BranchID).Count(); femalecount.custom = femalecount.y; obj.employeeDataVm.genderCount.Add(femalecount); //var query = dbCntx.EmployeeLeaveLists // .Where(x => x.EmployeeId == EMPLOYEEID && x.BranchId == BRANCHID); //var leaveStartTransactions = dbCntx.LeaveTrans // .Where(x => x.EmployeeId == EMPLOYEEID && x.BranchId == BRANCHID && x.CreatedOn >= startDayOfYear) // .OrderBy(x => x.TransactionId) // .FirstOrDefault(); //if (leaveStartTransactions != null) //{ // obj.totalPLs = leaveStartTransactions.CurrentLeaves; // obj.totalCLs = leaveStartTransactions.CurrentLeaves; // DateTime now = DateTime.Now; // var startDate = new DateTime(now.Year, now.Month, 1); // var endDate = startDate.AddMonths(1).AddDays(-1); // var SLPerMonth = dbCntx.Leaves.Where(x => x.BranchId == BRANCHID).FirstOrDefault().SickLeavesPerMonth; // var CurrentMonthSLs = query.Where(x => x.FromDate >= startDate && x.ToDate <= endDate && x.LeaveTypeId == 1031).ToList(); // foreach (var item in CurrentMonthSLs) // { // obj.totalSLs += item.Days.Value; // } // obj.totalSLs = SLPerMonth.Value - obj.totalSLs; //} ViewData["BranchId"] = BRANCHID; return(View("admindashboard", obj)); } } else if (ROLECODE == UTILITY.ROLE_EMPLOYEE) { using (var dbCntx = new HrDataContext()) { EmployeeDashBoardVm obj = new EmployeeDashBoardVm(); var empheader = dbCntx.EmployeeHeaders.Where(x => x.EmployeeId == EMPLOYEEID).FirstOrDefault(); var managername = dbCntx.EmployeeHeaders.Where(x => x.EmployeeId == empheader.ManagerId).FirstOrDefault(); if (empheader != null) { int managerId = empheader.ManagerId == null ? 0 : empheader.ManagerId.Value; if (managerId == 0) { ViewData["message"] = "You Don't Have Reporting Manger"; } else { ViewData["message"] = "Your Reporting manager is" + " " + managername.FirstName + " " + managername.LastName; } } var query = dbCntx.EmployeeLeaveLists .Where(x => x.EmployeeId == EMPLOYEEID && x.BranchId == BRANCHID); var empLeaveDetails = query.OrderByDescending(x => x.EmployeeLeaveID) .ThenByDescending(x => x.ApplyDate) .Take(5) .Select(x => new EmpLeaveDashBoard { FromDate = x.FromDate, ToDate = x.ToDate, ApplyDate = x.ApplyDate, LeaveTypeDesc = dbCntx.LookUps.Where(y => y.LookUpID == x.LeaveTypeId).FirstOrDefault().LookUpDescription, Status = x.Status, Days = x.Days.Value, Reason = x.Reason }) .ToList() .AsEnumerable(); LeaveMaster lMaster = new LeaveMaster(); var paidLeave = lMaster.ANNUALLEAVE(BRANCHID); var sickLeave = lMaster.MEDICALLEAVE(BRANCHID); LeaveReportVm vm = new LeaveReportVm(); vm.consReport = LEAVEREPORTYTD(BRANCHID, DateTime.Now.Year, EMPLOYEEID); List <OtherLeave> leavepolicy = dbCntx.OtherLeaves.Where(x => x.BranchId == BRANCHID && x.IsActive == true).ToList(); if (leavepolicy.Count != 0) { var annualLeaves = vm.consReport.Where(x => x.LeaveType.ToUpper() == "ANNUAL LEAVE"); var medicalLeaves = vm.consReport.Where(x => x.LeaveType.ToUpper() == "MEDICAL LEAVE"); var totalpaidleaves = annualLeaves.Sum(x => x.TotalLeaves) + (annualLeaves.FirstOrDefault() == null ? 0 : annualLeaves.FirstOrDefault().BalanceLeaves); var totalsickLeaves = medicalLeaves.Sum(x => x.TotalLeaves) + (medicalLeaves.FirstOrDefault() == null ? 0 : medicalLeaves.FirstOrDefault().BalanceLeaves); obj.empLeaveDashBoard = empLeaveDetails.ToList(); obj.totalPLs = totalpaidleaves; obj.totalSLs = totalsickLeaves; obj.currentpls = annualLeaves.Sum(x => x.TotalLeaves); obj.currentsls = medicalLeaves.Sum(x => x.TotalLeaves); obj.remainingpls = annualLeaves.FirstOrDefault() == null ? 0 : annualLeaves.FirstOrDefault().BalanceLeaves; obj.remainingsls = medicalLeaves.FirstOrDefault() == null ? 0 : medicalLeaves.FirstOrDefault().BalanceLeaves; obj.EmployeeId = EMPLOYEEID; obj.EmployeeName = empheader.FirstName + " " + empheader.LastName; ViewData["Alert"] = ""; } else { obj.empLeaveDashBoard = empLeaveDetails.ToList(); obj.totalPLs = 0; obj.totalSLs = 0; obj.currentpls = 0; obj.currentsls = 0; obj.EmployeeId = EMPLOYEEID; obj.EmployeeName = empheader.FirstName + " " + empheader.LastName; ViewData["Alert"] = UTILITY.MISSINGLEAVEPOLICYALERT; } return(View("employeedashboard", obj)); } } } catch (Exception ex) { //Session["ErrMsg"] = ex.Message + " " + // ex.StackTrace + " " + // ex.TargetSite + " " + // ex.Source; throw; } return(View()); }