public ActionResult Step1(Company company, int?edit) { if (Session["userId"] == null || Session["userId"].ToString() == "") { return(RedirectToAction("UserLogin", "Login")); } string type; if (edit != 1) { GeneratesCode gc = new GeneratesCode(); _comCode = company.CompanyCode = gc.GenerateCompanyCode(company.CompanyName); type = "INSERT"; } else { company.CompanyCode = _comCode; type = "UPDATE"; } // company.Zip = company.ZipPre; if (company.Extension != null) { company.Zip += "-" + company.Extension; } company.CreatedBy = company.FirstSuperAdminId = Convert.ToInt32(Session["userId"]); company.CompanyStatus = true; CompanyAccess ca = new CompanyAccess(); //check this record is new one or exitsting one //string type = (edit == 1) ? "UPDATE" : "INSERT"; int companyId = ca.InsertCompany(company, type); if (companyId > 0) { ViewBag.SuccessMsg = "Company Successfully setup."; CompanyType = (company.TypeId == 1) ? "Lender" : "Dealer"; //If succeed update step table to step2 StepAccess sa = new StepAccess(); sa.updateStepNumberByUserId(company.FirstSuperAdminId, 2); //Send company detail to step 2 CompanyBranchModel comBranch = new CompanyBranchModel(); comBranch.Company = company; TempData["Company"] = comBranch; return(RedirectToAction("Step2")); } ViewBag.ErrorMsg = "Failed to Setup company."; // Get company types to list List <CompanyType> ctList = ca.GetAllCompanyType(); ViewBag.TypeId = new SelectList(ctList, "TypeId", "TypeName"); //Get states to list List <State> stateList = ca.GetAllStates(); ViewBag.StateId = new SelectList(stateList, "StateId", "StateName"); return(View()); }
/// <summary> /// Insert a company in the database, /// /// </summary> /// <param name="userId"></param> /// <param name="company"></param> /// <returns></returns> public int InsertCompany(uint userId, Company company) { company.Ticker = company.Ticker.ToUpper(); var err_code = CanBeInsertedInCompanies(company); List <string> ratioList = new List <string>(); List <string> incomeList = new List <string>(); bool companyFlag = false; bool ratioFlag = false; bool incomeFlag = false; //can be inserted if (err_code == 000) { var err_code_2 = csvHelper.DownloadCsvFiles(company.Ticker); if (err_code_2 != 000) { err_code = err_code_2; } else { //true to have indentation and false for no indentation csvHelper.KeyRatiosCsvToXml(company.Ticker, true); // This code is commented since Income Statement Files of companies have not all the same structure //csvHelper.IncomeStatementsCsvToXml(company.Ticker, true); companyFlag = false; for (int year = 2006; year < 2016; year++) { ratioList = csvHelper.ReadKeyRatiosXmlFile(company.Ticker, year.ToString()); ratioList.Insert(0, year.ToString()); if (year > 2006) { ratioFlag = true; } else { ratioFlag = false; } company.Name = csvHelper.GetCompanyName(company.Ticker, 0); company.Sector = "Unknown"; company.Currency = csvHelper.GetCompanyCurrency(company.Ticker); companyAccess.InsertCompany(userId, company, ratioList, incomeList, companyFlag, ratioFlag, incomeFlag); } // This code is commented since Income Statement Files of companies have not all the same structure /* * for (int year = 2010; year < 2016; year++) * { * incomeList = csvHelper.ReadIncomeStatementsXmlFile(company.Ticker, year.ToString()); * incomeList.Insert(0, year.ToString()); * incomeFlag = true; * companyAccess.InsertCompany(userId, company, ratioList, incomeList, companyFlag, ratioFlag, incomeFlag); * }*/ } } else { err_code = CanBeInsertedInUserCompanies(userId, company); if (err_code == 000) { company = companyAccess.SelectCompanyByTicker(company.Ticker); company.Name = csvHelper.GetCompanyName(company.Ticker, 0); company.Sector = "Unknown"; company.Currency = csvHelper.GetCompanyCurrency(company.Ticker); companyFlag = true; companyAccess.InsertCompany(userId, company, ratioList, incomeList, companyFlag, ratioFlag, incomeFlag); } } return(err_code); }