//Returns the view for the Add City functionality public ActionResult AddMaintenanceGroup() { var customerModel = new MaintenangeGroupCreateModel { ConnectionStrings = SettingsFactory.GetMaintenanceGroupConnectionStringNames() }; return(View(customerModel)); }
public int CreateNewMaintananceGroup(MaintenangeGroupCreateModel model, string templateFolder, string workingFolder) { // In order to create a new maintenance group // 1. Create customer in AuthorizationManager // 3. Create the customer (customer profile) in the RBAC database. // 6. Create menu and authorization entries in NetSqlAzMan // 7. Add the current user to the list in the cache table int customerId = 0; var authorizationManager = new AuthorizationManager(); if (authorizationManager.CreateCity(model.Id, model.DisplayName, "Internal Name: " + model.InternalName)) { var customerProfile = new CustomerProfile() { CustomerId = model.Id, DisplayName = model.DisplayName, CreatedOn = DateTime.Now, CreatedBy = WebSecurity.CurrentUserId, StatusChangeDate = DateTime.Now, Is24HrFormat = false, MaintenanceConnectionStringName = model.ConnectionStringName, CustomerTypeId = (int)CustomerProfileType.MaintenanceGroup, Status = (int)CustomerStatus.New }; RbacEntities.CustomerProfiles.Add(customerProfile); RbacEntities.SaveChanges(); customerId = model.Id; } if (customerId != 0) { // Set the menus into RBAC SetMenus(model.DisplayName, templateFolder, workingFolder, MaintenanceGroupTemplateName); //NOTE: We dont need to do this, no need to custom hidden columns for maintenanceGroups // RbacEntities.InitializeCustomerGrids(customerId); //add the current customer to the access caching table (new UserCustomerAccessManager()).AddCustomerAccess(WebSecurity.CurrentUserId, customerId); } return(customerId); }
public ActionResult AddMaintenanceGroup(string submitButton, MaintenangeGroupCreateModel model) { // Was action RETURN? if (submitButton.Equals("RETURN")) { return(RedirectToAction("Index", new { rtn = "true" })); } try { if (ModelState.IsValid) { var customerFactory = new CustomerFactory(model.ConnectionStringName); // Validate that this model.Id has not yet been used. if (customerFactory.CustomerIdExists(model.Id)) { // Cannot use this id. ModelState.AddModelError("Id", "Id already in use."); } if (customerFactory.CustomerNameExists(model.DisplayName)) { // Cannot use this name. ModelState.AddModelError("DisplayName", "Name already in use."); } if (!ModelState.IsValid) { model.ConnectionStrings = SettingsFactory.GetMaintenanceGroupConnectionStringNames(); return(View(model)); } // At this point, can create new customer. // Get server-relative paths for create customer process. string templateFolder = Server.MapPath(ConfigurationManager.AppSettings["rbac.menu.template.dir"]); string workingFolder = Server.MapPath(ConfigurationManager.AppSettings["rbac.menu.template.upload"]); //create the new maint group here int customerId = (new MaintenanceGroupFactory()).CreateNewMaintananceGroup(model, templateFolder, workingFolder); if (customerId == 0) { var ei = new ErrorItem() { ErrorCode = "1236", ErrorMessage = "General failure creating new maintenance group." }; ViewData["__errorItem"] = ei; model.ConnectionStrings = SettingsFactory.GetMaintenanceGroupConnectionStringNames(); return(View(model)); } // Success creating new customer. Redirect to Edit return(RedirectToAction("EditMaintenanceGroup", new { customerId = model.Id })); } model.ConnectionStrings = SettingsFactory.GetMaintenanceGroupConnectionStringNames(); return(View(model)); } catch (Exception ex) { var ei = new ErrorItem() { ErrorCode = "1237", ErrorMessage = "General failure creating new maintenance group. " + ex.Message }; ViewData["__errorItem"] = ei; model.ConnectionStrings = SettingsFactory.GetMaintenanceGroupConnectionStringNames(); return(View(model)); } }