Ejemplo n.º 1
0
        public ActionResult Index()
        {
            var userId = User.Identity.GetUserId();
            var emails = _emailRepository.GetEmails(userId);

            return(View(emails));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetEmails(int contactId)
        {
            var emails = await _repo.GetEmails(contactId);

            return(Ok(emails));
        }
        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);
        }