public void StatusTest(string input, TimesheetStatus expected) { JsonDoc.Assert <Timesheet, TimesheetStatus>( input: new JsonDoc.String(nameof(Timesheet.Status), input), toProperty: x => x.Status, shouldBe: expected ); }
public void UpdateTimesheetStatusWithNoHistory(int timesheetId, TimesheetStatus timesheetStatus) { var timesheet = context.TimeSheets.FirstOrDefault(x => x.TimeSheetId == timesheetId); timesheet.TimeSheetStatusId = (byte)timesheetStatus; context.TimeSheets.Context.ObjectStateManager.ChangeObjectState(timesheet, EntityState.Modified); context.SaveChanges(); }
public void CreateTimesheetHistory(int timesheetId, TimesheetStatus status, string comment = "", int?associateId = null, int?approverAssociateId = null, int?approverClientContactId = null) { if (timesheetId == default(int)) { throw new ArgumentNullException("invalid timesheetId"); } context.Context.CreateTimesheetHistory(timesheetId, (int)status, comment, associateId, approverAssociateId, approverClientContactId); }
public void UpdateStatus(int timesheetId, TimesheetStatus status, string comment = "", int?associateId = null, int?approverAssociateId = null, int?approverClientContactId = null, string timesheetChecker = null) { if (timesheetId == default(int)) { throw new ArgumentNullException("invalid timesheetId"); } context.Context.UpdateTimeSheetStatus(timesheetId, (int)status, comment, associateId, approverAssociateId, approverClientContactId, timesheetChecker); }
public void SetState(int timeSheetId, TimesheetStatus newState, string notes = null) { var timeSheet = DataContext.TimeSheets.FirstOrDefault(i => i.tid == timeSheetId); if (timeSheet != null) { if (notes != null) { timeSheet.notes = notes; } timeSheet.statusid = (int)newState; DataContext.SaveChanges(); } }
/// <summary> /// Gets the timesheet requests using project Id. /// </summary> /// <param name="projectIds">The project Ids of which requests to get.</param> /// <param name="timesheetStatus">Indicates the status of timesheet.</param> /// /// <param name="startDate">Start date of the month.</param> /// <param name="endDate">Last date the of the month</param> /// <returns>Returns the collection of timesheet requests.</returns> public IEnumerable <TimesheetEntity> GetTimesheetRequestsByProjectIds(IEnumerable <Guid> projectIds, TimesheetStatus timesheetStatus, DateTime startDate, DateTime endDate) { var status = (int)timesheetStatus; return(this.Context.Timesheets .Include(timesheet => timesheet.Task) .Where(timesheet => projectIds.Contains(timesheet.Task.ProjectId) && timesheet.Status == status && timesheet.TimesheetDate >= startDate.Date && timesheet.TimesheetDate.Date <= endDate.Date && !timesheet.Task.IsRemoved)); }
/// <summary> /// Gets the timesheet requests using project id /// </summary> /// <param name="projectId">The project id of which requests to get.</param> /// <param name="timesheetStatus">Indicates the status of timesheet.</param> /// <param name="startDate">Start date of the month.</param> /// <param name="endDate">Last date the of the month</param> /// <returns>Returns the collection of timesheet requests.</returns> public IEnumerable <TimesheetEntity> GetTimesheetRequestsByProjectId(Guid projectId, TimesheetStatus timesheetStatus, DateTime startDate, DateTime endDate) { var status = (int)timesheetStatus; return(this.Context.Timesheets .Where(timesheet => timesheet.Task.ProjectId == projectId && timesheet.Status == status && timesheet.TimesheetDate >= startDate.Date && timesheet.TimesheetDate.Date <= endDate.Date) .Include(timesheet => timesheet.Task)); }
/// <summary> /// Gets the submitted timesheets of a reportee. /// </summary> /// <param name="userObjectIds">The user Ids of which timesheets to get.</param> /// <param name="status">Timesheet status for filtering.</param> /// <returns>Returns user id and list of timesheets key value pairs.</returns> public Dictionary <Guid, IEnumerable <TimesheetEntity> > GetTimesheetOfUsersByStatus(List <Guid> userObjectIds, TimesheetStatus status) { return(this.Context.Timesheets .Where(timesheet => timesheet.Status == (int)status && userObjectIds.Contains(timesheet.UserId) && !timesheet.Task.IsRemoved) .Include(timesheet => timesheet.Task) .Include(timesheet => timesheet.Task.Project) .AsEnumerable() .GroupBy(timesheet => timesheet.UserId) .ToDictionary(timesheet => timesheet.Key, timesheet => timesheet.AsEnumerable())); }
/// <summary> /// Gets the timesheet by manager Id. /// </summary> /// <param name="managerId">The manager Id of the project's creator for which timesheets to get.</param> /// <param name="timesheetStatus">The status of timesheets to get.</param> /// <returns>Returns user id and list of timesheets key value pairs.</returns> public Dictionary <Guid, IEnumerable <TimesheetEntity> > GetTimesheetsByManagerId(Guid managerId, TimesheetStatus timesheetStatus) { return(this.Context.Timesheets .Where(timesheet => timesheet.Status == (int)timesheetStatus && timesheet.Task.Project.CreatedBy == managerId && !timesheet.Task.IsRemoved) .AsEnumerable() .GroupBy(timesheet => timesheet.UserId) .ToDictionary(timesheet => timesheet.Key, timesheet => timesheet.AsEnumerable())); }
/// <summary> /// To approve or reject the timesheets. /// </summary> /// <param name="timesheets">Timesheets to be approved or rejected. /// Timesheets are validated at controller that it should be submitted to the logged-in manager.</param> /// <param name="timesheetApprovals">The details of timesheets which are approved or reject by the manager.</param> /// <param name="status">If true, the timesheet get approved. Else timesheet get rejected.</param> /// <returns>Returns true if timesheets approved or rejected successfully. Else returns false.</returns> public async Task <bool> ApproveOrRejectTimesheetsAsync(IEnumerable <TimesheetEntity> timesheets, IEnumerable <RequestApprovalDTO> timesheetApprovals, TimesheetStatus status) { var timesheetsToUpdateCount = timesheets.Count(); #pragma warning disable CA1062 // Null check is handled by controller. foreach (var timesheetRequest in timesheets) #pragma warning restore CA1062 // Null check is handled by controller. { var approvalDetails = timesheetApprovals.Where(requestApproval => requestApproval.TimesheetId == timesheetRequest.Id).First(); timesheetRequest.Status = (int)status; timesheetRequest.ManagerComments = status == TimesheetStatus.Rejected ? approvalDetails.ManagerComments : string.Empty; } using (var transaction = this.repositoryAccessors.Context.Database.BeginTransaction()) { try { this.repositoryAccessors.TimesheetRepository.Update(timesheets); var responseCount = await this.repositoryAccessors.SaveChangesAsync(); if (responseCount == timesheetsToUpdateCount) { transaction.Commit(); return(true); } } #pragma warning disable CA1031 // Handled general exception catch #pragma warning restore CA1031 // Handled general exception { transaction.Rollback(); } } return(false); }
/// <summary> /// Generate adaptive card for notification. /// </summary> /// <param name="cardDetails">Adaptive card to be sent.</param> /// <param name="userConversation">User conversation.</param> /// <param name="status">Status of timesheet approval.</param> /// <returns>Task represent async operation.</returns> internal async Tasks.Task NotifyUserAsync(ApproveRejectCard cardDetails, Conversation userConversation, TimesheetStatus status) { if (status == TimesheetStatus.Approved) { var approvedCardAttachment = this.adaptiveCardService.GetApprovedNotificationCard(cardDetails); await this.notificationHelper.SendNotificationToUserAsync(userConversation, approvedCardAttachment); } else if (status == TimesheetStatus.Rejected) { var rejectedCardAttachment = this.adaptiveCardService.GetRejectedNotificationCard(cardDetails); await this.notificationHelper.SendNotificationToUserAsync(userConversation, rejectedCardAttachment); } }
public IEnumerable <TimeSheet> GetAssociateTimeSheetsByStatus(int associateId, TimesheetStatus status) { return(context.Context.TimeSheets.Where(t => t.AssociateId == associateId && t.TimeSheetStatusId == (byte)status).ToList <TimeSheet>()); }
public IEnumerable <TimeSheet> GetTimeSheetsByStatus(TimesheetStatus status) { return(context.Context.TimeSheets.Where(t => t.TimeSheetStatusId == (byte)status).ToList <TimeSheet>()); }
/// <summary> /// Send notification. /// </summary> /// <param name="timesheets">Details of timesheet.</param> /// <param name="status">Status of timesheet.</param> /// <returns>Task represent async operation.</returns> private async Task <bool> SendNotificationsAsync(List <TimesheetEntity> timesheets, TimesheetStatus status) { var timesheetsGroupedByUser = timesheets.Where(timesheet => timesheet.Hours > 0).GroupBy(timesheet => timesheet.UserId); foreach (var userTimesheets in timesheetsGroupedByUser) { var userConversation = await this.repositoryAccessors.ConversationRepository.GetAsync(userTimesheets.First().UserId); if (userConversation != null) { var groupedByProject = userTimesheets.GroupBy(timesheet => timesheet.Task.ProjectId); foreach (var projectwiseTimesheets in groupedByProject) { var tprojectwiseTimesheets = projectwiseTimesheets.OrderBy(timesheet => timesheet.TimesheetDate).ToList(); var daterange = new List <TimesheetEntity> [100]; int currentItemIndex = 0; for (int i = 0; i < tprojectwiseTimesheets.Count; i++) { if (i == 0) { daterange[currentItemIndex] = new List <TimesheetEntity>(); daterange[currentItemIndex].Add(tprojectwiseTimesheets[i]); } else { if ((tprojectwiseTimesheets[i].TimesheetDate == daterange[currentItemIndex].Last().TimesheetDate) || (tprojectwiseTimesheets[i].TimesheetDate.AddDays(-1) == daterange[currentItemIndex].Last().TimesheetDate)) { daterange[currentItemIndex].Add(tprojectwiseTimesheets[i]); } else { currentItemIndex += 1; daterange[currentItemIndex] = new List <TimesheetEntity>(); daterange[currentItemIndex].Add(tprojectwiseTimesheets[i]); } } } var filteredDaterange = daterange.Where(item => item != null && item.Count > 0); foreach (var item in filteredDaterange) { if (item.Count > 0) { var isTimesheetForOneDay = item.First().TimesheetDate.Date == item.Last().TimesheetDate.Date; var cardDetails = new ApproveRejectCard { Date = isTimesheetForOneDay ? "{{DATE(" + item.First().TimesheetDate.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", CultureInfo.InvariantCulture) + ")}}" : "{{DATE(" + item.First().TimesheetDate.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", CultureInfo.InvariantCulture) + ")}} - {{DATE(" + item.Last().TimesheetDate.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", CultureInfo.InvariantCulture) + ")}}", Hours = Convert.ToString(item.Sum(timesheet => timesheet.Hours), CultureInfo.InvariantCulture), ProjectTitle = item.First().Task.Project.Title, }; if (status == TimesheetStatus.Approved) { var approvedCardAttachment = this.adaptiveCardService.GetApprovedNotificationCard(cardDetails); await this.notificationHelper.SendNotificationToUserAsync(userConversation, approvedCardAttachment); } else if (status == TimesheetStatus.Rejected) { var commentByManager = item.First().ManagerComments; cardDetails.Comment = string.IsNullOrEmpty(commentByManager) ? "-" : commentByManager; var rejectedCardAttachment = this.adaptiveCardService.GetRejectedNotificationCard(cardDetails); await this.notificationHelper.SendNotificationToUserAsync(userConversation, rejectedCardAttachment); } } } } } } return(true); }
/// <summary> /// Gets the active timesheet requests. /// </summary> /// <param name="reporteeObjectId">The user Id of which requests to get.</param> /// <param name="status">Timesheet status for filtering.</param> /// <returns>Returns the list of timesheet requests.</returns> public IEnumerable <SubmittedRequestDTO> GetTimesheetRequestsByStatusAsync(string reporteeObjectId, TimesheetStatus status) { var userObjectIds = new List <Guid> { Guid.Parse(reporteeObjectId), }; var timesheetRequests = this.repositoryAccessors.TimesheetRepository.GetTimesheetRequestsOfUsersByStatus(userObjectIds, status); // Map timesheet to pending request view model. return(this.timesheetMapper.MapToViewModel(timesheetRequests.Values.First()).OrderBy(timesheet => timesheet.TimesheetDate)); }
/// <summary> /// Gets the timesheet requests using task id /// </summary> /// <param name="taskId">The task id of which requests to get.</param> /// <param name="timesheetStatus">Indicates the status of timesheet.</param> /// <param name="startDate">Start date of the month.</param> /// <param name="endDate">Last date the of the month</param> /// <returns>Returns the collection of timesheet requests.</returns> public IEnumerable <TimesheetEntity> GetTimesheetRequestsByTaskId(Guid taskId, TimesheetStatus timesheetStatus, DateTime startDate, DateTime endDate) { return(this.Context.Timesheets .Where(timesheet => timesheet.TaskId == taskId && timesheet.Status == (int)timesheetStatus && timesheet.TimesheetDate >= startDate.Date && timesheet.TimesheetDate.Date <= endDate.Date)); }
/// <summary> /// Send timesheet approval or rejection notifications to users. /// </summary> /// <param name="timesheets">Details of timesheets which got approved/rejected.</param> /// <param name="status">Status of timesheet approval.</param> /// <returns>Task represent async operation.</returns> internal async Tasks.Task SendNotificationsAsync(IEnumerable <TimesheetEntity> timesheets, TimesheetStatus status) { var timesheetsGroupedByUser = timesheets.Where(timesheet => timesheet.Hours > 0).GroupBy(timesheet => timesheet.UserId); foreach (var userTimesheets in timesheetsGroupedByUser) { var userConversation = await this.repositoryAccessors.ConversationRepository.GetAsync(userTimesheets.First().UserId); // If user conversation Id is not stored in database then skip user. if (userConversation == null) { continue; } var groupedByProject = userTimesheets.GroupBy(timesheet => timesheet.Task.ProjectId); // Group by project to send projectwise notification cards. foreach (var projectwiseTimesheets in groupedByProject) { var projectwiseTimesheetsOrderdByDate = projectwiseTimesheets.OrderBy(timesheet => timesheet.TimesheetDate); var timesheetsGroupedByDateSequence = this.GetTimesheetsGroupedByDateSequence(projectwiseTimesheetsOrderdByDate); foreach (var groupedTimesheets in timesheetsGroupedByDateSequence) { var managerComment = status == TimesheetStatus.Rejected ? groupedTimesheets.First().ManagerComments : string.Empty; var card = this.PrepareCard(groupedTimesheets, managerComment); await this.NotifyUserAsync(card, userConversation, status); } } } }
/// <summary> /// Gets timesheet requests which are pending for manager approval. /// </summary> /// <param name="managerObjectId">The manager Id for which request has been raised.</param> /// <param name="timesheetStatus">The status of requests to fetch.</param> /// <returns>Return list of submitted timesheet request.</returns> public async Task <IEnumerable <DashboardRequestDTO> > GetDashboardRequestsAsync(Guid managerObjectId, TimesheetStatus timesheetStatus) { // Get timesheet requests pending with manager. var response = this.repositoryAccessors.TimesheetRepository.GetTimesheetRequestsByManager(managerObjectId, timesheetStatus); if (!response.Any()) { return(null); } // Map timesheet entity to dashboard requests view model. var dashboardRequests = this.managerDashboardMapper.MapForViewModel(response.Values).ToList(); var userIds = dashboardRequests.Select(dashboardRequest => dashboardRequest.UserId.ToString()); var users = await this.userGraphService.GetUsersAsync(userIds); // Mapping users with their graph user display name. for (var i = 0; i < dashboardRequests.Count; i++) { var isUserFound = !users.Where(user => Guid.Parse(user.Id) == dashboardRequests[i].UserId).IsNullOrEmpty(); if (isUserFound) { dashboardRequests[i].UserName = users.Where(user => Guid.Parse(user.Id) == dashboardRequests[i].UserId).FirstOrDefault().DisplayName; } } return(dashboardRequests); }
//For seeding public Timesheet(int id, int version, int empId, int weekNumber, DateTime weekEndingIn, TimesheetStatus status) { this.TimesheetId = id; this.VersionNumber = version; this.EmployeeId = empId; this.WeekNumber = weekNumber; this.WeekEndingIn = weekEndingIn; this.Status = status; this.LastUpdatedTime = DateTime.Now; this.LastUpdatedBy = "Seeded"; this.Comment = "seeded comment"; this.OverTime = 1; this.FlexTime = 2; }
public void Insert(TimesheetStatus log) { throw new System.NotImplementedException(); }
/// <summary> /// Gets the active timesheet requests. /// </summary> /// <param name="reporteeObjectId">The user Id of which requests to get.</param> /// <param name="status">Timesheet status for filtering.</param> /// <returns>Returns the list of timesheet requests.</returns> public IEnumerable <SubmittedRequestDTO> GetTimesheetsByStatus(Guid reporteeObjectId, TimesheetStatus status) { var reporteeObjectIds = new List <Guid> { reporteeObjectId, }; var timesheetRequests = this.repositoryAccessors.TimesheetRepository.GetTimesheetOfUsersByStatus(reporteeObjectIds, status); // Map timesheet to pending request view model. var mappedTimesheets = this.timesheetMapper.MapToViewModel(timesheetRequests.Values.First()); return(mappedTimesheets.OrderBy(timesheet => timesheet.TimesheetDate)); }
/// <summary> /// Gets the timesheet requests. /// </summary> /// <param name="managerId">The manager Id of which requests to get.</param> /// <param name="timesheetStatus">The status of requests to get.</param> /// <returns>Returns the list of timesheet requests.</returns> public async Task <Dictionary <Guid, List <TimesheetEntity> > > GetTimesheetRequestsByManagerAsync(Guid managerId, TimesheetStatus timesheetStatus) { var data = await this.Context.Timesheets .Where(x => x.Status == (int)timesheetStatus && x.Task.Project.CreatedBy == managerId) .ToListAsync(); return(data .AsEnumerable() .GroupBy(x => x.UserId) .ToDictionary(x => x.Key, x => x.ToList())); }