private HttpResponseMessage ProcessExistingAbsenceRecord(HttpRequestMessage request, AbsenceDTO cqDto, int contactId, string key, int AbsenceId, int userId) { var ur = new AbsenceRepository(); var user = new Absence(); user = ur.GetById(contactId); var validationErrors = GetValidationErrors(ur, user, cqDto, AbsenceId, userId); if (validationErrors.Any()) { return(ProcessValidationErrors(request, validationErrors, key)); } //if (cqDto.Remove != null && int.Parse(cqDto.Remove) == 1) //{ // ur.Delete(user); //} else { ur.Save(user); } UpdateDepartmentTotalAbsence(cqDto); cqDto.Key = key; return(request.CreateResponse(HttpStatusCode.Accepted, cqDto)); }
private HttpResponseMessage ProcessNewAbsenceRecord(HttpRequestMessage request, AbsenceDTO uDto, string key, int AbsenceId, int userId) { var ur = new AbsenceRepository(); var user = new Absence(); var validationErrors = GetValidationErrors(ur, user, uDto, AbsenceId, userId); if (validationErrors.Any()) { return(ProcessValidationErrors(request, validationErrors, key)); } user = ur.Save(user); UpdateDepartmentTotalAbsence(uDto); uDto.Key = key; uDto.AbsenceID = user.AbsenceID.ToString(); var response = request.CreateResponse(HttpStatusCode.Created, uDto); response.Headers.Location = new Uri(Url.Link("Default", new { id = user.AbsenceID })); return(response); }
public UnitOfWork(ApplicationDbContext context) { _context = context; TodoItem = new TodoItemRepository(context); TodoList = new TodoListItemRepository(context); AbsenceGate = new AbsenceRepository(context); TodoItemCategoryGate = new TodoCategoryRepository(context); User = new UserRepository(context); CompanyGate = new CompanyRepository(context); }
private void UpdateDepartmentTotalAbsence(AbsenceDTO uDto) { var pr = new DepartmentTotalRepository(); var prod = new DepartmentTotal(); var prodexists = pr.GetByDateAndDepartment(DateTime.Parse(uDto.AbsenceDate), int.Parse(uDto.DepartmentID)); int wb = 0; wb = uDto.RegEmpLate == null ? 0 : int.Parse(uDto.RegEmpLate); wb += uDto.RegEmpLeftEarly == null ? 0 : int.Parse(uDto.RegEmpLeftEarly); wb += uDto.RegEmpOut == null ? 0 : int.Parse(uDto.RegEmpOut); wb += uDto.TempEmpLate == null ? 0 : int.Parse(uDto.TempEmpLate); wb += uDto.TempEmpLeftEarly == null ? 0 : int.Parse(uDto.TempEmpLeftEarly); wb += uDto.TempEmpOut == null ? 0 : int.Parse(uDto.TempEmpOut); wb += uDto.InmateLeftEarly == null ? 0 : int.Parse(uDto.InmateLeftEarly); wb += uDto.InmateOut == null ? 0 : int.Parse(uDto.InmateOut); wb += uDto.EmployeesOnVacation == null ? 0 : int.Parse(uDto.EmployeesOnVacation); if (prodexists == null) { prod.DepartmentID = int.Parse(uDto.DepartmentID); prod.DTDate = DateTime.Parse(uDto.AbsenceDate); prod.Absences = wb; pr.Save(prod); } else { prod = prodexists; var wbr = new AbsenceRepository(); List <Absence> wbl = wbr.GetByDateAndDepartment(DateTime.Parse(uDto.AbsenceDate), int.Parse(uDto.DepartmentID)); wb = wbl.Where(x => x.RegEmpLate != null).Sum(x => x.RegEmpLate).Value; wb += wbl.Where(x => x.RegEmpLeftEarly != null).Sum(x => x.RegEmpLeftEarly).Value; wb += wbl.Where(x => x.RegEmpOut != null).Sum(x => x.RegEmpOut).Value; wb += wbl.Where(x => x.TempEmpLate != null).Sum(x => x.TempEmpLate).Value; wb += wbl.Where(x => x.TempEmpLeftEarly != null).Sum(x => x.TempEmpLeftEarly).Value; wb += wbl.Where(x => x.TempEmpOut != null).Sum(x => x.TempEmpOut).Value; wb += wbl.Where(x => x.InmateLeftEarly != null).Sum(x => x.InmateLeftEarly).Value; wb += wbl.Where(x => x.InmateOut != null).Sum(x => x.InmateOut).Value; wb += wbl.Where(x => x.EmployeesOnVacation != null).Sum(x => x.EmployeesOnVacation).Value; if (wb != 0) { prod.Absences = wb; } pr.Save(prod); } }
public async Task AddAbsenceToDatabase() { IFixture fixture = new Fixture(); var databaseName = fixture.Create <string>(); var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName).Options; using (var context = new ApplicationDbContext(options)) { var repository = new AbsenceRepository(context); await repository.CreateAsync(testDoctorAbsence, CancellationToken.None); } using (var context = new ApplicationDbContext(options)) { context.DoctorsAbsences.Count().Should().Be(1); } }
public async Task ReturnAbsenceFromDatabase() { IFixture fixture = new Fixture(); var databaseName = fixture.Create <string>(); var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName).Options; using (var context = new ApplicationDbContext(options)) { var repository = new AbsenceRepository(context); await repository.CreateAsync(testDoctorAbsence, CancellationToken.None); } using (var context = new ApplicationDbContext(options)) { var repository = new AbsenceRepository(context); var ret = await repository.GetAsync(testDoctorAbsence.Doctor.Name, CancellationToken.None); ret.AbsenceDate.Should().Be(testDoctorAbsence.AbsenceDate); ret.AbsenceDescription.Should().Be(testDoctorAbsence.AbsenceDescription); } }
static void Main(string[] args) { if (args.Any()) { string fileName = string.Empty; string date = string.Empty; List <string> grades = new List <string>() { "pk", "k", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }; // There aren't nearly this many blocks in a day, but this future proofs it. It can't pull absences for blocks that dont exist List <int> softBlocks = new List <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; List <int> hardBlocks = new List <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; bool allSchools = false; bool onlyPeriodAttendance = false; bool onlyDailyAttendance = false; List <string> options = new List <string>(); List <string> selectedSchoolIDs = new List <string>(); foreach (string argument in args) { if (argument.ToLower().StartsWith("/schoolid:")) { foreach (string enteredID in argument.Substring(10, argument.Length - 10).Split(new char[] { ';', ',' })) { if (!string.IsNullOrEmpty(enteredID)) { selectedSchoolIDs.Add(enteredID); } } } else if (argument.ToLower().StartsWith("/filename:")) { fileName = argument.Substring(10, argument.Length - 10); } else if (argument.ToLower().StartsWith("/allschools")) { options.Add("allschools"); allSchools = true; } else if (argument.ToLower().StartsWith("/justperiodattendance")) { options.Add("justperiodattendance"); onlyPeriodAttendance = true; } else if (argument.ToLower().StartsWith("/justdailyattendance")) { options.Add("justdailyattendance"); onlyDailyAttendance = true; } else if (argument.ToLower().StartsWith("/date:")) { date = argument.Substring(6, argument.Length - 6); if (date.ToLower().Equals("today")) { date = DateTime.Today.ToString(); } if (date.ToLower().Equals("yesterday")) { date = Helpers.GetPreviousBusinessDay(DateTime.Today).ToString(); } if (date.ToLower().Equals("now")) { date = DateTime.Now.ToString(); } } else if (argument.ToLower().StartsWith("/logfilename:")) { Log.LogFileName = argument.Substring(13, argument.Length - 13); } else if (argument.ToLower().StartsWith("/blocks:")) { string blob = argument.Substring(8, argument.Length - 8); char[] splitChars = { ',', ';' }; List <string> unparsedBlocks = blob.Split(splitChars).ToList(); softBlocks.Clear(); foreach (string s in unparsedBlocks) { if (!string.IsNullOrEmpty(s)) { int parsed = 0; if (int.TryParse(s, out parsed)) { if (parsed > 0) { softBlocks.Add(parsed); } } } } } else if (argument.ToLower().StartsWith("/hardblocks:")) { string blob = argument.Substring(12, argument.Length - 12); char[] splitChars = { ',', ';' }; List <string> unparsedBlocks = blob.Split(splitChars).ToList(); hardBlocks.Clear(); foreach (string s in unparsedBlocks) { if (!string.IsNullOrEmpty(s)) { int parsed = 0; if (int.TryParse(s, out parsed)) { if (parsed > 0) { hardBlocks.Add(parsed); } } } } } else if (argument.ToLower().StartsWith("/grades:")) { string gradesRaw = argument.Substring(8, argument.Length - 8).Trim('\"').Trim(); grades = new List <string>(); Log.Info("Limiting student selection to specific grades"); foreach (string ss in gradesRaw.Split(',')) { if (!string.IsNullOrEmpty(ss)) { grades.Add(ss.ToLower()); Log.Info(" Adding grade \"" + ss + "\""); } } } } if (((selectedSchoolIDs.Count <= 0) && (!allSchools)) || (string.IsNullOrEmpty(fileName)) || (string.IsNullOrEmpty(date))) { SendSyntax(); } else { if (Config.ConfigFileExists()) { DateTime parsedDate = Helpers.ParseDate(date); try { Log.ToLog("----------------------------------------------------------------"); Log.Info("Started: " + DateTime.Now); Log.Info("Date: " + date); Log.Info("Output: " + fileName); Log.Info("Grades: " + grades.ToCommaSeparatedString()); Log.Info("Soft Blocks: " + softBlocks.ToCommaSeparatedString()); Log.Info("Hard Blocks: " + hardBlocks.ToCommaSeparatedString()); Log.Info("Options: " + options.ToCommaSeparatedString()); Log.Info("Schools: " + (allSchools ? "ALL" : selectedSchoolIDs.ToCommaSeparatedString())); Dictionary <Student, List <Absence> > studentsWithAbsences = new Dictionary <Student, List <Absence> >(); List <School> selectedSchools = new List <School>(); AbsenceRepository absenceRepo = new AbsenceRepository(); StudentRepository studentRepo = new StudentRepository(); using ( SqlConnection connection = new SqlConnection(Config.dbConnectionString_SchoolLogic)) { SchoolRepository schoolRepo = new SchoolRepository(connection); if (allSchools) { selectedSchools = schoolRepo.GetAll(); } else { selectedSchools = schoolRepo.Get(selectedSchoolIDs); } Log.Info("Loading students"); foreach (School school in selectedSchools) { List <Student> schoolStudents = studentRepo.LoadForSchool(connection, school, parsedDate).Where(s => grades.Contains(s.Grade.ToLower())).ToList(); if (onlyDailyAttendance && !onlyPeriodAttendance) { Log.Info("Only using daily attendance students"); schoolStudents = schoolStudents.Where(s => s.IsTrackDaily == true).ToList(); } if (onlyPeriodAttendance && !onlyDailyAttendance) { Log.Info("Only using period attendance students"); schoolStudents = schoolStudents.Where(s => s.IsTrackDaily == false).ToList(); } Log.Info("Loaded " + schoolStudents.Count + " students for school " + school.Name); int schoolAbsenceCount = 0; // Load student absences foreach (Student student in schoolStudents) { List <Absence> studentAbsences = absenceRepo.LoadAbsencesFor(connection, school, student, parsedDate, parsedDate.AddHours(23.5)).Where(abs => hardBlocks.Contains(abs.BlockNumber)).ToList(); if (studentAbsences.Count > 0) { studentsWithAbsences.Add(student, studentAbsences); } schoolAbsenceCount += studentAbsences.Count; } Log.Info(" Loaded " + schoolAbsenceCount + " absences for school " + school.Name); } } Log.Info("Creating CSV data"); MemoryStream csvContents = AbsenceCSV.GenerateCSV(studentsWithAbsences, softBlocks); Log.Info("Saving CSV file (" + fileName + ")"); if (FileHelpers.FileExists(fileName)) { FileHelpers.DeleteFile(fileName); } FileHelpers.SaveFile(csvContents, fileName); Log.Info("Done!"); } catch (Exception ex) { Log.Error(ex.Message); } } else { Log.Error("Configuration file not found"); Log.Info("Creating new config file (" + Config.configFileName + ")..."); Log.Info("Please edit the file and try again"); Config.CreateNewConfigFile(); } } } else { // If any argument is missing, send the syntax SendSyntax(); } }
public RefereeController(AbsenceRepository abscenceRepository, GameRepository gameRepository, CityRepository cityRepository) { _absenceRepository = abscenceRepository; _gameRepository = gameRepository; _cityRepository = cityRepository; }
internal HttpResponseMessage AbsenceDates(HttpRequestMessage request, AbsenceDTO cqDTO) { string key; var aur = new AppUserRepository(); var companyId = 0; var userId = aur.ValidateUser(cqDTO.Key, out key, ref companyId); if (userId > 0) { var ur = new AbsenceRepository(); var u = new Absence(); if (cqDTO.AbsenceDate != null) { cqDTO.Start_AbsenceDate = DateTime.Parse(cqDTO.AbsenceDate).ToString(); cqDTO.End_AbsenceDate = DateTime.Parse(cqDTO.AbsenceDate).AddDays(1).ToString(); } else { int sm = int.Parse(cqDTO.StartDateMonth); if (sm == 1) { cqDTO.Start_AbsenceDate = DateTime.Parse("12/23/" + (int.Parse(cqDTO.StartDateYear) - 1).ToString()).ToString(); cqDTO.End_AbsenceDate = DateTime.Parse("2/14/" + cqDTO.StartDateYear).ToString(); } else if (sm == 12) { cqDTO.Start_AbsenceDate = DateTime.Parse("11/23/" + cqDTO.StartDateYear).ToString(); cqDTO.End_AbsenceDate = DateTime.Parse("1/14/" + (int.Parse(cqDTO.StartDateYear) + 1).ToString()).ToString(); } else { cqDTO.Start_AbsenceDate = DateTime.Parse((int.Parse(cqDTO.StartDateMonth) - 1).ToString() + "/23/" + cqDTO.StartDateYear).ToString(); cqDTO.End_AbsenceDate = DateTime.Parse((int.Parse(cqDTO.StartDateMonth) + 1).ToString() + "/14/" + cqDTO.StartDateYear).ToString(); } cqDTO.StartDateMonth = null; cqDTO.StartDateYear = null; } var predicate = ur.GetPredicate(cqDTO, u, companyId); var data = ur.GetByPredicate(predicate); var col = new Collection <Dictionary <string, string> >(); data = data.GroupBy(x => x.AbsenceDate).Select(x => x.First()).OrderBy(x => x.AbsenceDate).ToList(); foreach (var item in data) { var dic = new Dictionary <string, string>(); dic.Add("AbsenceDate", item.AbsenceDate.ToShortDateString()); col.Add(dic); var ufdic = new Dictionary <string, string>(); } var retVal = new GenericDTO { Key = key, ReturnData = col }; return(Request.CreateResponse(HttpStatusCode.OK, retVal)); } var message = "validation failed"; return(request.CreateResponse(HttpStatusCode.NotFound, message)); }
private List <DbValidationError> GetValidationErrors(AbsenceRepository pr, Absence contact, AbsenceDTO cqDto, int YieldID, int userId) { contact.ProcessRecord(cqDto); return(pr.Validate(contact)); }
internal HttpResponseMessage AbsenceDates(HttpRequestMessage request, AbsenceDTO cqDTO) { string key; var aur = new AppUserRepository(); var companyId = 0; var userId = aur.ValidateUser(cqDTO.Key, out key, ref companyId); if (userId > 0) { var ur = new AbsenceRepository(); var u = new Absence(); if (cqDTO.AbsenceDate != null) { cqDTO.Start_AbsenceDate = DateTime.Parse(cqDTO.AbsenceDate).ToString(); cqDTO.End_AbsenceDate = DateTime.Parse(cqDTO.AbsenceDate).AddDays(1).ToString(); } else { int sm = int.Parse(cqDTO.StartDateMonth); if (sm == 1) { cqDTO.Start_AbsenceDate = DateTime.Parse("12/23/" + (int.Parse(cqDTO.StartDateYear) - 1).ToString()).ToString(); cqDTO.End_AbsenceDate = DateTime.Parse("2/14/" + cqDTO.StartDateYear).ToString(); } else if (sm == 12) { cqDTO.Start_AbsenceDate = DateTime.Parse("11/23/" + cqDTO.StartDateYear).ToString(); cqDTO.End_AbsenceDate = DateTime.Parse("1/14/" + (int.Parse(cqDTO.StartDateYear) + 1).ToString()).ToString(); } else { cqDTO.Start_AbsenceDate = DateTime.Parse((int.Parse(cqDTO.StartDateMonth) - 1).ToString() + "/23/" + cqDTO.StartDateYear).ToString(); cqDTO.End_AbsenceDate = DateTime.Parse((int.Parse(cqDTO.StartDateMonth) + 1).ToString() + "/14/" + cqDTO.StartDateYear).ToString(); } cqDTO.StartDateMonth = null; cqDTO.StartDateYear = null; } var predicate = ur.GetPredicate(cqDTO, u, companyId); var data = ur.GetByPredicate(predicate); var col = new Collection<Dictionary<string, string>>(); data = data.GroupBy(x => x.AbsenceDate).Select(x => x.First()).OrderBy(x => x.AbsenceDate).ToList(); foreach (var item in data) { var dic = new Dictionary<string, string>(); dic.Add("AbsenceDate", item.AbsenceDate.ToShortDateString()); col.Add(dic); var ufdic = new Dictionary<string, string>(); } var retVal = new GenericDTO { Key = key, ReturnData = col }; return Request.CreateResponse(HttpStatusCode.OK, retVal); } var message = "validation failed"; return request.CreateResponse(HttpStatusCode.NotFound, message); }
private void UpdateDepartmentTotalAbsence(AbsenceDTO uDto) { var pr = new DepartmentTotalRepository(); var prod = new DepartmentTotal(); var prodexists = pr.GetByDateAndDepartment(DateTime.Parse(uDto.AbsenceDate), int.Parse(uDto.DepartmentID)); int wb = 0; wb = uDto.RegEmpLate == null ? 0 : int.Parse(uDto.RegEmpLate); wb += uDto.RegEmpLeftEarly == null ? 0 : int.Parse(uDto.RegEmpLeftEarly); wb += uDto.RegEmpOut == null ? 0 : int.Parse(uDto.RegEmpOut); wb += uDto.TempEmpLate == null ? 0 : int.Parse(uDto.TempEmpLate); wb += uDto.TempEmpLeftEarly == null ? 0 : int.Parse(uDto.TempEmpLeftEarly); wb += uDto.TempEmpOut == null ? 0 : int.Parse(uDto.TempEmpOut); wb += uDto.InmateLeftEarly == null ? 0 : int.Parse(uDto.InmateLeftEarly); wb += uDto.InmateOut == null ? 0 : int.Parse(uDto.InmateOut); wb += uDto.EmployeesOnVacation == null ? 0 : int.Parse(uDto.EmployeesOnVacation); if (prodexists == null) { prod.DepartmentID = int.Parse(uDto.DepartmentID); prod.DTDate = DateTime.Parse(uDto.AbsenceDate); prod.Absences = wb; pr.Save(prod); } else { prod = prodexists; var wbr = new AbsenceRepository(); List<Absence> wbl = wbr.GetByDateAndDepartment(DateTime.Parse(uDto.AbsenceDate), int.Parse(uDto.DepartmentID)); wb = wbl.Where(x => x.RegEmpLate != null).Sum(x => x.RegEmpLate).Value; wb += wbl.Where(x => x.RegEmpLeftEarly != null).Sum(x => x.RegEmpLeftEarly).Value; wb += wbl.Where(x => x.RegEmpOut != null).Sum(x => x.RegEmpOut).Value; wb += wbl.Where(x => x.TempEmpLate != null).Sum(x => x.TempEmpLate).Value; wb += wbl.Where(x => x.TempEmpLeftEarly != null).Sum(x => x.TempEmpLeftEarly).Value; wb += wbl.Where(x => x.TempEmpOut != null).Sum(x => x.TempEmpOut).Value; wb += wbl.Where(x => x.InmateLeftEarly != null).Sum(x => x.InmateLeftEarly).Value; wb += wbl.Where(x => x.InmateOut != null).Sum(x => x.InmateOut).Value; wb += wbl.Where(x => x.EmployeesOnVacation != null).Sum(x => x.EmployeesOnVacation).Value; if (wb != 0) { prod.Absences = wb; } pr.Save(prod); } }
private HttpResponseMessage ProcessNewAbsenceRecord(HttpRequestMessage request, AbsenceDTO uDto, string key, int AbsenceId, int userId) { var ur = new AbsenceRepository(); var user = new Absence(); var validationErrors = GetValidationErrors(ur, user, uDto, AbsenceId, userId); if (validationErrors.Any()) { return ProcessValidationErrors(request, validationErrors, key); } user = ur.Save(user); UpdateDepartmentTotalAbsence(uDto); uDto.Key = key; uDto.AbsenceID = user.AbsenceID.ToString(); var response = request.CreateResponse(HttpStatusCode.Created, uDto); response.Headers.Location = new Uri(Url.Link("Default", new { id = user.AbsenceID })); return response; }
private HttpResponseMessage ProcessExistingAbsenceRecord(HttpRequestMessage request, AbsenceDTO cqDto, int contactId, string key, int AbsenceId, int userId) { var ur = new AbsenceRepository(); var user = new Absence(); user = ur.GetById(contactId); var validationErrors = GetValidationErrors(ur, user, cqDto, AbsenceId, userId); if (validationErrors.Any()) { return ProcessValidationErrors(request, validationErrors, key); } //if (cqDto.Remove != null && int.Parse(cqDto.Remove) == 1) //{ // ur.Delete(user); //} else { ur.Save(user); } UpdateDepartmentTotalAbsence(cqDto); cqDto.Key = key; return request.CreateResponse(HttpStatusCode.Accepted, cqDto); }
private List<DbValidationError> GetValidationErrors(AbsenceRepository pr, Absence contact, AbsenceDTO cqDto, int YieldID, int userId) { contact.ProcessRecord(cqDto); return pr.Validate(contact); }
public HttpResponseMessage EmailDailyReport() { //Update Shift Weights List<ShiftWeight> shiftResults = new List<ShiftWeight>(); //SGApp.DTOs.GenericDTO dto = new GenericDTO(); SGApp.DTOs.GenericDTO dto = new GenericDTO(); var dic = Request.GetQueryNameValuePairs().ToDictionary(x => x.Key, x => x.Value, StringComparer.OrdinalIgnoreCase); var sDate = DateTime.ParseExact(dic.First().Value, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture).Date; var eDate = DateTime.ParseExact(dic.Last().Value, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture).Date; dto.StartDate = sDate; dto.EndDate = eDate; //dto.StartDate = DateTime.Now.AddDays(-1).Date; //dto.EndDate = DateTime.Now.Date; //dto.StartDate = DateTime.Now.AddDays(1).Date; //dto.EndDate = DateTime.Now.AddDays(2).Date; var client = new HttpClient { //BaseAddress = new Uri("http://323-booth-svr2:3030/") //BaseAddress = new Uri("http://64.139.95.243:7846/") BaseAddress = new Uri("http://64.139.95.243:7846/") //BaseAddress = new Uri(baseAddress) }; try { var response = client.PostAsJsonAsync("api/Remote/GetDailyProductionTotal", dto).Result; response.EnsureSuccessStatusCode(); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); //Sampling[] samplingResultsArray = json_serializer.Deserialize<Sampling[]>(response.Content.ReadAsStringAsync().Result); // new List<Sampling>(); //Sampling[] samplingResultsArray = response.Content.ReadAsAsync<Sampling[]>().Result; //samplingResults = samplingResultsArray.ToList(); //JavaScriptSerializer json_serializer = new JavaScriptSerializer(); //Object[] samplingResultsArray = json_serializer.Deserialize<Sampling[]>(Constants.testdata); //string teststuff = "[{\"station\":10,\"nominal\":34038.25,\"weight\":35469.6},{\"station\":12,\"nominal\":7950.0,\"weight\":8062.02},{\"station\":13,\"nominal\":3165.0,\"weight\":3213.56},{\"station\":14,\"nominal\":3920.0,\"weight\":3990.14},{\"station\":15,\"nominal\":8342.0,\"weight\":8987.8},{\"station\":16,\"nominal\":10580.0,\"weight\":10862.35}]"; //ShiftWeight[] samplingResultsArray = json_serializer.Deserialize<ShiftWeight[]>(Constants.testprod); ShiftWeight[] samplingResultsArray = json_serializer.Deserialize<ShiftWeight[]>(response.Content.ReadAsStringAsync().Result); shiftResults = samplingResultsArray.ToList(); //shiftResults = shiftResults.GroupBy(x => x.farmPond).Select(group => group.First()).ToList(); //var result = response.Content.ReadAsStringAsync().Result; //return Request.CreateResponse(HttpStatusCode.OK, result); } catch (Exception e) { throw new HttpException("Error occurred: " + e.Message); } List<string> iqfstations = new List<string>(); iqfstations.Add("9"); iqfstations.Add("10"); var IQFweight = shiftResults.Where(x => iqfstations.Contains(x.Station)).Sum(x => decimal.Parse(x.Nominal)).ToString(); var BaggerWeightRecord = shiftResults.Where(x => x.Station == "7").FirstOrDefault(); var BaggerWeight = BaggerWeightRecord != null ? BaggerWeightRecord.Nominal : "0"; List<string> stations = new List<string>(); stations.Add("8"); stations.Add("2"); stations.Add("4"); stations.Add("3"); var FreshWeight = shiftResults.Where(x => stations.Contains(x.Station)).Sum(x => decimal.Parse(x.Nominal)).ToString(); var reportdate = DateTime.Now; //reportdate = DateTime.Parse(DateTime.Now.AddDays(-1).ToShortDateString()); reportdate = dto.StartDate; //dto.StartDate = DateTime.Now.AddDays(-1).Date; //reportdate = DateTime.Parse(DateTime.Now.AddDays(11).ToShortDateString()); var ptr = new ProductionTotalRepository(); var dtr = new DepartmentTotalRepository(); var wbr = new WeighBackRepository(); var ar = new AbsenceRepository(); var dr = new DownTimeRepository(); var fsrr = new FilletScaleReadingRepository(); var iqfw = dtr.GetByDateAndDepartment(reportdate, 5); if (iqfw != null && IQFweight != null) { iqfw.ShiftWeight = decimal.Parse(IQFweight); dtr.Save(iqfw); } else { iqfw = new DepartmentTotal(); if (IQFweight != null) { iqfw.ShiftWeight = decimal.Parse(IQFweight); } iqfw.DepartmentID = 5; iqfw.DTDate = reportdate; dtr.Save(iqfw); } var freshw = dtr.GetByDateAndDepartment(reportdate, 4); if (freshw != null && FreshWeight != null) { freshw.ShiftWeight = decimal.Parse(FreshWeight); dtr.Save(freshw); } else { freshw = new DepartmentTotal(); freshw.DepartmentID = 4; freshw.DTDate = reportdate; if (FreshWeight != null) { freshw.ShiftWeight = decimal.Parse(FreshWeight); } dtr.Save(freshw); } var bagw = dtr.GetByDateAndDepartment(reportdate, 6); if (bagw != null && BaggerWeight != null) { bagw.ShiftWeight = decimal.Parse(BaggerWeight); dtr.Save(bagw); } else { bagw = new DepartmentTotal(); bagw.DepartmentID = 6; bagw.DTDate = reportdate; if (BaggerWeight != null) { bagw.ShiftWeight = decimal.Parse(BaggerWeight); } dtr.Save(bagw); } List<Sampling> samplingResults = new List<Sampling>(); try { var response = client.PostAsJsonAsync("api/Remote/GetKeithsData", dto).Result; response.EnsureSuccessStatusCode(); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); //Sampling[] samplingResultsArray = json_serializer.Deserialize<Sampling[]>(response.Content.ReadAsStringAsync().Result); // new List<Sampling>(); //Sampling[] samplingResultsArray = response.Content.ReadAsAsync<Sampling[]>().Result; //samplingResults = samplingResultsArray.ToList(); //JavaScriptSerializer json_serializer = new JavaScriptSerializer(); //Sampling[] samplingResultsArray = json_serializer.Deserialize<Sampling[]>(Constants.testdata); Sampling[] samplingResultsArray = json_serializer.Deserialize<Sampling[]>(response.Content.ReadAsStringAsync().Result); samplingResults = samplingResultsArray.ToList(); var samplingResultsData = samplingResults.GroupBy(x => new { x.farm, x.pond, x.farmPond, x.rangeName }) .Select(group => new { Key = group.Key, Weight = group.Sum(s => decimal.Parse(s.weight)), Count = group.Count() }).ToList(); //var result = response.Content.ReadAsStringAsync().Result; //return Request.CreateResponse(HttpStatusCode.OK, result); List<Sampling> samplingReport = new List<Sampling>(samplingResultsData.Capacity); foreach (var rec in samplingResultsData) { Sampling fee2 = new Sampling(); fee2.farm = rec.Key.farm; fee2.pond = rec.Key.pond; fee2.farmPond = rec.Key.farmPond; fee2.rangeName = rec.Key.rangeName; fee2.weight = rec.Weight.ToString(); fee2.count = rec.Count.ToString(); samplingReport.Add(fee2); } samplingResults = samplingReport; } catch (Exception e) { throw new HttpException("Error occurred: " + e.Message); } var pts = ptr.GetByDate(reportdate); var dts = dtr.GetByDate(reportdate); var wbs = wbr.GetByDate(reportdate); var abs = ar.GetByDate(reportdate); var dsl = dr.GetByDate(reportdate); var fsrs = fsrr.GetByDate(reportdate); decimal headedweighttotal = 0; decimal plweight = 0; decimal wbweight = 0; decimal avgyield = 100; foreach (ProductionTotal pt in pts) { if (pt.PlantWeight != null) {plweight = pt.PlantWeight.Value;} if (pt.WeighBacks != null) {wbweight = pt.WeighBacks.Value;} if (pt.AverageYield != null) {avgyield = pt.AverageYield.Value;} headedweighttotal += (plweight - wbweight) * avgyield / 100; plweight = 0; wbweight = 0; avgyield = 100; } decimal notzero = pts.Sum(x => x.PlantWeight).Value - pts.Sum(x => x.WeighBacks).Value; decimal avgTotal = 1; if (notzero == 0) { avgTotal = 0; } else { avgTotal = headedweighttotal * 100 / (pts.Sum(x => x.PlantWeight).Value - pts.Sum(x => x.WeighBacks).Value); } //decimal avgTotal = headedweighttotal * 100 / (pts.Sum(x => x.PlantWeight).Value - pts.Sum(x => x.WeighBacks).Value); string filletscale = fsrs == null ? "0" : fsrs.FilletScaleReading1.ToString(); string subject = ""; string body = ""; body += "<style>table, td, th {border: 1px solid #ddd; text-align: left;}table {border-collapse: collapse; width: 100%;} th, td {padding: 5px;} tr:nth-child(2) {background-color: #f8f8f8;} th {background-color: #ddd;}</style>"; subject = "Harvest Select Daily Production Report"; body += "Report Date: " + reportdate.ToShortDateString() + "<br /><br />"; body += "Fillet Scale Reading: " + filletscale + "<br /><br />"; body += "<b>Live Fish Receiving</b><br />"; body += "<table style='border: 1px solid #ddd; text-align:left; border-collapse: collapse; width: 100%;'><tr><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'></th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Pond Weight</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Plant Weight</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Difference</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>WeighBacks</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Net Live Weight</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Yield %</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Headed Yield</th></tr>"; body += "<tr style='background-color: #A1D490; font-weight: bold;'><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>TOTAL</td><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + pts.Sum(x => x.PondWeight).Value.ToString("#") + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + pts.Sum(x => x.PlantWeight).Value.ToString("#") + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + (pts.Sum(x => x.PondWeight).Value - pts.Sum(x => x.PlantWeight).Value).ToString("#") + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + pts.Sum(x => x.WeighBacks).Value.ToString("#") + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + (pts.Sum(x => x.PlantWeight).Value - pts.Sum(x => x.WeighBacks).Value).ToString("#") + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + avgTotal.ToString("#.####") + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + headedweighttotal.ToString("#") + "</td></tr>"; foreach (ProductionTotal pt in pts) { decimal plantweight = pt.PlantWeight.HasValue ? pt.PlantWeight.Value : 0; decimal pondweight = pt.PondWeight.HasValue ? pt.PondWeight.Value : 0; decimal weighbacks = pt.WeighBacks.HasValue ? pt.WeighBacks.Value : 0; decimal averageyield = pt.AverageYield.HasValue ? pt.AverageYield.Value : 0; body += "<tr><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + pt.Pond.Farm.InnovaName + " - " + pt.Pond.PondName + "</td><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + pondweight.ToString("#") + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + plantweight.ToString("#") + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + (pondweight - plantweight).ToString("#") + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + weighbacks.ToString("#") + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + (plantweight - weighbacks).ToString("#") + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + averageyield.ToString("#.####") + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + ((plantweight - weighbacks) * averageyield / 100).ToString("#") + "</td></tr>"; } body += "</table><br /><br />"; body += "<b>Samplings</b><br />"; body += "<table style='border: 1px solid #ddd; text-align:left; border-collapse: collapse; width: 100%;'><tr>"; body += "<th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Farm</th>"; body += "<th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Pond</th>"; body += "<th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Fish Size</th>"; body += "<th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Count</th>"; body += "<th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>% of Count</th>"; body += "<th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Weight (lbs)</th>"; body += "<th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>% of Weight</th>"; body += "<th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Avg Weight (lbs)</th>"; body += "</tr>"; List<Sampling> sresultsRanges = new List<Sampling>(); List<Sampling> sresultsPonds = new List<Sampling>(); List<Sampling> sresultsFarms = new List<Sampling>(); sresultsRanges = samplingResults.GroupBy(x => x.rangeName).Select(group => group.First()).ToList(); sresultsFarms = samplingResults.GroupBy(x => x.farm).Select(group => group.First()).ToList(); sresultsPonds = samplingResults.GroupBy(x => x.pond).Select(group => group.First()).ToList(); var totalScount = samplingResults.Sum(x => decimal.Parse(x.count)); var totalSweight = samplingResults.Sum(x => decimal.Parse(x.weight)); var totalSaverage = totalScount == 0 ? 0 : (totalSweight / totalScount); body += "<tr style='background-color: #A1D490;'>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>All Farms</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'></td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'></td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + string.Format("{0:N2}", totalScount) + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'></td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + string.Format("{0:N2}", totalSweight) + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'></td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + string.Format("{0:N2}", totalSaverage) + "</td>"; body += "</tr>"; foreach (Sampling sam3 in sresultsRanges) { body += "<tr>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'></td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'></td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + sam3.rangeName + "</td>"; var thispondScount = samplingResults.Where(x => x.rangeName == sam3.rangeName).Sum(x => decimal.Parse(x.count)); var thispondScountpercent = totalScount == 0 ? 0 : (thispondScount / totalScount) * 100; var thispondSweight = samplingResults.Where(x => x.rangeName == sam3.rangeName).Sum(x => decimal.Parse(x.weight)); var thispondSweightpercent = totalSweight == 0 ? 0 : (thispondSweight / totalSweight) * 100; var thisSaverage = thispondScount == 0 ? 0 : thispondSweight / thispondScount; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + string.Format("{0:N2}", thispondScount) + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + string.Format("{0:N2}%", thispondScountpercent) + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + string.Format("{0:N2}", thispondSweight) + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + string.Format("{0:N2}%", thispondSweightpercent) + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + string.Format("{0:N2}", thisSaverage) + "</td>"; body += "</tr>"; } foreach (Sampling sam in sresultsFarms) { var totalfarmcount = samplingResults.Where(x => x.farm == sam.farm).Sum(x => decimal.Parse(x.count)); var totalfarmweight = samplingResults.Where(x => x.farm == sam.farm).Sum(x => decimal.Parse(x.weight)); var totalfarmaverage = totalfarmcount == 0 ? 0 : (totalfarmweight / totalfarmcount); body += "<tr style='background-color: #A1D490;'>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + sam.farm + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'></td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>Farm Total</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + string.Format("{0:N2}", totalfarmcount) + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'></td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + string.Format("{0:N2}", totalfarmweight) + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'></td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + string.Format("{0:N2}", totalfarmaverage) + "</td>"; body += "</tr>"; foreach (Sampling sam1 in sresultsPonds.Where(x => x.farm == sam.farm)) { bool pNameLabel = true; var totalpondcount = samplingResults.Where(x => x.pond == sam1.pond && x.farm == sam.farm).Sum(x => decimal.Parse(x.count)); var totalpondweight = samplingResults.Where(x => x.pond == sam1.pond && x.farm == sam.farm).Sum(x => decimal.Parse(x.weight)); var totalaverage = totalpondcount == 0 ? 0 : (totalpondweight / totalpondcount); body += "<tr style='background-color: #CED490;'>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'></td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + sam1.pond + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>Pond Total</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + string.Format("{0:N2}", totalpondcount) + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'></td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + string.Format("{0:N2}", totalpondweight) + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'></td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + string.Format("{0:N2}", totalaverage) + "</td>"; body += "</tr>"; foreach (Sampling sam2 in sresultsRanges) { body += "<tr>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'></td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'></td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + sam2.rangeName + "</td>"; var thispondcount = samplingResults.Where(x => x.pond == sam1.pond && x.rangeName == sam2.rangeName && x.farm == sam.farm).Sum(x => decimal.Parse(x.count)); var thispondcountpercent = totalpondcount == 0 ? 0 : (thispondcount / totalpondcount) * 100; var thispondweight = samplingResults.Where(x => x.pond == sam1.pond && x.rangeName == sam2.rangeName && x.farm == sam.farm).Sum(x => decimal.Parse(x.weight)); var thispondweightpercent = totalpondweight == 0 ? 0 : (thispondweight / totalpondweight) * 100; var thisaverage = thispondcount == 0 ? 0 : thispondweight / thispondcount; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + string.Format("{0:N2}", thispondcount) + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + string.Format("{0:N2}%", thispondcountpercent) + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + string.Format("{0:N2}", thispondweight) + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + string.Format("{0:N2}%", thispondweightpercent) + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + string.Format("{0:N2}", thisaverage) + "</td>"; body += "</tr>"; } } } //body += "<tr style='background-color: #A1D490; font-weight: bold;'><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'></td>"; //foreach (Sampling sam in sresultsRanges) //{ // body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>Weight</td>"; // body += "<td style='border: 1px solid #ddd; border-right: 2px solid #222; text-align:left; padding: 5px;'>Count</td>"; //} //body += "</tr>"; //body += "<tr style='background-color: #A1D490; font-weight: bold;'><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>TOTAL (Weight | Count)</td>"; //foreach (Sampling sam in sresultsRanges) //{ // body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + samplingResults.Where(x => x.rangeName == sam.rangeName).Sum(x => decimal.Parse(x.weight)).ToString() + "</td>"; // body += "<td style='border: 1px solid #ddd; border-right: 2px solid #222; text-align:left; padding: 5px;'>" + samplingResults.Where(x => x.rangeName == sam.rangeName).Sum(x => decimal.Parse(x.count)).ToString() + "</td>"; //} //body += "</tr>"; //foreach (Sampling sam1 in sresultsPonds) //{ // body += "<tr><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + sam1.farmPond + "</td>"; // foreach (Sampling sam in sresultsRanges) // { // body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + samplingResults.Where(x => x.rangeName == sam.rangeName && x.farmPond == sam1.farmPond).Select(x => x.weight).FirstOrDefault() + "</td>"; // body += "<td style='border: 1px solid #ddd; border-right: 2px solid #222; text-align:left; padding: 5px;'>" + samplingResults.Where(x => x.rangeName == sam.rangeName && x.farmPond == sam1.farmPond).Select(x => x.count).FirstOrDefault() + "</td>"; // } // body += "</tr>"; //} body += "</table><br /><br />"; body += "<b>Production By Department</b><br />"; body += "<table style='border: 1px solid #ddd; text-align:left; border-collapse: collapse; width: 100%;'><tr><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'></th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Absences</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Finish Time</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Production Total</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Downtime</th></tr>"; body += "<tr style='background-color: #A1D490; font-weight: bold;'><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>TOTAL</td><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + dts.Sum(x => x.Absences).Value.ToString() + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>---</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + dts.Sum(x => x.ShiftWeight).Value.ToString() + " lbs</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + dts.Sum(x => x.DownTime).Value.ToString() + "</td></tr>"; foreach (DepartmentTotal dt in dts) { string finishtime = dt.FinishTime.HasValue ? dt.FinishTime.Value.ToShortTimeString() : "---"; string shiftweight = dt.ShiftWeight.HasValue ? dt.ShiftWeight.Value.ToString() : "---"; if (dt.DepartmentID == 3) { shiftweight = filletscale; } string downtime = dt.DownTime.HasValue ? dt.DownTime.Value.ToString() : "---"; string absences = dt.Absences.HasValue ? dt.Absences.Value.ToString() : "---"; body += "<tr><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + dt.Department.DepartmentName + "</td><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + absences + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + finishtime + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + shiftweight + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + downtime + "</td></tr>"; } body += "</table><br /><br />"; //body += "<b>WeighBack Details</b><br />"; //body += "<table style='border: 1px solid #ddd; text-align:left; border-collapse: collapse; width: 100%;'><tr><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'></th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Turtle/Trash</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Shad/Carp/Bream</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Live Disease</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Dressed Disease</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>~~Backs</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Red Fillet</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Big Fish</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>DOAs</th></tr>"; //body += "<tr style='background-color: #A1D490; font-weight: bold;'><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>TOTAL</td><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + wbs.Sum(x => x.Turtle).Value.ToString() + "</td>"; //body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + wbs.Sum(x => x.Shad).Value.ToString() + "</td>"; //body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + wbs.Sum(x => x.LiveDisease).Value.ToString() + "</td>"; //body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + wbs.Sum(x => x.DressedDisease).Value.ToString() + "</td>"; //body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + wbs.Sum(x => x.Backs).Value.ToString() + "</td>"; //body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + wbs.Sum(x => x.RedFillet).Value.ToString() + "</td>"; //body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + wbs.Sum(x => x.BigFish).Value.ToString() + "</td>"; //body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + wbs.Sum(x => x.DOAs).Value.ToString() + "</td></tr>"; //List<int> ponds = new List<int>(); //foreach (WeighBack wb in wbs) //{ // if (!ponds.Contains(wb.PondID)){ // body += "<tr><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + wb.Pond.Farm.FarmName + " - " + wb.Pond.PondName + "</td><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + wbs.Where(x => x.PondID == wb.PondID).Sum(x => x.Turtle).Value.ToString() + "</td>"; // body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + wbs.Where(x => x.PondID == wb.PondID).Sum(x => x.Shad).Value.ToString() + "</td>"; // body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + wbs.Where(x => x.PondID == wb.PondID).Sum(x => x.LiveDisease).Value.ToString() + "</td>"; // body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + wbs.Where(x => x.PondID == wb.PondID).Sum(x => x.DressedDisease).Value.ToString() + "</td>"; // body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + wbs.Where(x => x.PondID == wb.PondID).Sum(x => x.Backs).Value.ToString() + "</td>"; // body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + wbs.Where(x => x.PondID == wb.PondID).Sum(x => x.RedFillet).Value.ToString() + "</td>"; // body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + wbs.Where(x => x.PondID == wb.PondID).Sum(x => x.BigFish).Value.ToString() + "</td>"; // body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + wbs.Where(x => x.PondID == wb.PondID).Sum(x => x.DOAs).Value.ToString() + "</td></tr>"; // } // ponds.Add(wb.PondID); //} //body += "</table><br /><br />"; body += "<b>Employee Absence Details</b><br />"; body += "<table style='border: 1px solid #ddd; text-align:left; border-collapse: collapse; width: 100%;'><tr><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'></th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Reg Out</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Reg Late</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Reg Left Early</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Temp Out</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Temp Late</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Temp Left Early</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Inmate Out</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Inmate Left Early</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Vacation</th></tr>"; body += "<tr style='background-color: #A1D490; font-weight: bold;'><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>TOTAL</td><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + abs.Sum(x => x.RegEmpOut).Value.ToString() + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + abs.Sum(x => x.RegEmpLate).Value.ToString() + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + abs.Sum(x => x.RegEmpLeftEarly).Value.ToString() + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + abs.Sum(x => x.TempEmpOut).Value.ToString() + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + abs.Sum(x => x.TempEmpLate).Value.ToString() + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + abs.Sum(x => x.TempEmpLeftEarly).Value.ToString() + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + abs.Sum(x => x.InmateOut).Value.ToString() + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + abs.Sum(x => x.InmateLeftEarly).Value.ToString() + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + abs.Sum(x => x.EmployeesOnVacation).Value.ToString() + "</td></tr>"; foreach (Absence ab in abs) { string RegEmpOut = ab.RegEmpOut.HasValue ? ab.RegEmpOut.Value.ToString() : "---"; string RegEmpLate = ab.RegEmpLate.HasValue ? ab.RegEmpLate.Value.ToString() : "---"; string RegEmpLeftEarly = ab.RegEmpLeftEarly.HasValue ? ab.RegEmpLeftEarly.Value.ToString() : "---"; string TempEmpOut = ab.TempEmpOut.HasValue ? ab.TempEmpOut.Value.ToString() : "---"; string TempEmpLate = ab.TempEmpLate.HasValue ? ab.TempEmpLate.Value.ToString() : "---"; string TempEmpLeftEarly = ab.TempEmpLeftEarly.HasValue ? ab.TempEmpLeftEarly.Value.ToString() : "---"; string InmateOut = ab.InmateOut.HasValue ? ab.InmateOut.Value.ToString() : "---"; string InmateLeftEarly = ab.InmateLeftEarly.HasValue ? ab.InmateLeftEarly.Value.ToString() : "---"; string EmployeesOnVacation = ab.EmployeesOnVacation.HasValue ? ab.EmployeesOnVacation.Value.ToString() : "---"; body += "<tr><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + ab.Department.DepartmentName + "</td><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + RegEmpOut + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + RegEmpLate + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + RegEmpLeftEarly + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + TempEmpOut + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + TempEmpLate + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + TempEmpLeftEarly + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + InmateOut + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + InmateLeftEarly + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + EmployeesOnVacation + "</td></tr>"; } body += "</table><br /><br />"; body += "<b>Downtime Details</b><br />"; body += "<table style='border: 1px solid #ddd; text-align:left; border-collapse: collapse; width: 100%;'><tr><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'></th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Type</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Minutes</th><th style='border: 1px solid #ddd; text-align:left; padding: 5px; background-color: #ddd;'>Note</th></tr>"; body += "<tr style='background-color: #A1D490; font-weight: bold;'><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>TOTAL</td><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>---</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + dsl.Sum(x => x.Minutes).ToString() + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>---</td></tr>"; foreach (DownTime dt in dsl) { string DownTimeNote = dt.DownTimeNote != null ? dt.DownTimeNote : "---"; body += "<tr><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + dt.DownTimeType.Department.DepartmentName + "</td><td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + dt.DownTimeType.DownTimeName + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + dt.Minutes.ToString() + "</td>"; body += "<td style='border: 1px solid #ddd; text-align:left; padding: 5px;'>" + dt.DownTimeNote + "</td></tr>"; } body += "</table><br /><br />"; body += "</table>"; //, [email protected] string elist = ""; EmailRepository er = new EmailRepository(); List<Email> emails = er.GetEmails(); foreach (Email em in emails) { elist += em.EmailAddress + ", "; } elist = elist.Substring(0, elist.Length - 2); //SendMail("[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]", subject, body); SendMail(elist, subject, body); return Request.CreateResponse(HttpStatusCode.OK); }