public async Task <ActionResult <TimesheetRow> > PostTimesheetRow(TimesheetRow timesheetRow) { _context.TimesheetRow.Add(timesheetRow); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTimesheetRow", new { id = timesheetRow.Id }, timesheetRow)); }
public async Task <IActionResult> PutTimesheetRow(int id, TimesheetRow timesheetRow) { if (id != timesheetRow.Id) { return(BadRequest()); } _context.Entry(timesheetRow).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TimesheetRowExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("TimesheetRowId,SatHour,SunHour,MonHour,TueHour,WedHour,ThuHour,FriHour,Notes,TimesheetId,WorkPackageId")] TimesheetRow timesheetRow) { if (ModelState.IsValid) { _context.Add(timesheetRow); await _context.SaveChangesAsync(); return(RedirectToAction("Edit", "Timesheets", new { id = timesheetRow.TimesheetId })); } var timesheet = await _context.Timesheets.Include(t => t.Employee).FirstOrDefaultAsync(t => t.TimesheetId == timesheetRow.TimesheetId); var timesheetrows = _context.TimesheetRows.Where(t => t.TimesheetId == timesheetRow.TimesheetId); var pes = _context.ProjectEmployees.Where(pe => pe.EmployeeId == timesheet.EmployeeId); List <WorkPackage> wpl = new List <WorkPackage>(); foreach (ProjectEmployee pe in pes) { bool exist = false; foreach (TimesheetRow tr in timesheetrows) { if (tr.WorkPackageId == pe.WorkPackageId) { exist = true; } } if (!exist) { var wp = await _context.WorkPackages.Include(wpp => wpp.Project).FirstOrDefaultAsync(wpp => wpp.WorkPackageId == pe.WorkPackageId); wpl.Add(wp); } } //authorization if (timesheet.Employee.Id != _userManager.GetUserId(HttpContext.User)) { return(NotFound()); } var wpes = wpl .Select(s => new SelectListItem { Value = s.WorkPackageId.ToString(), Text = s.Project.Name + " --- " + s.Name }); ViewData["WorkPackageId"] = new SelectList(wpes, "Value", "Text"); return(View(timesheetRow)); }
//Constructor that converts tsRow to tsRowViewModel directly public TimesheetRowViewModel(TimesheetRow tsRow) { this.Friday = tsRow.Friday; this.Thursday = tsRow.Thursday; this.Wednesday = tsRow.Wednesday; this.Tuesday = tsRow.Tuesday; this.Monday = tsRow.Monday; this.Saturday = tsRow.Saturday; this.Sunday = tsRow.Sunday; this.Notes = Notes; this.TimesheetId = tsRow.TimesheetId; this.TimesheetVersionNumber = tsRow.TimesheetVersionNumber; this.WorkPackageId = tsRow.WorkPackageId; }
public async Task <IActionResult> Edit(int id, [Bind("TimesheetRowId,SatHour,SunHour,MonHour,TueHour,WedHour,ThuHour,FriHour,Notes,TimesheetId,WorkPackageId")] TimesheetRow timesheetRow) { if (id != timesheetRow.TimesheetRowId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(timesheetRow); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TimesheetRowExists(timesheetRow.TimesheetRowId)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Edit", "Timesheets", new { id = timesheetRow.TimesheetId })); } var timesheet = await _context.Timesheets.Include(t => t.Employee).FirstOrDefaultAsync(t => t.TimesheetId == timesheetRow.TimesheetId); var package = _context.WorkPackages.Find(timesheetRow.WorkPackageId); var project = _context.Projects.Find(package.ProjectId); //authorization if (timesheet.Employee.Id != _userManager.GetUserId(HttpContext.User)) { return(NotFound()); } return(View(timesheetRow)); }
public IssueTimesheetRowModel(TimesheetDialog view, TimesheetRow timesheetRow, List<QuickIssue> quickIssues, List<TimesheetCode> adminCodes) { mMaxHoursInDay = CMS.AppSetting.TimesheetMaxHoursPerDay; mAdminCodes = adminCodes; mTimesheetRow = timesheetRow; QuickIssues = quickIssues; mView = view; SetDayIndexes(); GotFocusCommand = new DelegateCommand<object>(GotFocusHandler, (x) => true); if (mTimesheetRow.IssueId.HasValue) { mSystemReferenceNumbers = timesheetRow.Issue.SystemReferences.Where(x => x.SystemReferenceType.ShowInTimesheet).OrderBy(x => x.Number).ToList(); RaisePropertyChanged("SystemReferenceNumbers"); RaisePropertyChanged("SystemReferenceNumber"); } }
public TimesheetRowViewModel(TimesheetRow tsRow, Project proj, string wpCode) { this.ProjectId = proj.ProjectId; this.ProjectName = proj.ProjectName; this.Friday = tsRow.Friday; this.Thursday = tsRow.Thursday; this.Wednesday = tsRow.Wednesday; this.Tuesday = tsRow.Tuesday; this.Monday = tsRow.Monday; this.Saturday = tsRow.Saturday; this.Sunday = tsRow.Sunday; this.Notes = Notes; this.TimesheetId = tsRow.TimesheetId; this.TimesheetVersionNumber = tsRow.TimesheetVersionNumber; this.WorkPackageId = tsRow.WorkPackageId; this.WorkPackageCode = wpCode; }
private void AddIssueToTimesheets(Issue issue) { //Created Timesheet Row based on Assigned and Favorites Issues var timesheetRow = new TimesheetRow { Timesheet = mTimesheet, IssueId = issue.Id, Issue = issue, TimesheetValues = new List<TimesheetValue>() }; //Add hours for next 7 days for (int i = 0; i < 7; i++) { TimesheetValue timesheetValue = new TimesheetValue { Date = mTimesheet.StartDate.AddDays(i), TimesheetRow = timesheetRow, Hours = 0 }; timesheetRow.TimesheetValues.Add(timesheetValue); } var timesheetRowModel = new IssueTimesheetRowModel(mView, timesheetRow, QuickIssues, mAdminCodes); mIssueTimesheetRowModels.Add(timesheetRowModel); mTimesheet.TimesheetRows.Add(timesheetRow); }
public void SetBindingForNotes(TimesheetRow timesheetRow, int dayIndex) { mTimesheetValue = timesheetRow.TimesheetValues[dayIndex]; RaisePropertyChanged("Notes"); RaisePropertyChanged("NoteLabel"); }
// /* Uses TempData["hoursList"] (assigned by the calling function) to create a list of objects * that each contain number of hours for Sun-Sat for each workEffort/timeCode pairing. The * list of objects is then returned to the calling function */ public List <TimesheetRow> convertHoursForTimesheetView() { WorkEffort effort = new WorkEffort(); string effortDescription = ""; List <WorkEffort> workEffortList = new List <WorkEffort>(); List <string> timeCodeList = new List <string>(); List <string> effortAndCodeConcat = new List <string>(); List <TimesheetRow> tsRowList = new List <TimesheetRow>(); //TempData["hoursList"] was assigned in viewTimesheet() before calling this method IEnumerable <Hours> hoursList = (IEnumerable <Hours>)TempData["hoursList"]; //create a list of workEffort/timeCode pairings for the pay period foreach (var item in hoursList) { timeCodeList.Add(item.description); effort = WorkEffortDB.WorkEffortList.Find(item.workEffortID); if (effort != null) { workEffortList.Add(effort); effortAndCodeConcat.Add(effort.description + "::::" + item.description); } } //remove duplicates from the list effortAndCodeConcat = effortAndCodeConcat.Distinct().ToList(); //for each unique workEffort/timeCode pairing foreach (var effortAndCode in effortAndCodeConcat) { TimesheetRow tmpTsRow = new TimesheetRow(); /* save the work effort description and time code, then remove from the front of the list. * In the process, any duplicate pairs are ignored and removed by comparing to effortAndCodeConcat */ for (int count = 0; count < 100; count++) { try { if ((effortAndCode.Contains(workEffortList.First().description)) && (effortAndCode.Contains(timeCodeList.First()))) { tmpTsRow.weID = workEffortList.First().ID; tmpTsRow.workeffort = workEffortList.First().description; tmpTsRow.timecode = timeCodeList.First(); workEffortList.RemoveAt(0); timeCodeList.RemoveAt(0); break; } else { workEffortList.RemoveAt(0); timeCodeList.RemoveAt(0); } } catch { } } //for each hours entry in the pay period foreach (var tmpVal in hoursList) { effortDescription = getWeDescription(tmpVal.workEffortID); //if the hours entry belongs to the unique workEffort/timeCode pairing if ((effortAndCode.CompareTo(effortDescription + "::::" + tmpVal.description) == 0)) { switch (tmpVal.timestamp.DayOfWeek.ToString()) { case ("Sunday"): tmpTsRow.sunHours = tmpVal; break; case ("Monday"): tmpTsRow.monHours = tmpVal; break; case ("Tuesday"): tmpTsRow.tueHours = tmpVal; break; case ("Wednesday"): tmpTsRow.wedHours = tmpVal; break; case ("Thursday"): tmpTsRow.thuHours = tmpVal; break; case ("Friday"): tmpTsRow.friHours = tmpVal; break; case ("Saturday"): tmpTsRow.satHours = tmpVal; break; default: break; } } } //Add the TimesheetRow so it will be displayed in viewTimesheet View tsRowList.Add(tmpTsRow); } return(tsRowList); }
public static double SumTotalHoursOfTimesheetRow(TimesheetRow row) { return(row.Monday + row.Tuesday + row.Wednesday + row.Thursday + row.Friday + row.Saturday + row.Saturday); }
public async Task <ActionResult <TimesheetRow> > PostTimesheetRow(TimesheetRow timesheetRow) { return(null); }
public async Task <IActionResult> PutTimesheetRow(int id, TimesheetRow timesheetRow) { return(null); }
// GET: TimesheetRows/Create/timesheetId public async Task <IActionResult> Create(int id) { TimesheetRow model = new TimesheetRow() { TimesheetId = id }; var timesheet = await _context.Timesheets.Include(t => t.Employee).FirstOrDefaultAsync(t => t.TimesheetId == id); var timesheetrows = _context.TimesheetRows.Where(t => t.TimesheetId == id); var pes = _context.ProjectEmployees.Where(pe => pe.EmployeeId == timesheet.EmployeeId); List <WorkPackage> wpl = new List <WorkPackage>(); foreach (ProjectEmployee pe in pes) { if (pe.ProjectId != null && pe.WorkPackageId != null && pe.Status == ProjectEmployee.CURRENTLY_WORKING) { bool exist = false; foreach (TimesheetRow tr in timesheetrows) { if (tr.WorkPackageId == pe.WorkPackageId) { exist = true; } } if (!exist) { var wp = await _context.WorkPackages.Include(wpp => wpp.Project).FirstOrDefaultAsync(wpp => wpp.WorkPackageId == pe.WorkPackageId); wpl.Add(wp); } } } //authorization if (timesheet.Employee.Id != _userManager.GetUserId(User)) { return(NotFound()); } //check any available wp if (wpl.Count == 0) { TempData["info2"] = "No available work package"; return(Redirect(Request.Headers["Referer"].ToString())); } var wpes = wpl .Select(s => new SelectListItem { Value = s.WorkPackageId.ToString(), Text = s.Project.Name + " --- " + s.Name }); ViewData["WorkPackageId"] = new SelectList(wpes, "Value", "Text"); // string uid = (await _userManager.GetUserAsync(User)).Id; // var listInfo = _context.ProjectEmployees // .Where(pe => pe.EmployeeId == uid // && pe.Status == ProjectEmployee.CURRENTLY_WORKING) // .Join(_context.WorkPackages, // pe => pe.ProjectId, // wp => wp.ProjectId, // (pe, wp) => new { PE = pe, WP = wp }) // .Join(_context.Projects, // i => i.PE.ProjectId, // p => p.ProjectId, // (i, p) => new { WorkPackgeInfo = i.WP, ProjectInfo = p }) // .Distinct() // .ToList(); // var list = new List<SelectListItem>(); // foreach(var info in listInfo) // { // list.Add(new SelectListItem // { // Value = info.WorkPackgeInfo.WorkPackageId.ToString(), // Text = info.ProjectInfo.Name + "---" + info.WorkPackgeInfo.Name // }); // } // ViewData["WorkPackageId"] = new SelectList(list, "Value", "Text"); //>>>>>>> origin/TEST return(View(model)); }
/// <summary> /// This will add Assigned and Favorited Issues and all codes under Timesheet Admin /// </summary> private void PopulateDefaultTimesheetRows() { mIssueTimesheetRowModels.Clear(); var getDefaultIssuesForTimesheet = DatabaseLoader.GetDefaultIssuesForTimesheet(mTimesheet.UserId); var getPreviousTimesheetReferences = DatabaseLoader.GetPreviousTimesheetReferences(mTimesheet.UserId, mTimesheet.StartDate); List<Task> tasks = new List<Task>(); tasks.Add(getDefaultIssuesForTimesheet); tasks.Add(getPreviousTimesheetReferences); Task.Factory.ContinueWhenAll(tasks.ToArray(), x => { //Add Admin Codes timesheets foreach (var adminCode in mAdminCodes) { //Created Timesheet Row based on Assigned and Favorites Issues var timesheetRow = new TimesheetRow { Timesheet = mTimesheet, TimesheetCodeId = adminCode.Id, TimesheetValues = new List<TimesheetValue>() }; //Add hours for next 7 days for (int i = 0; i < 7; i++) { TimesheetValue timesheetValue = new TimesheetValue { Date = mTimesheet.StartDate.AddDays(i), TimesheetRow = timesheetRow, Hours = 0 }; timesheetRow.TimesheetValues.Add(timesheetValue); } var timesheetRowModel = new IssueTimesheetRowModel(mView, timesheetRow, QuickIssues, mAdminCodes); mIssueTimesheetRowModels.Add(timesheetRowModel); mTimesheet.TimesheetRows.Add(timesheetRow); } foreach (var issue in getDefaultIssuesForTimesheet.Result) { AddIssueToTimesheets(issue); } //Set previous Reference Numbers if (getPreviousTimesheetReferences.Result.Any()) { foreach (var previousIsseuReference in getPreviousTimesheetReferences.Result) { var issueId = previousIsseuReference.Key; var referenceNumber = previousIsseuReference.Value; var timesheetRow = mTimesheet.TimesheetRows.FirstOrDefault(t => t.IssueId == issueId); if (timesheetRow != null) { timesheetRow.SystemReferenceNumber = referenceNumber; } } } CMS.UiFactory.StartNew(() => { mView.TelerikGrid.Rebind(); RaisePropertyChanged("IssueTimesheetRowModels"); RaisePropertyChanged("TotalHours"); RaisePropertyChanged("Week"); RaisePropertyChanged("User"); RaisePropertyChanged("LastModifiedBy"); OkButtonCommand.RaiseCanExecuteChanged(); SubmitButtonCommand.RaiseCanExecuteChanged(); AddIssueButtonCommand.RaiseCanExecuteChanged(); mView.IsBusyIndicator.IsBusy = false; }); }); }
public async Task <EmployeeTimesheet> GetTimesheetByUserID(UserDateDto userDate) { EmployeeTimesheet empSheet = null; TimesheetRow sheetRow = null; var teamId = 0; DateTime fromDate = userDate.Date.AddDays(-1); DateTime toDate = userDate.Date.AddDays(6); using (var context = new DatabaseContext()) { teamId = context.Employee.Where(x => x.BSIPLid == userDate.UserId).Select(x => x.TeamId).FirstOrDefault <int>(); var taskTeams = await context.TaskTeam.Where(x => x.TeamId == teamId).Include(x => x.Task).ToListAsync <TaskTeam>(); var taskGroup = (from t in taskTeams select new EmployeeTask { Id = t.TaskId, Name = t.Task.Name }).ToList(); var tsheet1 = await(context.TimeSheet.Include(x => x.Task).Where(t => t.EmployeeId == userDate.UserId && t.Date >= fromDate && t.Date <= toDate) .ToListAsync()); decimal workHours = 0; empSheet = new EmployeeTimesheet() { EmployeeId = userDate.UserId, TeamId = teamId, TimesheetRows = new List <TimesheetRow>() }; //select max data rom tsheets DateTime maxdate = new DateTime(); if (tsheet1.Count > 0) { maxdate = tsheet1[0].Date; } foreach (Timesheet t in tsheet1) { if (t.Date > maxdate) { maxdate = t.Date; } } //Prepare Colmns and Rows //Group by TaskIds //Loop through Tasks int ctr = 1; string taskName = string.Empty; foreach (var task in taskGroup) { List <TimesheetColumn> cols = null; //Loop through days //get the actual days with dates cols = new List <TimesheetColumn>(); var newDate = new DateTime(userDate.Date.Year, userDate.Date.Month, userDate.Date.Day, 0, 0, 0, DateTimeKind.Utc); while (newDate.Date <= toDate.Date && newDate.Date <= maxdate.Date) { if (newDate.Date >= fromDate.Date) { workHours = (tsheet1 == null || tsheet1.Count == 0) ? 0 : tsheet1.Where(x => DateTime.Compare(x.Date.Date, newDate.Date) == 0 && x.TaskId == task.Id).FirstOrDefault().Hour; var timesheetCol = new TimesheetColumn() { id = 1, taskId = task.Id, employeeId = userDate.UserId, //get task name date = newDate, hours = workHours //approved = }; cols.Add(timesheetCol); newDate = newDate.AddDays(1); } } taskName = (tsheet1 == null || tsheet1.Count == 0) ? task.Name : tsheet1.Where(x => x.TaskId == task.Id).FirstOrDefault().Task.Name; sheetRow = new TimesheetRow() { id = ctr, taskId = task.Id, taskName = taskName, timesheetColumns = cols, totalHours = 0 }; empSheet.TimesheetRows.Add(sheetRow); ctr++; } } return(empSheet); }
public async Task <IActionResult> Create([Bind("TimesheetId,WeekEnding,WeekNumber,FlexTime,Status,EmployeeId,EmployeePayId,SignatureId")] Timesheet timesheet) { if (ModelState.IsValid) { //default status is not submitted and not approved timesheet.Status = Timesheet.NOT_SUBMITTED_NOT_APPROVED; //calculate week number timesheet.WeekNumber = Utility.GetWeekNumberByDate(timesheet.WeekEnding); //get user's employee id timesheet.EmployeeId = _userManager.GetUserId(HttpContext.User); //select the valid employee pay var emppay = await _context.EmployeePays.FirstOrDefaultAsync(ep => ep.EmployeeId == timesheet.EmployeeId && ep.Status == EmployeePay.VALID); timesheet.EmployeePay = emppay; timesheet.EmployeePayId = emppay.EmployeePayId; //select valid var sign = await _context.Signatures.FirstOrDefaultAsync(s => s.EmployeeId == timesheet.EmployeeId && s.Status == Signature.VALID); if (sign == null) { TempData["Link"] = "Signature"; TempData["begin"] = "Fill in a "; TempData["end"] = " pass phrase in your profile first"; return(Redirect(Request.Headers["Referer"].ToString())); } timesheet.Signature = sign; timesheet.SignatureId = sign.SignatureId; timesheet.FlexTime = 0; _context.Add(timesheet); //add HR reserved rows var wp1 = _context.WorkPackages.FirstOrDefault(wp => wp.WorkPackageCode == "SICK"); TimesheetRow tr1 = new TimesheetRow() { Timesheet = timesheet, WorkPackage = wp1 }; _context.Add(tr1); var wp2 = _context.WorkPackages.FirstOrDefault(wp => wp.WorkPackageCode == "VACN"); TimesheetRow tr2 = new TimesheetRow() { Timesheet = timesheet, WorkPackage = wp2 }; _context.Add(tr2); var wp3 = _context.WorkPackages.FirstOrDefault(wp => wp.WorkPackageCode == "SHOL"); TimesheetRow tr3 = new TimesheetRow() { Timesheet = timesheet, WorkPackage = wp3 }; _context.Add(tr3); var wp4 = _context.WorkPackages.FirstOrDefault(wp => wp.WorkPackageCode == "FLEX"); TimesheetRow tr4 = new TimesheetRow() { Timesheet = timesheet, WorkPackage = wp4 }; _context.Add(tr4); await _context.SaveChangesAsync(); return(RedirectToAction("Edit", new { id = timesheet.TimesheetId })); } return(View(timesheet)); }