public ApplicationSetupViewModel Setup(ApplicationSetupViewModel appSetupVm, VirtualCityApp vcApp)
 {
     string serverName, dbName;
     appSetupVm.DatabaseExists = _applicationSetup.DatabaseExists(out serverName, out dbName);
     appSetupVm.DatabaseName = dbName;
     appSetupVm.DatabaseServer = serverName;
     appSetupVm.CompanyIsSetup = _applicationSetup.CompanyIsSetup(vcApp);
     appSetupVm.userType = (vcApp == VirtualCityApp.Agrimanagr ? UserType.AgriHQAdmin : UserType.HQAdmin);
    
     return appSetupVm;
 }
        public bool CreateCompanyAndSuperAdmin(ApplicationSetupViewModel appSetupVm)
        {

            using (TransactionScope scope = TransactionUtils.CreateTransactionScope())
            {
                appSetupVm.CompanyId = _applicationSetup.RegisterCompay(appSetupVm.CompanyName);
                if (appSetupVm.CompanyId == Guid.Empty)
                    throw new DomainValidationException(new ValidationResultInfo(),
                                                        "Unable to create company " + appSetupVm.CompanyName);
                if (appSetupVm.userType == UserType.HQAdmin)
                {
                    User admin = new User(Guid.NewGuid())
                                     {
                                         Username = "******",
                                         Password = EncryptorMD5.GetMd5Hash(appSetupVm.AdminPassword),
                                         Mobile = appSetupVm.Mobile,
                                         PIN = appSetupVm.Pin,
                                         UserType = appSetupVm.userType,
                                         CostCentre = appSetupVm.CompanyId,
                                     };
                    if (_applicationSetup.RegisterSuperAdmin(admin))
                    {
                        scope.Complete();
                        return true;
                    }
                }
                if (appSetupVm.userType == UserType.AgriHQAdmin)
                {
                    
                    User admin = new User(Guid.NewGuid())
                    {
                        Username = "******",
                        Password = EncryptorMD5.GetMd5Hash(appSetupVm.AdminPassword),
                        Mobile = appSetupVm.Mobile,
                        PIN = appSetupVm.Pin,
                        UserType = appSetupVm.userType,
                        CostCentre = appSetupVm.CompanyId,
                    };
                    if (_applicationSetup.RegisterSuperAdmin(admin))
                    {
                        scope.Complete();
                        return true;
                    }
                }
                return false;
            }
        }
예제 #3
0
 public ActionResult RegisterCompany(ApplicationSetupViewModel model)
 {
     try
     {
         model.userType = UserType.AgriHQAdmin;
         if (_applicationSetupViewModelBuilder.CreateCompanyAndSuperAdmin(model))
             return RedirectToAction("Login");
     }
     catch (DomainValidationException dve)
     {
         ValidationSummary.DomainValidationErrors(dve, ModelState);
         return View(model);
     }
     catch (Exception exx)
     {
         ViewBag.msg = exx.Message;
         return View(model);
     }
     return null;
 }