示例#1
0
        public IActionResult SoilTest(SoilTestViewModel fvm)
        {
            fvm.tstOptions = new List <SelectListItem>();
            fvm.tstOptions = _sd.GetSoilTestMethodsDll().ToList();

            if (fvm.buttonPressed == "MethodChange")
            {
                ModelState.Clear();
                FarmDetails fd = _ud.FarmDetails();
                fd.testingMethod = fvm.selTstOption == "select" ? string.Empty : fvm.selTstOption;
                _ud.UpdateFarmDetails(fd);
                fvm.testSelected = string.IsNullOrEmpty(fd.testingMethod) ? false : true;
                List <Field> fl = _ud.GetFields();

                //update fields with convert STP and STK
                _ud.UpdateSTPSTK(fl);

                //update the Nutrient calculations with the new/changed soil test data
                Utility.ChemicalBalanceMessage cbm = new Utility.ChemicalBalanceMessage(_ud, _sd);
                cbm.RecalcCropsSoilTestMessagesByFarm();

                RedirectToAction("SoilTest", "Soil");
            }
            return(View(fvm));
        }
示例#2
0
        private Task <ReportFieldsViewModel> ReportFieldsAsync()
        {
            ReportFieldsViewModel fvm = new ReportFieldsViewModel();

            FarmDetails fd = _ud.FarmDetails();


            List <Field> flds = _ud.GetFields();

            foreach (var m in flds)
            {
                DisplayReportField dc = new DisplayReportField();
                dc.fldName = m.fieldName;
                if (m.soilTest != null)
                {
                    dc.sampleDate = m.soilTest.sampleDate.ToString("MMM-yyyy");
                    dc.dispNO3H   = m.soilTest.valNO3H.ToString();
                    dc.dispP      = m.soilTest.ValP.ToString();
                    dc.dispK      = m.soilTest.valK.ToString();
                    dc.dispPH     = m.soilTest.valPH.ToString();
                }
                fvm.fields.Add(dc);
            }

            return(Task.FromResult(fvm));
        }
示例#3
0
        public void UpdateFarmDetails(FarmDetails fd)
        {
            FarmData userData = _ctx.HttpContext.Session.GetObjectFromJson <FarmData>("FarmData");

            userData.unsaved = true;
            userData.farmDetails.farmName      = fd.farmName;
            userData.farmDetails.farmRegion    = fd.farmRegion;
            userData.farmDetails.soilTests     = fd.soilTests;
            userData.farmDetails.testingMethod = fd.testingMethod;
            userData.farmDetails.manure        = fd.manure;
            userData.farmDetails.year          = fd.year;

            //change the year associated with the array
            YearData yd = userData.years.FirstOrDefault();

            if (yd == null)
            {
                YearData ny = new YearData();
                ny.year = fd.year;
                userData.years.Add(ny);
            }
            else
            {
                yd.year = fd.year;
            }
            _ctx.HttpContext.Session.SetObjectAsJson("FarmData", userData);
        }
        public int GetConvertedSTP(SoilTest soilTest)
        {
            int convertedP = 0;

            try
            {
                //get soil test method selected by user
                FarmDetails fd = _ud.FarmDetails();

                if (fd.testingMethod == null)
                {
                    fd.testingMethod = _sd.GetDefaultSoilTestMethod();
                }

                SoilTestMethod soilTestMethod = _sd.GetSoilTestMethodById(fd.testingMethod);

                if (soilTest.valPH >= 7.2M) //ph of 7.2 is a constant boundary
                {
                    convertedP = Convert.ToInt16(Decimal.Multiply(soilTestMethod.ConvertToKelownaPHGreaterThanEqual72, soilTest.ValP));
                }
                else
                {
                    convertedP = Convert.ToInt16(Decimal.Multiply(soilTestMethod.ConvertToKelownaPHLessThan72, soilTest.ValP));
                }
            }
            catch (Exception ex)
            {
                // display error
                throw;
            }

            return(convertedP);
        }
        public int GetConvertedSTK(SoilTest soilTest)
        {
            int convertedK = 0;

            try
            {
                //get soil test method selected by user
                FarmDetails fd = _ud.FarmDetails();

                if (fd.testingMethod == null)
                {
                    fd.testingMethod = _sd.GetDefaultSoilTestMethod();
                }

                var soilTestMethod = _sd.GetSoilTestMethodById(fd.testingMethod);

                convertedK = Convert.ToInt16(Decimal.Multiply(soilTestMethod.ConvertToKelownaK, soilTest.valK));
            }
            catch (Exception ex)
            {
                // display error
                throw;
            }

            return(convertedK);
        }
示例#6
0
        public IActionResult SoilTest(SoilTestViewModel fvm)
        {
            fvm.tstOptions = new List <SelectListItem>();
            fvm.tstOptions = _sd.GetSoilTestMethodsDll().ToList();

            if (fvm.buttonPressed == "MethodChange")
            {
                ModelState.Clear();
                FarmDetails fd = _ud.FarmDetails();
                fd.TestingMethod = fvm.selTstOption == "select" ? string.Empty : fvm.selTstOption;
                _ud.UpdateFarmDetails(fd);
                fvm.testSelected = string.IsNullOrEmpty(fd.TestingMethod) ? false : true;
                List <Field> fl = _ud.GetFields();

                //update fields with convert STP and STK
                _ud.UpdateSTPSTK(fl);

                //update the Nutrient calculations with the new/changed soil test data
                var updatedFields = _chemicalBalanceMessage.RecalcCropsSoilTestMessagesByFarm(_ud.GetFields(), _ud.FarmDetails().FarmRegion.Value);
                foreach (var field in updatedFields)
                {
                    foreach (var crop in field.Crops)
                    {
                        _ud.UpdateFieldCrop(field.FieldName, crop);
                    }
                }

                RedirectToAction("SoilTest", "Soil");
            }
            return(View(fvm));
        }
示例#7
0
        public decimal?GetDefaultYieldByCropId(FarmDetails farmDetails, int _cropid, bool useBushelPerAcreUnits)
        {
            decimal?defaultYield = null;
            int     _locationid;

            if (farmDetails.FarmRegion.HasValue)
            {
                _locationid = _sd.GetRegion(farmDetails.FarmRegion.Value).LocationId;
                CropYield cy = _sd.GetCropYield(_cropid, _locationid);
                if (cy != null && cy.Amount.HasValue)
                {
                    defaultYield = cy.Amount.Value;
                }
                if (useBushelPerAcreUnits && defaultYield.HasValue)
                {
                    //E07US18 - convert to bushels per acre
                    Crop crop = _sd.GetCrop(_cropid);
                    if (crop.HarvestBushelsPerTon.HasValue)
                    {
                        defaultYield = defaultYield * crop.HarvestBushelsPerTon;
                    }
                }
            }

            return(defaultYield);
        }
        private Task <FieldsViewModel> GetFieldsAsync()
        {
            FieldsViewModel fvm = new FieldsViewModel();
            FarmDetails     fd  = _ud.FarmDetails();

            if (fd.farmRegion.HasValue)
            {
                fvm.regionFnd = true;
            }
            else
            {
                fvm.regionFnd = false;
                fvm.noRegion  = _sd.GetUserPrompt("missingregion");
            }

            fvm.fields = new List <Field>();

            List <Field> fldList = _ud.GetFields();

            foreach (var f in fldList)
            {
                Field nf = new Field();
                nf.fieldName = f.fieldName;
                nf.area      = f.area;
                nf.comment   = f.comment;
                fvm.fields.Add(nf);
            }

            return(Task.FromResult(fvm));
        }
示例#9
0
        public IActionResult SoilTest()
        {
            SoilTestViewModel fvm = new SoilTestViewModel();

            FarmDetails fd = _ud.FarmDetails();

            fvm.selTstOption = fd.testingMethod;

            if (!string.IsNullOrEmpty(fd.testingMethod))
            {
                fvm.testSelected = true;
            }

            fvm.tstOptions = new List <Models.StaticData.SelectListItem>();
            fvm.tstOptions = _sd.GetSoilTestMethodsDll().ToList();

            List <Field> fl = _ud.GetFields();

            fvm.fldsFnd = (fl.Count() > 0) ? true : false;

            fvm.url        = _sd.GetExternalLink("soiltestexplanation");
            fvm.warningMsg = _sd.GetUserPrompt("soiltestwarning");

            return(View(fvm));
        }
        public ActionResult FarmDetails(int?cid, FarmDetails FarmDetails)
        {
            NewPolicyDetailsClass FarmDetailsmodel     = new NewPolicyDetailsClass();
            List <SelectListItem> constructionTypeList = new List <SelectListItem>();

            constructionTypeList = FarmDetailsmodel.constructionType();
            FarmDetails.ConstructionFBObj.ConstructionHCList = constructionTypeList;
            var db = new MasterDataEntities();

            if (cid != null)
            {
                ViewBag.cid            = cid;
                FarmDetails.CustomerId = cid.Value;
            }
            else
            {
                ViewBag.cid = FarmDetails.CustomerId;
            }
            string policyid = null;

            Session["unId"]      = null;
            Session["profileId"] = null;
            Session["FarmFxd"]   = 1;

            return(RedirectToAction("FarmContents", "MobileFarm", new { cid = FarmDetails.CustomerId, PcId = FarmDetails.PcId }));

            return(View(FarmDetails));
        }
示例#11
0
        public ActionResult Fields()
        {
            FieldPageViewModel fvm = new FieldPageViewModel();

            FarmDetails fd = _ud.FarmDetails();

            return(View(fvm));
        }
示例#12
0
        private bool HasAnimalSelectionChanged(FarmViewModel fvm, FarmDetails farmData)
        {
            var animalSelectionsUnchanged = (
                (farmData.HasAnimals == fvm.OriginalHasAnimals) &&
                (farmData.HasBeefCows == fvm.OriginalHasBeefCows) &&
                (farmData.HasDairyCows == fvm.OriginalHasDairyCows) &&
                (farmData.HasMixedLiveStock == fvm.OriginalHasMixedLiveStock) &&
                (farmData.HasPoultry == fvm.OriginalHasPoultry)
                );

            return(!animalSelectionsUnchanged);
        }
        private Task <GetSoilTestNitrateOverrideViewModel> GetSoilTestNitrateOverrideAsync(string fldName)
        {
            GetSoilTestNitrateOverrideViewModel soilvm = new GetSoilTestNitrateOverrideViewModel();

            // get the current associated value for nitrogen credit.  Note, can be null
            SERVERAPI.Utility.ChemicalBalanceMessage calculator = new Utility.ChemicalBalanceMessage(_ud, _sd);

            FarmDetails farmdtl = _ud.FarmDetails();
            Field       fld     = _ud.GetFieldDetails(fldName);

            soilvm.display = false;

            if ((fld.crops != null) && (fld.soilTest != null))
            {
                if (fld.crops.Count() > 0)
                {
                    soilvm.display = _sd.IsNitrateCreditApplicable(farmdtl.farmRegion, fld.soilTest.sampleDate, Convert.ToInt16(farmdtl.year));
                    if (soilvm.display)
                    {
                        soilvm.fldName = fldName;
                        if (fld.SoilTestNitrateOverrideNitrogenCredit != null)
                        {
                            soilvm.nitrogen = Math.Round(Convert.ToDecimal(fld.SoilTestNitrateOverrideNitrogenCredit));
                        }
                        else
                        {
                            // lookup default Nitrogen credit
                            soilvm.nitrogen = Math.Round(fld.soilTest.valNO3H * _sd.GetSoilTestNitratePPMToPoundPerAcreConversionFactor());
                        }
                    }
                    else
                    {
                        fld.SoilTestNitrateOverrideNitrogenCredit = null;
                        _ud.UpdateField(fld);
                    }
                }
                else
                {
                    fld.SoilTestNitrateOverrideNitrogenCredit = null;
                    _ud.UpdateField(fld);
                }
            }
            else
            {
                fld.SoilTestNitrateOverrideNitrogenCredit = null;
                _ud.UpdateField(fld);
            }
            return(Task.FromResult(soilvm));
        }
示例#14
0
        private Task <SoilTestsViewModel> GetSoilTestAsync()
        {
            SoilTestsViewModel svm = new SoilTestsViewModel();

            Utility.SoilTestConversions stc = new SoilTestConversions(_ud, _sd);

            svm.missingTests = false;

            FarmDetails fd = _ud.FarmDetails();

            svm.testingMethod = fd.testingMethod;

            svm.tests = new List <DisplaySoilTest>();

            List <Field> flds = _ud.GetFields();

            foreach (var m in flds)
            {
                DisplaySoilTest dc = new DisplaySoilTest();
                dc.fldName = m.fieldName;
                if (m.soilTest != null)
                {
                    dc.sampleDate  = m.soilTest.sampleDate.ToString("MMM-yyyy");
                    dc.dispNO3H    = m.soilTest.valNO3H.ToString();
                    dc.dispP       = m.soilTest.ValP.ToString();
                    dc.dispK       = m.soilTest.valK.ToString();
                    dc.dispPH      = m.soilTest.valPH.ToString();
                    dc.dispPRating = _sd.SoilTestRating("phosphorous", stc.GetConvertedSTP(m.soilTest));
                    dc.dispKRating = _sd.SoilTestRating("potassium", stc.GetConvertedSTK(m.soilTest));
                }
                else
                {
                    svm.missingTests = true;
                }
                svm.tests.Add(dc);
            }

            return(Task.FromResult(svm));
        }
        public async System.Threading.Tasks.Task <ActionResult> FarmDetails(int?cid, int?PcId)
        {
            string ApiKey = null;

            if (Session["ApiKey"] != null)
            {
                ApiKey = Session["ApiKey"].ToString();
            }
            else
            {
                return(RedirectToAction("AgentLogin", "Login"));
            }
            var Policyincllist = new List <SessionModel>();

            if (Session["Policyinclustions"] != null)
            {
                Policyincllist = Session["Policyinclustions"] as List <SessionModel>;
                if (Policyincllist != null)
                {
                    if (Policyincllist != null)
                    {
                        if (Policyincllist.Exists(p => p.name == "Fixed Farm Property"))
                        {
                        }

                        else if (Policyincllist.Exists(p => p.name == "Mobile Farm Property"))
                        {
                            return(RedirectToAction("FarmContents", "MobileFarm", new { cid = cid, PcId = PcId }));
                        }
                        else if (Policyincllist.Exists(p => p.name == "Burglary"))
                        {
                            return(RedirectToAction("Burglary", "FarmPolicyBurglary", new { cid = cid, PcId = PcId }));
                        }
                        else if (Policyincllist.Exists(p => p.name == "Farm Interuption"))
                        {
                            return(RedirectToAction("FarmInterruption", "FarmPolicyFarmInterruption", new { cid = cid, PcId = PcId }));
                        }
                        else if (Policyincllist.Exists(p => p.name == "Money"))
                        {
                            return(RedirectToAction("Money", "FarmPolicyMoney", new { cid = cid, PcId = PcId }));
                        }
                        else if (Policyincllist.Exists(p => p.name == "Farm Liability"))
                        {
                            return(RedirectToAction("FarmLiability", "FarmPolicyFarmLiability", new { cid = cid, PcId = PcId }));
                        }
                        else if (Policyincllist.Exists(p => p.name == "Machinery"))
                        {
                            return(RedirectToAction("Machinery", "FarmPolicyMachinery", new { cid = cid, PcId = PcId }));
                        }

                        else if (Policyincllist.Exists(p => p.name == "Electronics"))
                        {
                            return(RedirectToAction("Electronics", "FarmPolicyElectronics", new { cid = cid, PcId = PcId }));
                        }

                        else if (Policyincllist.Exists(p => p.name == "Transit"))
                        {
                            return(RedirectToAction("Transit", "FarmPolicyTransit", new { cid = cid, PcId = PcId }));
                        }
                        else if (Policyincllist.Exists(p => p.name == "Livestock"))
                        {
                            return(RedirectToAction("Livestock", "FarmPolicyLivestock", new { cid = cid, PcId = PcId }));
                        }
                        else if (Policyincllist.Exists(p => p.name == "Home Buildings"))
                        {
                            return(RedirectToAction("MainDetails", "FarmPolicyHome", new { cid = cid, PcId = PcId }));
                        }
                        else if (Policyincllist.Exists(p => p.name == "Home Contents"))
                        {
                            return(RedirectToAction("HomeContents", "FarmPolicyHomeContent", new { cid = cid, PcId = PcId }));
                        }
                        else if (Policyincllist.Exists(p => p.name == "Personal Liability"))
                        {
                            return(RedirectToAction("PersonalLiability", "FarmPolicyPersonalLiability", new { cid = cid, PcId = PcId }));
                        }
                        else if (Policyincllist.Exists(p => p.name == "Valuables"))
                        {
                            return(RedirectToAction("Valuables", "FarmPolicyValuables", new { cid = cid, PcId = PcId }));
                        }
                        else if (Policyincllist.Exists(p => p.name == "Motor"))
                        {
                            return(RedirectToAction("VehicleDescription", "FarmMotors", new { cid = cid, PcId = PcId }));
                        }
                        if (Policyincllist.Exists(p => p.name == "Fixed Farm Property"))
                        {
                            if (Session["unId"] == null && Session["profileId"] == null)
                            {
                                Session["unId"]      = Policyincllist.Where(p => p.name == "Fixed Farm Property").Select(p => p.UnitId).First();
                                Session["profileId"] = Policyincllist.Where(p => p.name == "Fixed Farm Property").Select(p => p.ProfileId).First();
                            }
                        }
                        else
                        {
                            return(RedirectToAction("DisclosureDetails", "Disclosure", new { cid = cid, PcId = PcId }));
                        }
                    }
                }
            }
            else
            {
                RedirectToAction("PolicyInclustions", "Customer", new { CustomerId = cid, type = 1021 });
            }
            ViewEditPolicyDetails unitdetails          = new ViewEditPolicyDetails();
            NewPolicyDetailsClass FarmDetailsmodel     = new NewPolicyDetailsClass();
            List <SelectListItem> constructionTypeList = new List <SelectListItem>();

            constructionTypeList = FarmDetailsmodel.constructionType();
            FarmDetails FarmDetails = new FarmDetails();

            #region Farm location details
            FarmDetails.AddressObj  = new AddressForFP();
            FarmDetails.LocationObj = new LocatioForFP();
            #endregion
            #region Farm Details
            FarmDetails.DescriptionFBObj                     = new DetailedDescription();
            FarmDetails.DescriptionFBObj.EiId                = 62255;
            FarmDetails.YearconstructedFBObj                 = new YearConstructedFB();
            FarmDetails.YearconstructedFBObj.EiId            = 62257;
            FarmDetails.ConstructionFBObj                    = new ConstructionFB();
            FarmDetails.ConstructionFBObj.ConstructionHCList = constructionTypeList;
            FarmDetails.ConstructionFBObj.EiId               = 62259;
            FarmDetails.ContaincoolroomObj                   = new ContainCoolroomFB();
            FarmDetails.ContaincoolroomObj.EiId              = 62261;
            FarmDetails.SuminsuredFBObj          = new SumInsuredsFB();
            FarmDetails.SuminsuredFBObj.EiId     = 62263;
            FarmDetails.UnrepaireddamageObj      = new UnrepairedDamageFS();
            FarmDetails.UnrepaireddamageObj.EiId = 62309;
            FarmDetails.ExcessFBObj        = new HarvestedCropsExcess();
            FarmDetails.ExcessFBObj.EiId   = 62315;
            FarmDetails.TypeoffarmObj      = new typeoffarmInFP();
            FarmDetails.TypeoffarmObj.EiId = 62005;
            FarmDetails.FarmsizeObj        = new farmsizeInFP();
            FarmDetails.FarmsizeObj.EiId   = 62007;
            #endregion
            #region Farm Structures
            List <SelectListItem> ExcessRateList = new List <SelectListItem>();
            ExcessRateList                       = FarmDetailsmodel.ExcessRateFS();
            FarmDetails.SublimitObj              = new SubLimitFarmFencing();
            FarmDetails.SublimitObj.EiId         = 62283;
            FarmDetails.TotalcoverObj            = new TotalCoverFarmFencing();
            FarmDetails.TotalcoverObj.EiId       = 62287;
            FarmDetails.OtherstructurefcObj      = new OtherFarmStructuresFC();
            FarmDetails.OtherstructurefcObj.EiId = 62291;
            FarmDetails.RoofwallsObj             = new RoofAndWallsFS();
            FarmDetails.RoofwallsObj.EiId        = 62297;
            //FarmStructures.UnrepaireddamageObj = new UnrepairedDamageFS();
            //FarmStructures.UnrepaireddamageObj.EiId = 62309;
            FarmDetails.ExcesshcFSObj = new HarvestedCropsExcess();
            FarmDetails.ExcesshcFSObj.ExcessHCList = ExcessRateList;
            FarmDetails.ExcesshcFSObj.EiId         = 62315;
            #endregion
            #region HarvestedCrops
            List <SelectListItem> ExcessRateLists = new List <SelectListItem>();
            ExcessRateLists                        = FarmDetailsmodel.excessRate();
            FarmDetails.SuminsuredhcObj            = new HarvestedCropsSumInsured();
            FarmDetails.SuminsuredhcObj.EiId       = 62329;
            FarmDetails.ExcesshcHCObj              = new HarvestedCropsExcess();
            FarmDetails.ExcesshcHCObj.ExcessHCList = ExcessRateLists;
            FarmDetails.ExcesshcHCObj.EiId         = 62331;
            #endregion
            #region Interested Parties
            FarmDetails.PartynameObj            = new InterestedPartyName();
            FarmDetails.PartynameObj.EiId       = 62345;
            FarmDetails.PartylocationObj        = new InterestedPartyLocation();
            FarmDetails.PartylocationObj.EiId   = 62347;
            FarmDetails.TotalsuminsuredObj      = new InterestedTotalSumInsured();
            FarmDetails.TotalsuminsuredObj.EiId = 62349;
            #endregion
            if (cid != null)
            {
                ViewBag.cid            = cid;
                FarmDetails.CustomerId = cid.Value;
            }
            else
            {
                ViewBag.cid = FarmDetails.CustomerId;
            }
            var        db       = new MasterDataEntities();
            string     policyid = null;
            HttpClient hclient  = new HttpClient();
            string     url      = System.Configuration.ConfigurationManager.AppSettings["APIURL"];
            hclient.BaseAddress = new Uri(url);
            hclient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            int unid       = 0;
            int profileid  = 0;
            int Fprofileid = 0;
            if (Session["unId"] != null && Session["ProfileId"] != null)
            {
                unid      = Convert.ToInt32(Session["unId"]);
                profileid = Convert.ToInt32(Session["profileId"]);
            }
            if (Session["FProfileId"] != null)
            {
                Fprofileid = Convert.ToInt32(Session["FprofileId"]);
            }
            if (Session["Policyinclustions"] != null)
            {
                FarmDetails.PolicyInclusions = Policyincllist;
            }
            if (PcId != null && PcId.HasValue && PcId > 0)
            {
                var policyinclusions = db.usp_GetUnit(null, PcId, null).ToList();
                FarmDetails.PolicyInclusion = new List <usp_GetUnit_Result>();
                if (PcId != null && PcId.HasValue && PcId > 0)
                {
                    FarmDetails.PolicyInclusion = policyinclusions;
                }
                FarmDetails.PolicyInclusions = new List <SessionModel>();
                if (PcId != null && PcId > 0)
                {
                    policyid             = PcId.ToString();
                    FarmDetails.PolicyId = policyid;
                }
                bool policyinclusion = policyinclusions.Exists(p => p.Name == "Fixed Farm Property");
                if (policyinclusion == true && PcId != null && PcId.HasValue)
                {
                    int sectionId               = policyinclusions.Where(p => p.Name == "Fixed Farm Property" && p.UnitNumber == unid).Select(p => p.UnId).FirstOrDefault();
                    int?profileunid             = policyinclusions.Where(p => p.Name == "Fixed Farm Property" && p.ProfileUnId == profileid).Select(p => p.ProfileUnId).FirstOrDefault();
                    HttpResponseMessage getunit = await hclient.GetAsync("UnitDetails?ApiKey=" + ApiKey + "&Action=Existing&SectionName=&SectionUnId=" + unid + "&ProfileUnId=" + profileid);

                    var EmpResponse = getunit.Content.ReadAsStringAsync().Result;
                    if (EmpResponse != null)
                    {
                        unitdetails = JsonConvert.DeserializeObject <ViewEditPolicyDetails>(EmpResponse);
                    }
                }
            }
            else
            {
                if (PcId == null && Session["unId"] == null && Session["profileId"] == null)
                {
                    HttpResponseMessage Res = await hclient.GetAsync("UnitDetails?ApiKey=" + ApiKey + "&Action=New&SectionName=Fixed Farm Property&SectionUnId=&ProfileUnId=");

                    var EmpResponse = Res.Content.ReadAsStringAsync().Result;
                    if (EmpResponse != null)
                    {
                        unitdetails = JsonConvert.DeserializeObject <ViewEditPolicyDetails>(EmpResponse);
                        if (unitdetails != null && unitdetails.SectionData != null)
                        {
                            Session["unId"]       = unitdetails.SectionData.UnId;
                            Session["FprofileId"] = unitdetails.SectionData.ProfileUnId;
                            Session["profileId"]  = unitdetails.SectionData.ProfileUnId;
                            if (Policyincllist != null && Policyincllist.Exists(p => p.name == "Fixed Farm Property"))
                            {
                                var policyhomelist = Policyincllist.FindAll(p => p.name == "Fixed Farm Property").ToList();
                                if (policyhomelist != null && policyhomelist.Count() > 0)
                                {
                                    Policyincllist.FindAll(p => p.name == "Fixed Farm Property").Where(p => p.UnitId == null).First().UnitId = unitdetails.SectionData.UnId;

                                    Policyincllist.FindAll(p => p.name == "Fixed Farm Property").Where(p => p.ProfileId == null).First().ProfileId = unitdetails.SectionData.ProfileUnId;
                                }
                                else
                                {
                                    Policyincllist.FindAll(p => p.name == "Fixed Farm Property").First().UnitId = unitdetails.SectionData.UnId;

                                    Policyincllist.FindAll(p => p.name == "Fixed Farm Property").First().ProfileId = unitdetails.SectionData.ProfileUnId;
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (PcId == null && Session["unId"] != null && (Session["profileId"] != null || (Fprofileid != null && Fprofileid < 0)))
                    {
                        if (profileid == null || profileid == 0)
                        {
                            profileid = Fprofileid;
                        }
                        HttpResponseMessage getunit = await hclient.GetAsync("UnitDetails?ApiKey=" + ApiKey + "&Action=Existing&SectionName=&SectionUnId=" + unid + "&ProfileUnId=" + profileid);

                        var EmpResponse = getunit.Content.ReadAsStringAsync().Result;
                        if (EmpResponse != null)
                        {
                            unitdetails = JsonConvert.DeserializeObject <ViewEditPolicyDetails>(EmpResponse);
                            if (unitdetails != null && unitdetails.SectionData != null)
                            {
                                Session["unId"]       = unitdetails.SectionData.UnId;
                                Session["FprofileId"] = unitdetails.SectionData.ProfileUnId;
                            }
                        }
                    }
                }
            }
            if (unitdetails != null)
            {
                if (unitdetails.SectionData.AddressData != null)
                {
                    FarmDetails.AddressObj           = new AddressForFP();
                    FarmDetails.LocationObj          = new LocatioForFP();
                    FarmDetails.AddressObj.Address   = unitdetails.SectionData.AddressData.AddressLine1;
                    FarmDetails.LocationObj.Location = unitdetails.SectionData.AddressData.State + ", " + unitdetails.SectionData.AddressData.Suburb + ", " + unitdetails.SectionData.AddressData.Postcode;
                    //homebuilding.Postcode = unitdetails.AddressData.Select(p => p.Postcode).First();
                    // FarmDetails.Suburb = unitdetails.AddressData.Select(p => p.Suburb).First();
                    //for (int add = 0; add <= unitdetails.AddressData.Count(); add++)
                    //{
                    //    if(unitdetails.AddressData[add].Suburb=="LAMBTON")
                    //    {
                    //        homebuilding.Sub = "WA";
                    //    }
                    //  //  homebuilding.Sub = unitdetails.AddressData[add].Suburb;
                    //    homebuilding.LocationObj.Location = unitdetails.AddressData[add].AddressLine1;
                    //    homebuilding.Pincode = unitdetails.AddressData[add].Postcode;
                    //    break;
                    //}
                }
                if (unitdetails.SectionData != null && unitdetails.SectionData.ValueData != null)
                {
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == FarmDetails.DescriptionFBObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.DescriptionFBObj.EiId).Select(p => p.Value).FirstOrDefault();
                        if (val != null && !string.IsNullOrEmpty(val))
                        {
                            FarmDetails.DescriptionFBObj.Description = val;
                        }
                        if (unitdetails.SectionData.ValueData.Select(p => p.Element.ElId == FarmDetails.DescriptionFBObj.EiId).Count() > 1)
                        {
                            List <ValueDatas> elmnts = new List <ValueDatas>();
                            var DescriptionFBList    = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.DescriptionFBObj.EiId).Select(p => p.Element.ItId).ToList();
                            for (int i = 0; i < DescriptionFBList.Count(); i++)
                            {
                                ValueDatas vds = new ValueDatas();
                                vds.Element      = new Elements();
                                vds.Element.ElId = 62255;
                                vds.Element.ItId = DescriptionFBList[i];
                                vds.Value        = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.DescriptionFBObj.EiId && p.Element.ItId == DescriptionFBList[i]).Select(p => p.Value).FirstOrDefault();
                                elmnts.Add(vds);
                            }
                            FarmDetails.DescriptionFBObjList = elmnts;
                        }
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == FarmDetails.YearconstructedFBObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.YearconstructedFBObj.EiId).Select(p => p.Value).FirstOrDefault();
                        if (val != null && !string.IsNullOrEmpty(val))
                        {
                            FarmDetails.YearconstructedFBObj.Year = val;
                        }
                        if (unitdetails.SectionData.ValueData.Select(p => p.Element.ElId == FarmDetails.YearconstructedFBObj.EiId).Count() > 1)
                        {
                            List <ValueDatas> elmnts  = new List <ValueDatas>();
                            var YearconstructedFBList = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.YearconstructedFBObj.EiId).Select(p => p.Element.ItId).ToList();
                            for (int i = 0; i < YearconstructedFBList.Count(); i++)
                            {
                                ValueDatas vds = new ValueDatas();
                                vds.Element      = new Elements();
                                vds.Element.ElId = 62257;
                                vds.Element.ItId = YearconstructedFBList[i];
                                vds.Value        = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.YearconstructedFBObj.EiId && p.Element.ItId == YearconstructedFBList[i]).Select(p => p.Value).FirstOrDefault();
                                elmnts.Add(vds);
                            }
                            FarmDetails.YearconstructedFBObjList = elmnts;
                        }
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == FarmDetails.ConstructionFBObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.ConstructionFBObj.EiId).Select(p => p.Value).FirstOrDefault();
                        if (val != null && !string.IsNullOrEmpty(val))
                        {
                            FarmDetails.ConstructionFBObj.Construction = val;
                        }
                        if (unitdetails.SectionData.ValueData.Select(p => p.Element.ElId == FarmDetails.ConstructionFBObj.EiId).Count() > 1)
                        {
                            List <ValueDatas> elmnts = new List <ValueDatas>();
                            var ConstructionFBList   = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.ConstructionFBObj.EiId).Select(p => p.Element.ItId).ToList();
                            for (int i = 0; i < ConstructionFBList.Count(); i++)
                            {
                                ValueDatas vds = new ValueDatas();
                                vds.Element      = new Elements();
                                vds.Element.ElId = 62259;
                                vds.Element.ItId = ConstructionFBList[i];
                                vds.Value        = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.ConstructionFBObj.EiId && p.Element.ItId == ConstructionFBList[i]).Select(p => p.Value).FirstOrDefault();
                                elmnts.Add(vds);
                            }
                            FarmDetails.ConstructionFBObjList = elmnts;
                        }
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == FarmDetails.ContaincoolroomObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.ContaincoolroomObj.EiId).Select(p => p.Value).FirstOrDefault();
                        if (val != null)
                        {
                            FarmDetails.ContaincoolroomObj.Coolroom = true;
                        }
                        else
                        {
                            FarmDetails.ContaincoolroomObj.Coolroom = false;
                        }
                        if (unitdetails.SectionData.ValueData.Select(p => p.Element.ElId == FarmDetails.ContaincoolroomObj.EiId).Count() > 1)
                        {
                            List <ValueDatas> elmnts  = new List <ValueDatas>();
                            var ContaincoolroomFBList = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.ContaincoolroomObj.EiId).Select(p => p.Element.ItId).ToList();
                            for (int i = 0; i < ContaincoolroomFBList.Count(); i++)
                            {
                                ValueDatas vds = new ValueDatas();
                                vds.Element      = new Elements();
                                vds.Element.ElId = 62261;
                                vds.Element.ItId = ContaincoolroomFBList[i];
                                vds.Value        = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.ContaincoolroomObj.EiId && p.Element.ItId == ContaincoolroomFBList[i]).Select(p => p.Value).FirstOrDefault();
                                elmnts.Add(vds);
                            }
                            FarmDetails.ContaincoolroomFBObjList = elmnts;
                        }
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == FarmDetails.SuminsuredFBObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.SuminsuredFBObj.EiId).Select(p => p.Value).FirstOrDefault();
                        if (val != null && !string.IsNullOrEmpty(val))
                        {
                            FarmDetails.SuminsuredFBObj.Suminsured = val;
                        }
                        if (unitdetails.SectionData.ValueData.Select(p => p.Element.ElId == FarmDetails.SuminsuredFBObj.EiId).Count() > 1)
                        {
                            List <ValueDatas> elmnts = new List <ValueDatas>();
                            var SuminsuredFBList     = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.SuminsuredFBObj.EiId).Select(p => p.Element.ItId).ToList();
                            for (int i = 0; i < SuminsuredFBList.Count(); i++)
                            {
                                ValueDatas vds = new ValueDatas();
                                vds.Element      = new Elements();
                                vds.Element.ElId = 62263;
                                vds.Element.ItId = SuminsuredFBList[i];
                                vds.Value        = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.SuminsuredFBObj.EiId && p.Element.ItId == SuminsuredFBList[i]).Select(p => p.Value).FirstOrDefault();
                                elmnts.Add(vds);
                            }
                            FarmDetails.SuminsuredFBObjList = elmnts;
                        }
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == FarmDetails.ExcessFBObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.ExcessFBObj.EiId).Select(p => p.Value).FirstOrDefault();
                        FarmDetails.ExcessFBObj.Excess = val;
                    }
                    if (unitdetails.ProfileData.ValueData.Exists(p => p.Element.ElId == FarmDetails.FarmsizeObj.EiId))
                    {
                        string val = unitdetails.ProfileData.ValueData.Where(p => p.Element.ElId == FarmDetails.FarmsizeObj.EiId).Select(p => p.Value).FirstOrDefault();
                        FarmDetails.FarmsizeObj.Farmsize = val;
                    }
                    if (unitdetails.ProfileData.ValueData.Exists(p => p.Element.ElId == FarmDetails.TypeoffarmObj.EiId))
                    {
                        string val = unitdetails.ProfileData.ValueData.Where(p => p.Element.ElId == FarmDetails.TypeoffarmObj.EiId).Select(p => p.Value).FirstOrDefault();
                        FarmDetails.TypeoffarmObj.typeoffarm = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == FarmDetails.ExcesshcFSObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.ExcesshcFSObj.EiId).Select(p => p.Value).FirstOrDefault();
                        FarmDetails.ExcesshcFSObj.Excess = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == FarmDetails.ExcesshcHCObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.ExcesshcHCObj.EiId).Select(p => p.Value).FirstOrDefault();
                        FarmDetails.ExcesshcHCObj.Excess = val;
                    }
                    //if (unitdetails.ProfileData.ValueData.Exists(p => p.Element.ElId == FarmDetails.ExcesshcObjH.EiId))
                    //{
                    //    string val = unitdetails.ProfileData.ValueData.Where(p => p.Element.ElId == FarmDetails.ExcesshcObjH.EiId).Select(p => p.Value).FirstOrDefault();
                    //    FarmDetails.ExcesshcObjH.Excess = val;
                    //}
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == FarmDetails.OtherstructurefcObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.OtherstructurefcObj.EiId).Select(p => p.Value).FirstOrDefault();
                        FarmDetails.OtherstructurefcObj.Otherstructure = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == FarmDetails.PartynameObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.PartynameObj.EiId).Select(p => p.Value).FirstOrDefault();
                        if (val != null && !string.IsNullOrEmpty(val))
                        {
                            FarmDetails.PartynameObj.Name = val;
                        }
                        if (unitdetails.SectionData.ValueData.Select(p => p.Element.ElId == FarmDetails.PartynameObj.EiId).Count() > 1)
                        {
                            List <ValueDatas> elmnts = new List <ValueDatas>();
                            var PartynameFBList      = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.PartynameObj.EiId).Select(p => p.Element.ItId).ToList();
                            for (int i = 0; i < PartynameFBList.Count(); i++)
                            {
                                ValueDatas vds = new ValueDatas();
                                vds.Element      = new Elements();
                                vds.Element.ElId = 62345;
                                vds.Element.ItId = PartynameFBList[i];
                                vds.Value        = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.PartynameObj.EiId && p.Element.ItId == PartynameFBList[i]).Select(p => p.Value).FirstOrDefault();
                                elmnts.Add(vds);
                            }
                            FarmDetails.PartynameObjList = elmnts;
                        }
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == FarmDetails.PartylocationObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.PartylocationObj.EiId).Select(p => p.Value).FirstOrDefault();
                        if (val != null && !string.IsNullOrEmpty(val))
                        {
                            FarmDetails.PartylocationObj.Location = val;
                        }
                        if (unitdetails.SectionData.ValueData.Select(p => p.Element.ElId == FarmDetails.PartylocationObj.EiId).Count() > 1)
                        {
                            List <ValueDatas> elmnts = new List <ValueDatas>();
                            var PartylocationFBList  = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.PartylocationObj.EiId).Select(p => p.Element.ItId).ToList();
                            for (int i = 0; i < PartylocationFBList.Count(); i++)
                            {
                                ValueDatas vds = new ValueDatas();
                                vds.Element      = new Elements();
                                vds.Element.ElId = 62347;
                                vds.Element.ItId = PartylocationFBList[i];
                                vds.Value        = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.PartylocationObj.EiId && p.Element.ItId == PartylocationFBList[i]).Select(p => p.Value).FirstOrDefault();
                                elmnts.Add(vds);
                            }
                            FarmDetails.PartylocationObjList = elmnts;
                        }
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == FarmDetails.RoofwallsObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.RoofwallsObj.EiId).Select(p => p.Value).FirstOrDefault();
                        FarmDetails.RoofwallsObj.Roofwalls = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == FarmDetails.SublimitObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.SublimitObj.EiId).Select(p => p.Value).FirstOrDefault();
                        FarmDetails.SublimitObj.Sublimit = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == FarmDetails.SuminsuredhcObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.SuminsuredhcObj.EiId).Select(p => p.Value).FirstOrDefault();
                        FarmDetails.SuminsuredhcObj.Suminsured = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == FarmDetails.TotalcoverObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.TotalcoverObj.EiId).Select(p => p.Value).FirstOrDefault();
                        FarmDetails.TotalcoverObj.Totalcover = val;
                    }
                    if (unitdetails.SectionData.ValueData.Exists(p => p.Element.ElId == FarmDetails.UnrepaireddamageObj.EiId))
                    {
                        string val = unitdetails.SectionData.ValueData.Where(p => p.Element.ElId == FarmDetails.UnrepaireddamageObj.EiId).Select(p => p.Value).FirstOrDefault();
                        FarmDetails.UnrepaireddamageObj.Unrepaireddamage = val;
                    }
                }
            }
            if (cid != null && cid.HasValue && cid > 0)
            {
                FarmDetails.CustomerId = cid.Value;
            }
            if (PcId != null && PcId > 0)
            {
                FarmDetails.PcId = PcId;
            }
            Session["Controller"] = "FarmPolicyProperty";
            Session["ActionName"] = "FarmDetails";
            return(View(FarmDetails));
        }
示例#16
0
        public async Task <string> RenderSummary()
        {
            string crpName = string.Empty;

            Utility.SoilTestConversions stc = new SoilTestConversions(_ud, _sd);

            ReportSummaryViewModel rvm = new ReportSummaryViewModel();

            rvm.testMethod = string.IsNullOrEmpty(_ud.FarmDetails().testingMethod) ? "Not Specified" : _sd.GetSoilTestMethod(_ud.FarmDetails().testingMethod);
            rvm.year       = _ud.FarmDetails().year;

            FarmDetails fd = _ud.FarmDetails();

            rvm.tests = new List <ReportSummaryTest>();

            List <Field> flds = _ud.GetFields();

            foreach (var m in flds)
            {
                ReportSummaryTest dc = new ReportSummaryTest();
                dc.fieldName = m.fieldName;
                if (m.soilTest != null)
                {
                    dc.sampleDate       = m.soilTest.sampleDate.ToString("MMM-yyyy");
                    dc.nitrogen         = m.soilTest.valNO3H.ToString();
                    dc.phosphorous      = m.soilTest.ValP.ToString();
                    dc.potassium        = m.soilTest.valK.ToString();
                    dc.pH               = m.soilTest.valPH.ToString();
                    dc.phosphorousRange = _sd.SoilTestRating("phosphorous", stc.GetConvertedSTP(m.soilTest));
                    dc.potassiumRange   = _sd.SoilTestRating("potassium", stc.GetConvertedSTK(m.soilTest));
                }
                else
                {
                    DefaultSoilTest dt = _sd.GetDefaultSoilTest();
                    SoilTest        st = new SoilTest();
                    st.valPH             = dt.pH;
                    st.ValP              = dt.phosphorous;
                    st.valK              = dt.potassium;
                    st.valNO3H           = dt.nitrogen;
                    st.ConvertedKelownaP = dt.convertedKelownaP;
                    st.ConvertedKelownaK = dt.convertedKelownaK;

                    dc.sampleDate       = "Default Values";
                    dc.nitrogen         = dt.nitrogen.ToString();
                    dc.phosphorous      = dt.phosphorous.ToString();
                    dc.potassium        = dt.potassium.ToString();
                    dc.pH               = dt.pH.ToString();
                    dc.phosphorousRange = _sd.SoilTestRating("phosphorous", stc.GetConvertedSTP(st));
                    dc.potassiumRange   = _sd.SoilTestRating("potassium", stc.GetConvertedSTK(st));
                }
                dc.fieldCrops = null;

                List <FieldCrop> crps = _ud.GetFieldCrops(m.fieldName);
                if (crps != null)
                {
                    foreach (var c in crps)
                    {
                        crpName       = string.IsNullOrEmpty(c.cropOther) ? _sd.GetCrop(Convert.ToInt32(c.cropId)).cropname : c.cropOther;
                        dc.fieldCrops = string.IsNullOrEmpty(dc.fieldCrops) ? crpName : dc.fieldCrops + "\n" + crpName;
                    }
                }
                rvm.tests.Add(dc);
            }


            var result = await _viewRenderService.RenderToStringAsync("~/Views/Report/ReportSummary.cshtml", rvm);

            return(result);
        }