/// <summary> /// Builds report /// </summary> /// <param name="table"><see cref="Table"/> entity</param> /// <returns><see cref="Report"/> instance</returns> public Report BuildReport(Table table) { if (table == null) throw new ArgumentNullException("table"); if (table.Records.IsEmpty()) throw new ArgumentException("table.records"); var report = new Report(); report.Year = table.Year; report.Month = table.Month; foreach (var groupedRecords in table.Records.GroupBy(x => x.Employee)) { var employeeLine = new Report.EmployeeLine(); employeeLine.FullName = groupedRecords.Key.LastName + " " + groupedRecords.Key.FirstName; employeeLine.Post = groupedRecords.Key.Post.ToString(); employeeLine.FirstWeek.Records = groupedRecords.Take(RECORDS_COUNT_OF_WEEK); employeeLine.SecondWeek.Records = groupedRecords.Skip(RECORDS_COUNT_OF_WEEK).Take(groupedRecords.Count() - RECORDS_COUNT_OF_WEEK); CalcWeek(employeeLine.FirstWeek); CalcWeek(employeeLine.SecondWeek); CalcTotal(employeeLine); report.EmployeeLines.Add(employeeLine); } return report; }
/// <summary> /// Adds a new table /// </summary> /// <param name="table">Table entity</param> public void AddTable(Table table) { if (table == null) throw new ArgumentNullException("table"); _tableRepository.Add(table); _tableRecordRepository.AddRange(table.Records); }
/// <summary> /// Removes the table /// </summary> /// <param name="table">Table entity</param> public void Remove(Table table) { if (table == null) throw new ArgumentNullException("table"); _tableRecordRepository.DeleteRange(table.Records); _tableRepository.Delete(table); }