public async Task <IActionResult> MyTeamRevisionRequest(string date, string searchtext, int draw, int start, int length = 10)
        {
            int pageIndex = 0;

            if (start != 0)
            {
                pageIndex = start / length + 1;
            }

            if (pageIndex == 0)
            {
                pageIndex = 1;
            }

            //var dateRequested = DateTime.ParseExact(date, "yyyMMdd", CultureInfo.InvariantCulture);

            MyTeamDataTableData dataTableData = new MyTeamDataTableData();

            if (User.Identity.IsAuthenticated)
            {
                MyTeamHoursViewModel myTeamsHoursViewModel = new MyTeamHoursViewModel();
                if (_userProfile == null)
                {
                    _userProfile = await _userProfileRepository.GetItemAsync();
                }
                ViewData["Email"]     = _userProfile.Fields.Upn;
                ViewData["IsManager"] = _userProfile.Fields.IsManager;
                ViewData["IsHr"]      = _userProfile.Fields.IsHr;
                ViewData["IsAdmin"]   = _userProfile.Fields.IsAdmin;
                ViewData["UserImage"] = _userProfile.Fields.UserPicture;

                DateTime selDt = DateTime.Now.AddMonths(-1);
                if (date != null)
                {
                    selDt = DateTime.Parse(date);
                }

                string             searchQuery        = HttpContext.Request.Query["search[value]"].ToString();
                TeamHoursViewModel teamHoursViewModel = new TeamHoursViewModel();
                if (searchtext != null)
                {
                    teamHoursViewModel = await _teamHoursService.GetSearchResults(selDt, searchtext, pageIndex, length);

                    dataTableData = teamHoursViewModel.MyTeamDataTableData;
                }
                else
                {
                    teamHoursViewModel = await _teamHoursService.GetViewModel(selDt, pageIndex, length);

                    dataTableData = teamHoursViewModel.MyTeamDataTableData;
                }


                dataTableData.draw         = draw;
                dataTableData.recordsTotal = (pageIndex * length) + dataTableData.data.Count + 1;
                int recordsFiltered = (pageIndex * length) + dataTableData.data.Count + 1;

                dataTableData.recordsFiltered = recordsFiltered;

                if (date == null)
                {
                    myTeamsHoursViewModel.SearchDate = myTeamsHoursViewModel.fnGetLastMonthEndDate();
                }
                else
                {
                    myTeamsHoursViewModel.SearchDate = selDt;
                }

                myTeamsHoursViewModel.UserInfo = _userProfile;
                //return View(myTeamsHoursViewModel);

                if (teamHoursViewModel.MyTeamDataTableData.data.Exists(x => x.SubmittedDate == DateTime.MinValue))
                {
                    myTeamsHoursViewModel.IsSubmitted = false;
                }
                else
                {
                    myTeamsHoursViewModel.IsSubmitted = true;
                }

                return(Json(dataTableData));
            }
            else
            {
                ErrorViewModel EVM = new ErrorViewModel();

                return(View(EVM));
            }

            //return Json(dataTableData);
        }
Пример #2
0
        public async Task <TeamHoursViewModel> GetViewModel(DateTime date, int pageIndex = 1, int pageSize = 10)
        {
            var  ci            = System.Threading.Thread.CurrentThread.CurrentCulture;
            bool userSubmitted = false;
            bool mgrSubmitted  = false;
            bool submitToHR    = false;

            try
            {
                if (_listCollectionPage == null)
                {
                    _listCollectionPage = await _teamHoursRepository.GetItemsAsync(date, pageSize);
                }

                // Exit from search
                //if (!String.IsNullOrEmpty(_listCollectionPage.SearchQuery)) _listCollectionPage = await _teamHoursRepository.GetItemsAsync(date, pageSize);

                // Check to see if a new date is being requested
                if (_listCollectionPage.QueryDate != date.ToString("yyyyMM"))
                {
                    _listCollectionPage = await _teamHoursRepository.GetItemsAsync(date, pageSize);
                }

                if ((pageIndex - _listCollectionPage.CurrentPageIndex) == 1)
                {
                    // Move next
                    _listCollectionPage = await _teamHoursRepository.GetNextItemsAsync(_listCollectionPage);
                }
                else if ((_listCollectionPage.CurrentPageIndex - pageIndex) == 1)
                {
                    // Move previous
                    _listCollectionPage = await _teamHoursRepository.GetPreviousItemsAsync(_listCollectionPage);
                }
                else if (pageIndex > 2)  // Increment until we find the correct page.
                {
                    while (_listCollectionPage.CurrentPageIndex < pageIndex)
                    {
                        _listCollectionPage = await _teamHoursRepository.GetNextItemsAsync(_listCollectionPage);
                    }
                }
                //var saveResults = await _graphSharePointService.CreateSiteListItemAsync(analyticsSiteList, dailyOTHoursRootObject.ToString());
                // Create the DataTable
                MyTeamDataTableData dataTableData = new MyTeamDataTableData();

                List <TeamHoursListData> th = new List <TeamHoursListData>();
                foreach (var item in _listCollectionPage.DataList)
                {
                    var computedHours = item.Fields.EmailHours + item.Fields.MeetingHours + item.Fields.OtherHours +
                                        ((item.Fields.EmailMinutes + item.Fields.MeetingMinutes + item.Fields.OtherMinutes) / 60);
                    var computedMinutes = (item.Fields.EmailMinutes + item.Fields.MeetingMinutes + item.Fields.OtherMinutes) % 60;

                    /*
                     *                  var AdjustedHours = item.Fields.EmailAdjustedHours + item.Fields.MeetingAdjustedHours + item.Fields.OtherAdjustedHours +
                     *                  ((item.Fields.EmailAdjustedMinutes + item.Fields.MeetingAdjustedMinutes + item.Fields.OtherAdjustedMinutes) / 60);
                     *                  var AdjustedMinutes = (item.Fields.EmailAdjustedMinutes + item.Fields.MeetingAdjustedMinutes + item.Fields.OtherAdjustedMinutes) % 60;
                     */
                    ConcurrentDictionary <string, short> hrsMins = new ConcurrentDictionary <string, short>();

                    //call to get Final hours for ReportHours Repository data
                    hrsMins = HoursComputeHelper.GetFinalTeamHrsMins(item);
                    var AdjustedHours   = hrsMins["FinalTotalHrs"];
                    var AdjustedMinutes = hrsMins["FinalTotalMins"];

                    string status      = "";
                    string actionLinks = "";
                    if (item.Fields.TeamHoursItemState.ToString() == ItemState.Submitted.ToString())
                    {
                        mgrSubmitted = true;
                        status       = item.Fields.ItemState.ToString();
                        actionLinks += "<span class='recheckHrs icon-noaction'> <i class='ms-Icon ms-Icon--DelveAnalytics font20' title='Request Revision'></i></span>";
                    }
                    else if (item.Fields.ItemState.ToString() == ItemState.Submitted.ToString())
                    {
                        userSubmitted = true;
                        status        = item.Fields.ItemState.ToString();
                        actionLinks  += "<span class='recheckHrs'> <i class='ms-Icon ms-Icon--DelveAnalytics font20 Pointer' title='Request Revision'></i></span>";
                    }
                    else if (item.Fields.ItemState.ToString() == ItemState.RequiresRevision.ToString())
                    {
                        status       = "Requires Revision";
                        actionLinks += "<span class='recheckHrs icon-noaction'> <i class='ms-Icon ms-Icon--DelveAnalytics font20' title='Request Revision'></i></span>";
                    }
                    else if (item.Fields.ItemState.ToString() == ItemState.NotSubmitted.ToString())
                    {
                        status       = "Not Submitted";
                        actionLinks += "<span class='recheckHrs icon-noaction'> <i class='ms-Icon ms-Icon--DelveAnalytics font20' title='Request Revision'></i></span>";
                    }
                    else if (item.Fields.ItemState.ToString() == ItemState.SubmittedBySystem.ToString())
                    {
                        userSubmitted = true;
                        status        = "Submitted By System";
                        actionLinks  += "<span class='recheckHrs'> <i class='ms-Icon ms-Icon--DelveAnalytics font20 Pointer' title='Request Revision'></i></span>";
                    }
                    else
                    {
                        status       = item.Fields.ItemState.ToString();
                        actionLinks += "<span class='recheckHrs icon-noaction'> <i class='ms-Icon ms-Icon--DelveAnalytics font20' title='Request Revision'></i></span>";
                    }

                    if (userSubmitted && !mgrSubmitted)  // Enable Submit Button.
                    {
                        submitToHR = true;
                    }

                    // reset the 2 local variables - never reset submitToHR.
                    userSubmitted = false;
                    mgrSubmitted  = false;

                    var t = new TeamHoursListData
                    {
                        Name             = item.Fields.DisplayName,
                        ComputedHours    = computedHours + "h " + computedMinutes + "m",
                        AdjustedHours    = AdjustedHours + "h " + AdjustedMinutes + "m",
                        ObjectIdentifier = item.Fields.ObjectIdentifier,
                        Status           = status,
                        Action           = actionLinks,
                        Id            = item.Id,
                        Date          = item.Fields.Date,
                        SubmittedDate = item.Fields.TeamHoursSubmittedDate
                    };
                    th.Add(t);
                }

                dataTableData.recordsTotal = (pageIndex * pageSize) + th.Count + 1;
                int recordsFiltered = (pageIndex * pageSize) + th.Count + 1;

                dataTableData.recordsFiltered = recordsFiltered;
                dataTableData.data            = th;
                dataTableData.SubmittedDate   = (dataTableData.data.Exists(x => x.SubmittedDate != DateTime.MinValue) ? dataTableData.data.FirstOrDefault().SubmittedDate.ToShortDateString() : DateTime.MinValue.ToShortDateString());
                //dataTableData.SubmitEnable = (dataTableData.data.Exists(x => x.SubmittedDate == DateTime.MinValue) ? true : false);
                dataTableData.SubmitEnable = (dataTableData.data.Exists(x => x.Status == ItemState.Submitted.ToString()) ? true : false);
                dataTableData.SubmitToHR   = submitToHR;

                var teamHoursViewModel = new TeamHoursViewModel
                {
                    MyTeamDataTableData = dataTableData,
                    RequestRevision     = "is-disabled",
                    EditTeamHours       = "is-disabled",
                };

                return(teamHoursViewModel);
            }
            catch (Exception ex)
            {
                return(new TeamHoursViewModel());
            }
        }
 public TeamHoursViewModel()
 {
     MyTeamDataTableData = new MyTeamDataTableData();
     PaginationInfo      = new PaginationInfoViewModel();
 }