public async Task Create(CreateProjectHourDto projecthour) { //var student = await _studentRepository.FindById(projecthour.Student); var student = await _studentRepository.FirstOrDefault(student => student.Account == projecthour.Student); var section = await _sectionRepository.FirstOrDefault(section => section.Id == projecthour.Section); var project = await _projectRepository.FirstOrDefault(project => project.Id == projecthour.Project); var projecthourInfo = new ProjectHour { Hours = projecthour.Hours, TableState = projecthour.TableState, Student = student, StudentId = student.Id, Section = section, SectionId = section.Id, Project = project, ProjectId = project.Id }; await _projecthourRepository.Add(projecthourInfo); }
private IEnumerable <ProjectHour> GetTableData(IEnumerable <VaultKey> vaultGuids, VaultServer server, DateTime?beginDate = null, DateTime?deadline = null, int showingType = 1) { var vaultInfo = _workHourService.GetHourInfo(vaultGuids, server, beginDate, deadline); var projHourList = new List <ProjectHour>(); foreach (ProjectHourInfo pInfo in vaultInfo) { var dbTotalBudget = pInfo.TotalBudget; var dbPersonalBudgets = pInfo.PersonalBudgets; var dbHourLogs = pInfo.HourLogs; if (beginDate == null) { beginDate = dbTotalBudget.BeginDate; } if (deadline == null) { deadline = dbTotalBudget.Deadline; } var projHour = new ProjectHour() { ProjName = dbTotalBudget.ProjectName //,BudgetHours = dbTotalBudget.TotalHours , TimeSpans = new List <string>() }; double tHoursBuget = 0.0; double tHoursActual = 0.0; var userList = new List <UserHour>(); var timeSpans = DateTimeTool.GetTimespanList(beginDate.GetValueOrDefault(), deadline.GetValueOrDefault(), showingType).ToList(); foreach (TimeArea span in timeSpans) { projHour.TimeSpans.Add(span.Title); } foreach (PersonalBudget b in dbPersonalBudgets) { var userHour = new UserHour { UserName = b.MemberName }; var uLogs = GetUserLogs(b.VaultGuid, b.UserID, dbHourLogs); var bHours = new List <UnitHour>(); var aHours = new List <UnitHour>(); var mBudgets = Convert2MonthBudgets(b.HoursDetail); foreach (TimeArea t in timeSpans) { var bUnit = GetBudgetUnit(t, mBudgets); var aUnit = GetActualUnit(t, uLogs); bHours.Add(bUnit); aHours.Add(aUnit); } userHour.BudgetHours = bHours; userHour.ActualHours = aHours; tHoursBuget += userHour.BudgetTotal; tHoursActual += userHour.ActualTotal; userList.Add(userHour); } projHour.UserList = userList; projHour.BudgetHours = tHoursBuget; projHour.ActualHours = tHoursActual; projHourList.Add(projHour); } return(projHourList); }