Exemple #1
0
        public ActionResult Create(MainApplication mainapp)
        {
            //DatabaseName = "RetailManagement1";
            //CompanyName = "RetailManagement1";
            //FinancialYear = "RetailManagement1";
            DatabaseName  = "A2ZRetail";
            CompanyName   = "A2ZRetail";
            FinancialYear = "A2ZRetail";
            Int32 sid   = Convert.ToInt32(mainapp.companydetails.State);
            var   state = _stateservice.GetStateNamebyId(sid);
            Int32 cid   = Convert.ToInt32(mainapp.companydetails.City);
            var   city  = _cityservice.GetCityNamebyId(cid);

            mainapp.companydetails.State      = state;
            mainapp.companydetails.City       = city;
            mainapp.companydetails.Replicated = "No";
            mainapp.companydetails.isEnabled  = "Active";
            mainapp.companydetails.ModifiedOn = DateTime.Now;
            if (mainapp.compbankdetails.BankName != null)
            {
                mainapp.compbankdetails.CompanyCode = mainapp.companydetails.CompanyCode;
                mainapp.compbankdetails.Status      = "Active";
                mainapp.compbankdetails.ModifiedOn  = DateTime.Now;
                _compbankservice.CreateCompanyBankDetails(mainapp.compbankdetails);
            }

            var CompaniesCounter = _companyService.GetCompanyCounter("ValidationCompany");
            int compcount        = 0;

            foreach (var company in CompaniesCounter)
            {
                if (company.CompanyName == mainapp.companydetails.companyName)
                {
                    compcount++;
                }
            }

            if (compcount != 0 || CompaniesCounter.Count() < 4)
            {
                _companyService.CreateCompany(mainapp.companydetails);
                string BackUpDbQuery = "BackUpDatabase";
                _companyService.BackUpDatabase(BackUpDbQuery);

                string dbname            = string.Empty;
                string datafilepath      = string.Empty;
                string logfilepath       = string.Empty;
                string FromFinancialYear = Convert.ToDateTime(mainapp.companydetails.FinancialYearFrom).ToString("dd-MM-yyyy");
                string ToFinancialYear   = Convert.ToDateTime(mainapp.companydetails.FinancialYearTo).ToString("dd-MM-yyyy");
                string FinancialYearDate = FromFinancialYear + " To " + ToFinancialYear;
                dbname       = mainapp.companydetails.companyName + " " + FinancialYearDate;
                datafilepath = ConfigurationManager.AppSettings["CreateDatabase.mdfFile"].ToString() + dbname + ".mdf";
                logfilepath  = ConfigurationManager.AppSettings["CreateDatabase.ldfFile"].ToString() + dbname + "_log.ldf";

                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@dbname", dbname),
                    new SqlParameter("@datafilepath", datafilepath),
                    new SqlParameter("@logfilepath", logfilepath),
                };
                string           query         = "CreateDynamicDb" + " " + "@dbname" + "," + "@datafilepath" + "," + "@logfilepath";
                var              list          = _companyService.CreateDynamicDatabase(query, para);
                var              usercompanies = _userService.GetUserByName((string)HttpContext.Session["UserName"]);
                EmployeesCompany EmpComp       = new EmployeesCompany();
                EmpComp.UserCode    = usercompanies.UserCode;
                EmpComp.CompanyCode = mainapp.companydetails.CompanyCode;
                _EmployeesCompanyService.Create(EmpComp);

                var    details = _companyService.getLastInsertedCompany();
                string compid  = Encode(details.companyId.ToString());
                return(RedirectToAction("Details/" + compid, "Company"));
            }
            else
            {
                TempData["CompanyExceed"] = "CompanyExceeded";
                return(RedirectToAction("ReloadCompany"));
            }
        }