예제 #1
0
        public ActionResult Create(Client client, bool? populateThemes, bool? populatePageTemplates, bool? populateSampleWebForms)
        {
            //check if client name or folder is already taken
            ValidateClientName(client);
            ValidateClientFolder(client);

            if (ModelState.IsValid)
            {
                IGstoreDb db = GStoreDb;
                client = db.Clients.Create(client);
                client.UpdateAuditFields(CurrentUserProfileOrThrow);
                client = db.Clients.Add(client);
                AddUserMessage("Client Added", "Client '" + client.Name.ToHtml() + "' [" + client.ClientId + "] created successfully!", UserMessageType.Success);
                db.SaveChanges();

                string clientFolderVirtualPath = client.ClientVirtualDirectoryToMap(Request.ApplicationPath);
                try
                {
                    client.CreateClientFolders(Request.ApplicationPath, Server);
                    AddUserMessage("Client Folders Created", "Client Folders were created in '" + clientFolderVirtualPath.ToHtml(), UserMessageType.Success);
                }
                catch (Exception ex)
                {
                    AddUserMessage("Error Creating Client Folders!", "There was an error creating client folders in '" + clientFolderVirtualPath.ToHtml() + "'. You will need to create the folder manually. Error: " + ex.Message.ToHtml(), UserMessageType.Warning);
                }

                if (populateThemes.HasValue && populateThemes.Value)
                {
                    List<Theme> newThemes = db.CreateSeedThemes(client);
                    AddUserMessage("Populated Themes", "New Themes added: " + newThemes.Count, UserMessageType.Success);
                }
                if (populatePageTemplates.HasValue && populatePageTemplates.Value)
                {
                    List<PageTemplate> newPageTemplates = db.CreateSeedPageTemplates(client);
                    AddUserMessage("Populated Page Templates", "New Page Templates added: " + newPageTemplates.Count, UserMessageType.Success);
                }
                if (populateSampleWebForms.HasValue && populateSampleWebForms.Value)
                {
                    List<WebForm> newWebForms = db.CreateSeedWebForms(client);
                    AddUserMessage("Populated Simple Web Forms", "New Forms added: " + newWebForms.Count, UserMessageType.Success);
                }

                return RedirectToAction("Index");
            }
            this.BreadCrumbsFunc = html => this.ClientBreadcrumb(html, 0, false, "New");
            return View(client);
        }
예제 #2
0
        public ActionResult Edit(Client client, bool? populateThemes, bool? populatePageTemplates, bool? populateSampleWebForms)
        {
            ValidateClientName(client);
            ValidateClientFolder(client);

            if (ModelState.IsValid)
            {
                IGstoreDb db = GStoreDb;
                Client originalValues = db.Clients.Single(c => c.ClientId == client.ClientId);
                string originalFolderName = originalValues.Folder;
                string originalFolderToMap = originalValues.ClientVirtualDirectoryToMap(Request.ApplicationPath);

                client.UpdateAuditFields(CurrentUserProfileOrThrow);
                client = db.Clients.Update(client);
                AddUserMessage("Client Updated", "Client '" + client.Name.ToHtml() + "' [" + client.ClientId + "] updated!", UserMessageType.Success);
                db.SaveChanges();

                if (populateThemes.HasValue && populateThemes.Value)
                {
                    List<Theme> newThemes = db.CreateSeedThemes(client);
                    AddUserMessage("Populated Themes", "New Themes added: " + newThemes.Count, UserMessageType.Success);
                }
                if (populatePageTemplates.HasValue && populatePageTemplates.Value)
                {
                    List<PageTemplate> newPageTemplates = db.CreateSeedPageTemplates(client);
                    AddUserMessage("Populated Page Templates", "New Page Templates added: " + newPageTemplates.Count, UserMessageType.Success);
                }
                if (populateSampleWebForms.HasValue && populateSampleWebForms.Value)
                {
                    List<WebForm> newWebForms = db.CreateSeedWebForms(client);
                    AddUserMessage("Populated Simple Web Forms", "New Forms added: " + newWebForms.Count, UserMessageType.Success);
                }
                string originalClientFolder = Server.MapPath(originalFolderToMap);
                string newClientFolder = Server.MapPath(client.ClientVirtualDirectoryToMap(Request.ApplicationPath));

                if (client.Folder == originalFolderName && !System.IO.Directory.Exists(newClientFolder))
                {
                    client.CreateClientFolders(Request.ApplicationPath, Server);
                    AddUserMessage("Folders Created", "Client folders were not found, so they were created in '" + client.ClientVirtualDirectoryToMap(Request.ApplicationPath).ToHtml() + "'", UserMessageType.Info);
                }
                else if (client.Folder != originalFolderName)
                {
                    //detect if folder name has changed

                    //default behavior is to move the old folder to the new name
                    if (System.IO.Directory.Exists(originalClientFolder))
                    {
                        try
                        {
                            System.IO.Directory.Move(originalClientFolder, newClientFolder);
                            AddUserMessage("Folder Moved", "Client folder name was changed, so the client folder was moved from '" + originalFolderToMap.ToHtml() + "' to '" + client.ClientVirtualDirectoryToMap(Request.ApplicationPath).ToHtml() + "'", UserMessageType.Success);
                        }
                        catch (Exception ex)
                        {
                            AddUserMessage("Error Moving Client Folder!", "There was an error moving the client folder from '" + originalFolderToMap.ToHtml() + "' to '" + client.ClientVirtualDirectoryToMap(Request.ApplicationPath).ToHtml() + "'. You will need to move the folder manually. Error: " + ex.Message, UserMessageType.Warning);
                        }
                    }
                    else
                    {
                        try
                        {
                            client.CreateClientFolders(Request.ApplicationPath, Server);
                            AddUserMessage("Folders Created", "Client folders were created: " + client.ClientVirtualDirectoryToMap(Request.ApplicationPath).ToHtml(), UserMessageType.Info);
                        }
                        catch (Exception ex)
                        {
                            AddUserMessage("Error Creating Client Folders!", "There was an error creating the client folders in '" + client.ClientVirtualDirectoryToMap(Request.ApplicationPath).ToHtml() + "'. You will need to create the folders manually. Error: " + ex.Message, UserMessageType.Warning);
                        }
                    }
                }
                else
                {
                    client.CreateClientFolders(Request.ApplicationPath, Server);
                }

                return RedirectToAction("Index");
            }
            this.BreadCrumbsFunc = html => this.ClientBreadcrumb(html, client.ClientId, false);
            return View(client);
        }