public void Order() { RememberCurrentStatus(PackageStatus.New); PackageResult result = PackageController.AddPackage( UserInfo.UserId, Convert.ToInt32(ServiceSettings[HOSTING_PLAN]), String.Format("My Space ({0})", UserInfo.Username), String.Empty, Convert.ToInt32(ServiceSettings[INITIAL_STATUS]), DateTime.Now, true ); // throws an exception if (result.Result <= 0) { throw new Exception("Couldn't add package to the user: " + UserInfo.Username); } ServiceSettings[PACKAGE_ID] = result.Result.ToString(); // update user details if (!String.IsNullOrEmpty(ServiceSettings[USER_ROLE])) { UserInfo.Role = (UserRole)Enum.Parse(typeof(UserRole), ServiceSettings[USER_ROLE]); } if (!String.IsNullOrEmpty(ServiceSettings[USER_STATUS])) { UserInfo.Status = (UserStatus)Enum.Parse(typeof(UserStatus), ServiceSettings[USER_STATUS]); } UserController.UpdateUser(UserInfo); }
private void Save_Click(object sender, RoutedEventArgs e) { var pkg = new PackageDto(Guid.NewGuid()); pkg.Name = package.PackageName; pkg.Description = package.PackageDescription; _controller.AddPackage(pkg); //_router.GoTo(new PackageIndexRoute()); }
/// ----------------------------------------------------------------------------- /// <summary> /// wizNewExtension_NextButtonClick when the next Button is clicked. It provides /// a mechanism for cancelling the page change if certain conditions aren't met. /// </summary> /// <remarks> /// </remarks> /// <history> /// [cnurse] 08/25/2008 created /// </history> /// ----------------------------------------------------------------------------- protected void wizNewExtension_NextButtonClick(object sender, WizardNavigationEventArgs e) { switch (e.CurrentStepIndex) { case 0: if (extensionForm.IsValid) { var newPackage = extensionForm.DataSource as PackageInfo; PackageInfo tmpPackage = PackageController.GetPackageByName(newPackage.Name); if (tmpPackage == null) { switch (Mode) { case "All": newPackage.PackageType = cboExtensionType.SelectedValue; break; default: newPackage.PackageType = Mode; break; } PackageID = PackageController.AddPackage(newPackage, true); } else { e.Cancel = true; lblError.Text = string.Format(Localization.GetString("DuplicateName", LocalResourceFile), newPackage.Name); lblError.Visible = true; } } if (PackageEditor != null && PackageID > Null.NullInteger) { BindPackageEditor(); } break; case 1: if (PackageEditor != null) { PackageEditor.UpdatePackage(); } break; case 2: if (ownerForm.IsValid) { PackageController.SavePackage(ownerForm.DataSource as PackageInfo); } Response.Redirect(Globals.NavigateURL(), true); break; } }
public PackageResult AddPackage(int userId, int planId, string packageName, string packageComments, int statusId, DateTime purchaseDate) { return(PackageController.AddPackage(userId, planId, packageName, packageComments, statusId, purchaseDate, true)); }
public int CreateUserAccountInternal(int parentPackageId, string username, string password, int roleId, string firstName, string lastName, string email, string secondaryEmail, bool htmlMail, bool sendAccountLetter, bool createPackage, int planId, bool sendPackageLetter, string domainName, bool tempDomain, bool createWebSite, bool createFtpAccount, string ftpAccountName, bool createMailAccount, string hostName, bool createZoneRecord) { // check account int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive | DemandAccount.IsReseller); if (accountCheck < 0) { return(accountCheck); } // check package int packageCheck = SecurityContext.CheckPackage(parentPackageId, DemandPackage.IsActive); if (packageCheck < 0) { return(packageCheck); } // check if username exists if (UserController.UserExists(username)) { return(BusinessErrorCodes.ERROR_ACCOUNT_WIZARD_USER_EXISTS); } // check if domain exists int checkDomainResult = ServerController.CheckDomain(domainName); if (checkDomainResult < 0) { return(checkDomainResult); } // check if FTP account exists if (String.IsNullOrEmpty(ftpAccountName)) { ftpAccountName = username; } if (FtpServerController.FtpAccountExists(ftpAccountName)) { return(BusinessErrorCodes.ERROR_ACCOUNT_WIZARD_FTP_ACCOUNT_EXISTS); } // load parent package PackageInfo parentPackage = PackageController.GetPackage(parentPackageId); /******************************************** * CREATE USER ACCOUNT * *****************************************/ UserInfo user = new UserInfo(); user.RoleId = roleId; user.StatusId = (int)UserStatus.Active; user.OwnerId = parentPackage.UserId; user.IsDemo = false; user.IsPeer = false; // account info user.FirstName = firstName; user.LastName = lastName; user.Email = email; user.SecondaryEmail = secondaryEmail; user.Username = username; // user.Password = password; user.HtmlMail = htmlMail; // add a new user createdUserId = UserController.AddUser(user, false, password); if (createdUserId < 0) { // exit return(createdUserId); } userCreated = true; // create package // load hosting plan createdPackageId = -1; if (createPackage) { try { HostingPlanInfo plan = PackageController.GetHostingPlan(planId); PackageResult packageResult = PackageController.AddPackage( createdUserId, planId, plan.PlanName, "", (int)PackageStatus.Active, DateTime.Now, false); createdPackageId = packageResult.Result; } catch (Exception ex) { // error while adding package // remove user account UserController.DeleteUser(createdUserId); throw ex; } if (createdPackageId < 0) { // rollback wizard Rollback(); // return code return(createdPackageId); } // create domain int domainId = 0; if ((createWebSite || createMailAccount || createZoneRecord) && !String.IsNullOrEmpty(domainName)) { try { DomainInfo domain = new DomainInfo(); domain.PackageId = createdPackageId; domain.DomainName = domainName; domain.HostingAllowed = false; domainId = ServerController.AddDomain(domain, false, false); if (domainId < 0) { // rollback wizard Rollback(); // return return(domainId); } } catch (Exception ex) { // rollback wizard Rollback(); // error while adding domain throw new Exception("Could not add domain", ex); } } if (createWebSite && (domainId > 0)) { // create web site try { int webSiteId = WebServerController.AddWebSite( createdPackageId, hostName, domainId, 0, true, false); if (webSiteId < 0) { // rollback wizard Rollback(); // return return(webSiteId); } } catch (Exception ex) { // rollback wizard Rollback(); // error while creating web site throw new Exception("Could not create web site", ex); } } // create FTP account if (createFtpAccount) { try { FtpAccount ftpAccount = new FtpAccount(); ftpAccount.PackageId = createdPackageId; ftpAccount.Name = ftpAccountName; ftpAccount.Password = password; ftpAccount.Folder = "\\"; ftpAccount.CanRead = true; ftpAccount.CanWrite = true; int ftpAccountId = FtpServerController.AddFtpAccount(ftpAccount); if (ftpAccountId < 0) { // rollback wizard Rollback(); // return return(ftpAccountId); } } catch (Exception ex) { // rollback wizard Rollback(); // error while creating ftp account throw new Exception("Could not create FTP account", ex); } } if (createMailAccount && (domainId > 0)) { // create default mailbox try { // load mail policy UserSettings settings = UserController.GetUserSettings(createdUserId, UserSettings.MAIL_POLICY); string catchAllName = !String.IsNullOrEmpty(settings["CatchAllName"]) ? settings["CatchAllName"] : "mail"; MailAccount mailbox = new MailAccount(); mailbox.Name = catchAllName + "@" + domainName; mailbox.PackageId = createdPackageId; // gather information from the form mailbox.Enabled = true; mailbox.ResponderEnabled = false; mailbox.ReplyTo = ""; mailbox.ResponderSubject = ""; mailbox.ResponderMessage = ""; // password mailbox.Password = password; // redirection mailbox.ForwardingAddresses = new string[] { }; mailbox.DeleteOnForward = false; mailbox.MaxMailboxSize = 0; int mailAccountId = MailServerController.AddMailAccount(mailbox); if (mailAccountId < 0) { // rollback wizard Rollback(); // return return(mailAccountId); } // set catch-all account MailDomain mailDomain = MailServerController.GetMailDomain(createdPackageId, domainName); mailDomain.CatchAllAccount = "mail"; mailDomain.PostmasterAccount = "mail"; mailDomain.AbuseAccount = "mail"; MailServerController.UpdateMailDomain(mailDomain); int mailDomainId = mailDomain.Id; } catch (Exception ex) { // rollback wizard Rollback(); // error while creating mail account throw new Exception("Could not create mail account", ex); } } // Preview Domain / Temporary URL if (tempDomain && (domainId > 0)) { int previewDomainId = ServerController.CreateDomainPreviewDomain("", domainId); if (previewDomainId < 0) { // rollback wizard Rollback(); return(previewDomainId); } } // Domain DNS Zone if (createZoneRecord && (domainId > 0)) { ServerController.EnableDomainDns(domainId); } } // send welcome letters if (sendAccountLetter) { int result = PackageController.SendAccountSummaryLetter(createdUserId, null, null, true); if (result < 0) { // rollback wizard Rollback(); // return return(result); } } if (createPackage && sendPackageLetter) { int result = PackageController.SendPackageSummaryLetter(createdPackageId, null, null, true); if (result < 0) { // rollback wizard Rollback(); // return return(result); } } return(createdUserId); }
public GenericSvcResult ActivateService(ProvisioningContext context) { GenericSvcResult result = new GenericSvcResult(); // SaveObjectState(SERVICE_INFO, context.ServiceInfo); // SaveObjectState(CONSUMER_INFO, context.ConsumerInfo); // concretize service to be provisioned HostingPackageSvc packageSvc = (HostingPackageSvc)context.ServiceInfo; // try { // TaskManager.StartTask(SystemTasks.SOURCE_ECOMMERCE, SystemTasks.SVC_ACTIVATE); // LOG INFO TaskManager.Write(START_ACTIVATION_MSG); TaskManager.WriteParameter(USERNAME_PARAM, context.ConsumerInfo[ContractAccount.USERNAME]); TaskManager.WriteParameter(SVC_PARAM, context.ServiceInfo.ServiceName); TaskManager.WriteParameter(SVC_ID_PARAM, context.ServiceInfo.ServiceId); TaskManager.TaskParameters[SystemTaskParams.PARAM_SEND_EMAIL] = context.SendEmail; // 0. Do security checks if (!CheckOperationClientPermissions(result)) { // LOG ERROR TaskManager.WriteError(ERROR_CLIENT_OPERATION_PERMISSIONS); TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode); // EXIT return(result); } // if (!CheckOperationClientStatus(result)) { // LOG ERROR TaskManager.WriteError(ERROR_CLIENT_OPERATION_STATUS); TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode); // EXIT return(result); } // 1. Hosting package is just ordered if (context.ServiceInfo.Status == ServiceStatus.Ordered && context.ContractInfo.CustomerId > 0) { // LOG INFO TaskManager.Write(CREATE_PCKG_MSG); // create new package PackageResult apiResult = PackageController.AddPackage(context.ContractInfo.CustomerId, packageSvc.PlanId, packageSvc.ServiceName, String.Empty, (int)packageSvc.InitialStatus, DateTime.Now, true, true); // failed to instantiate package if (apiResult.Result <= 0) { result.ResultCode = apiResult.Result; // result.Succeed = false; // LOG ERROR TaskManager.WriteError(CREATE_PCKG_ERROR_MSG); TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode); // EXIT return(result); } // save result PackageId packageSvc.PackageId = apiResult.Result; } else // 2. Package requires only to update its status { // LOG INFO TaskManager.Write(START_ACTIVATION_MSG); // int apiResult = PackageController.ChangePackageStatus(packageSvc.PackageId, PackageStatus.Active, false); // if (apiResult < 0) { result.ResultCode = apiResult; // result.Succeed = false; // LOG ERROR TaskManager.WriteError(ERROR_ACTIVATE_PCKG_MSG); TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode); // EXIT return(result); } } // check user role if (context.ContractInfo.CustomerId > 0) { UserInfo user = UserController.GetUserInternally(context.ContractInfo.CustomerId); // check user status // if (user.Status != UserStatus.Active) { // LOG INFO TaskManager.Write(START_USR_ACTIVATION_MSG); // trying to change user status int userResult = UserController.ChangeUserStatus(context.ContractInfo.CustomerId, UserStatus.Active); // failed to activate user account if (userResult < 0) { result.ResultCode = userResult; // result.Succeed = false; // LOG ERROR TaskManager.WriteError(ERROR_USR_ACTIVATION_MSG); TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode); // ROLLBACK CHANGES RollbackOperation(result.ResultCode); // EXIT return(result); } } // check user role if (user.Role != packageSvc.UserRole) { // LOG INFO TaskManager.Write(START_CHANGE_USR_ROLE_MSG); // user.Role = packageSvc.UserRole; // trying to change user role int roleResult = UserController.UpdateUser(user); // failed to change user role if (roleResult < 0) { result.ResultCode = roleResult; // result.Succeed = false; // TaskManager.WriteError(ERROR_CHANGE_USR_ROLE_MSG); TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode); // ROLLBACK CHANGES RollbackOperation(result.ResultCode); // EXIT return(result); } } } // update plan status if necessary if (packageSvc.Status != ServiceStatus.Active) { // change service status to active packageSvc.Status = ServiceStatus.Active; // put data into metabase int svcResult = UpdateServiceInfo(packageSvc); // error updating svc details if (svcResult < 0) { result.ResultCode = svcResult; // result.Succeed = false; // ROLLBACK CHANGES RollbackOperation(packageSvc.PackageId); // LOG ERROR TaskManager.WriteError(ERROR_SVC_UPDATE_MSG); TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode); // EXIT return(result); } } // SetOutboundParameters(context); // LOG INFO TaskManager.Write(PCKG_PROVISIONED_MSG); // result.Succeed = true; } catch (Exception ex) { // TaskManager.WriteError(ex); // ROLLBACK CHANGES RollbackOperation(packageSvc.PackageId); // result.Succeed = false; // result.Error = ex.Message; } finally { // complete task TaskManager.CompleteTask(); } // return(result); }
public void AddPackage_CallsCommandDispatcher() { _controller.AddPackage(_package); _controllerMockBundle.MockCommandDispatcher.Received().Submit(Arg.Any <AddPackageCommand>()); }