Esempio n. 1
0
        public ActionResult ConstructCompany(ConstructCompanyViewModel vm)
        {
            var country = countryRepository.GetById(vm.CountryID);
            var entity  = SessionHelper.CurrentEntity;
            var citizen = SessionHelper.LoggedCitizen;

            if (ModelState.IsValid)
            {
                MethodResult result;
                var          region = regionRepository.GetById(vm.RegionID);
                if ((result = countryService.CanCreateCountryCompany(vm.CompanyName, entity, country, citizen, region, (ProductTypeEnum)vm.ProductID)).IsError)
                {
                    AddError(result);
                }
                else
                {
                    Company company;
                    using (var scope = transactionScopeProvider.CreateTransactionScope())
                    {
                        company = companyService.CreateCompanyForCountry(vm.CompanyName, (ProductTypeEnum)vm.ProductID, vm.RegionID, country);
                        companyService.AddManager(company, citizen, CompanyRights.FullRgihts);

                        scope?.Complete();
                    }
                    AddSuccess("Company has been created successfully!");
                    return(RedirectToAction("View", "Company", new { companyID = company.ID }));
                }
            }

            vm = new ConstructCompanyViewModel(country, regionRepository, walletService, countryTreasureService);
            return(View(vm));
        }
Esempio n. 2
0
        public ActionResult ConstructCompany(int countryID)
        {
            var entity  = SessionHelper.CurrentEntity;
            var citizen = SessionHelper.LoggedCitizen;
            var country = countryRepository.GetById(countryID);

            MethodResult result;

            if ((result = countryService.CanCreateCountryCompany(entity, country, citizen)).IsError)
            {
                return(RedirectBackWithError(result));
            }

            var vm = new ConstructCompanyViewModel(country, regionRepository, walletService, countryTreasureService);

            return(View(vm));
        }