public ActionResult uploaddata(LoginViewModel lvm, FormCollection form) { try { UvlotAEntities db = new UvlotAEntities(); //string refNumber = MyUtility.GenerateRefNo(); DataTable dt = (DataTable)Session["myDtVal"]; DataReader dr = new DataReader(); GetMenus(); foreach (DataRow row in dt.Rows) { try { // LoanApplication inst = new LoanApplication(); if (row["SURNAME"] != null) { if (row["SURNAME"].ToString().Length < 2 && row["FIRST NAME"].ToString().Length < 2) { break; } } LoanApplication instObj = new LoanApplication(); instObj.AccomodationType_FK = dr.GetAccomType(row["ACCOMMODATION TYPE"].ToString()); instObj.AccountName = row["ACCOUNT NAME"].ToString(); instObj.AccountNumber = row["ACCOUNT NUMBER"].ToString(); instObj.ApplicantID = row["MEANS OF ID"].ToString(); instObj.ApplicationStatus_FK = 3;//Pending status, instObj.BVN = row["BANK VERIFICATION NUMBER"].ToString(); instObj.ClosestBusStop = row["CLOSEST BUSTOP"].ToString(); string DOB = row["DATE OF BIRTH"].ToString(); instObj.ContactAddress = row["HOME ADDRESS"].ToString(); instObj.CreatedBy = ""; //Change To User ID instObj.DateCreated = MyUtility.getCurrentLocalDateTime(); instObj.DateModified = MyUtility.getCurrentLocalDateTime(); instObj.DateOfBirth = DOB;// Helper.isDate(DOB) == true ? Convert.ToDateTime(DOB) : MyUtility.getCurrentLocalDateTime(); instObj.EmailAddress = row["PERSONAL EMAIL"].ToString(); instObj.ExistingLoan = row["ANY EXISTING LOAN"].ToString().ToUpper() == "YES" ? true : false; instObj.ExistingLoan_NoOfMonthsLeft = 0; instObj.ExistingLoan_OutstandingAmount = 0; instObj.Firstname = row["FIRST NAME"].ToString(); instObj.Gender_FK = row["GENDER"].ToString().ToUpper() == "MALE" ? 1 : 2; instObj.IdentficationNumber = row["IDENTIFICATION NUMBER"].ToString(); instObj.Landmark = row["LANDMARK"].ToString(); instObj.LGA_FK = dr.GetLocalGovt(row["LGA"].ToString()); instObj.LoanAmount = Convert.ToDouble(row["LOAN AMOUNT"]); instObj.LoanComment = ""; instObj.LoanRefNumber = MyUtility.GenerateRefNo(); instObj.MaritalStatus_FK = dr.GetStatus(row["MARITAL STATUS"].ToString()); instObj.BankCode = Convert.ToString(dr.GetBankCode(row["BANK NAME"].ToString().Trim())); instObj.MeansOfID_FK = dr.GetMeansofIdbyname(row["MEANS OF ID"].ToString()); instObj.NOK_EmailAddress = row["NOK_EMAIL ADDRESS"].ToString(); instObj.NOK_FullName = row["NOK_NAME"].ToString(); instObj.NOK_HomeAddress = row["NOK_HOME ADDRESS"].ToString(); instObj.NOK_PhoneNumber = row["NOK_PHONE"].ToString(); instObj.NOK_Relationship = row["NOK_RELATIONSHIP"].ToString(); instObj.Organization = row["EMPLOYER"].ToString(); instObj.Othernames = ""; instObj.PhoneNumber = row["MOBILE NUMBER"].ToString(); instObj.Institution_FK = dr.GetInstitution(row["INSTITUTION"].ToString()); instObj.RepaymentMethod_FK = 0; instObj.StateofResidence_FK = dr.GetState(row["STATE OF RESIDENCE"].ToString()); instObj.Surname = row["SURNAME"].ToString(); instObj.Title_FK = dr.GetTitleIDByName(row["TITLE"].ToString()); instObj.IsVisible = 1; instObj.ValueDate = MyUtility.getCurrentLocalDateTime().ToString("yyyy/MM/dd"); instObj.ValueTime = MyUtility.getCurrentLocalDateTime().ToString("H:mmss"); db.LoanApplications.Add(instObj); db.SaveChanges(); EmployerLoanDetail empObj = new EmployerLoanDetail(); empObj.ClosestBusStop = row["CLOSEST BUSTOP"].ToString(); empObj.DateCreated = MyUtility.getCurrentLocalDateTime(); empObj.DateModified = MyUtility.getCurrentLocalDateTime(); empObj.Department = row["DEPARTMENT"].ToString(); empObj.Designation = row["DESIGNATION"].ToString(); empObj.EmployerID = row["EMPLOYEE ID"].ToString(); empObj.EmploymentStatus_FK = dr.GetEmpoStatus(row["EMPLOYMENT STATUS"].ToString()); empObj.IsVisible = 1; empObj.LandMark = row["LANDMARK"].ToString(); var loss = row["LENGTH OF SERVICE WITH CURRENT EMPLOYER"].ToString(); int los = Helper.isNumeric(loss) == true?Convert.ToInt16(loss) : 0; empObj.LengthOfServiceInMth = los; empObj.LGA_FK = row["LGA"].ToString(); empObj.NetMonthlyIncome = Convert.ToDouble(row["NET MONTHLY INCOME"]); empObj.Occupation = row["OCCUPATION"].ToString(); empObj.OfficialEmailAddress = row["EMAIL"].ToString(); empObj.ValueDate = MyUtility.getCurrentLocalDateTime().ToString("yyyy/MM/dd"); empObj.ValueTime = MyUtility.getCurrentLocalDateTime().ToString("H:mmss"); empObj.LoanApplication_FK = instObj.ID; db.EmployerLoanDetails.Add(empObj); db.SaveChanges(); LoanLedger lonObj = new LoanLedger(); lonObj.ApplicantID = row["EMPLOYEE ID"].ToString(); lonObj.Credit = 0; lonObj.Debit = 0; lonObj.Institution_FK = instObj.Institution_FK; lonObj.IsVisible = 1; lonObj.LastUpdated = MyUtility.getCurrentLocalDateTime(); lonObj.RefNumber = instObj.LoanRefNumber; lonObj.PartnerRefNumber = ""; lonObj.TranxDate = MyUtility.getCurrentLocalDateTime(); lonObj.ValueDate = MyUtility.getCurrentLocalDateTime().ToString("yyyy/MM/dd"); lonObj.ValueTime = MyUtility.getCurrentLocalDateTime().ToString("H:mmss"); db.LoanLedgers.Add(lonObj); db.SaveChanges(); //DataWriter.CreateLoanApplication(instObj); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); //raise a new exception inserting the current one as the InnerException raise = new InvalidOperationException(message, raise); } } WebLog.Log(raise); } } } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); //raise a new exception inserting the current one as the InnerException raise = new InvalidOperationException(message, raise); } } WebLog.Log(raise); } return(View("ImportExcel1")); }