public ActionResult PendingBene(ConnectCarePendingBenePage page) { try { ServiceReference1.ArrayOfBeneficiarydata receive = serv.RECVBENDTLS(); //var shii = receive[6]; foreach (ServiceReference1.beneficiarydata shii in receive) { ConnectCareBeneficiary benefit = new ConnectCareBeneficiary(); string sponsorid = shii.sponsorid.Split('-').Last(); int sponsoridint = 0; int.TryParse(sponsorid, out sponsoridint); ConnectCareSponsor sponsordetails = _helperSvc.GetSponsor(sponsoridint); IList <ConnectCareBeneficiary> beneList = _helperSvc.GetBeneficiariesBySponsorID(sponsoridint); bool exist = beneList.Where(x => x.dob == shii.dateofbirth).Where(x => x.fullname.Contains(shii.fullname)).Any(); if (!exist && sponsordetails != null) { benefit.sponsorid = sponsordetails.Id; benefit.sponsoridstring = sponsordetails.sponsorSTRID; benefit.firstname = shii.fullname.Split(' ')[0]; benefit.lastname = shii.fullname.Split(' ')[1]; benefit.fullname = shii.fullname; benefit.gender = shii.gender; benefit.PolicyNumber = sponsordetails.policynumber + "-" + (beneList.Count() + 1).ToString(); benefit.Category = shii.category; benefit.dob = shii.dateofbirth; benefit.relationship = shii.relationship; benefit.country = shii.country; benefit.state = shii.state; benefit.city = shii.city; benefit.LGA = shii.lga; benefit.address = string.Empty; benefit.email = shii.email; benefit.phonenumber = shii.phonenumber; benefit.GuardianEmail = shii.guardianemail; benefit.GuardianPhonenumber = shii.guardianphone; benefit.suggestedPlan = string.Empty; benefit.SuggestedProvider = string.Empty; benefit.VerificationStatus = false;; benefit.addon = true; _helperSvc.addBeneficiary(benefit); benefit.BeneficiaryID = "NHACCB-" + benefit.Id.ToString(); //update the beneficiary id _helperSvc.addBeneficiary(benefit); } } ViewBag.exported = receive; } catch (Exception ex) { _pageMessageSvc.SetErrormessage("There was an error connecting to Matontine Server.Please try again."); } return(View(page)); }