public ActionResult Update(ShellFeatureModel model)
        {
            var service       = WorkContext.Resolve <IShellDescriptorManager>();
            var setting       = service.GetShellDescriptor();
            var configuration = WebConfigurationManager.OpenWebConfiguration("~");
            var sections      = ((CMSConfigurationSection)configuration.GetSection("solutions")).Modules;

            var element = new ModuleProviderConfigurationElement
            {
                Id       = model.Name,
                Name     = model.Name,
                Category = model.Category
            };

            if (setting.Features.Any(item => item.Name == model.Name))
            {
                sections.Remove(element.Id);
                sections.Add(element);
                configuration.Save(ConfigurationSaveMode.Modified);

                return(new AjaxResult().Alert(T("Existing the name.")));
            }

            setting.Features.Add(new ShellFeature {
                Name = model.Name
            });
            service.UpdateShellDescriptor(0, setting.Features);

            var serviceFile = WorkContext.Resolve <IShellDescriptorCache>();
            var st          = WorkContext.Resolve <ShellSettings>();

            serviceFile.Store(st.Name, setting);

            sections.Remove(element.Id);
            sections.Add(element);
            configuration.Save(ConfigurationSaveMode.Modified);

            return(new AjaxResult().NotifyMessage("UPDATE_ENTITY_COMPLETE").Alert(T("Save success.")));
        }
        public ActionResult SaveModule()
        {
            try
            {
                HttpPostedFileBase file = Request.Files["UploadedFile"];
                if (file != null)
                {
                    #region Save module
                    var assemblyName = Request.Form["AssemblyName"];
                    var category     = "Content Management";

                    var service       = WorkContext.Resolve <IShellDescriptorManager>();
                    var setting       = service.GetShellDescriptor();
                    var configuration = WebConfigurationManager.OpenWebConfiguration("~");
                    var sections      = ((CMSConfigurationSection)configuration.GetSection("solutions")).Modules;
                    var element       = new ModuleProviderConfigurationElement
                    {
                        Id       = assemblyName,
                        Name     = assemblyName,
                        Category = category
                    };

                    if (setting.Features.Any(item => item.Name == assemblyName))
                    {
                        sections.Remove(element.Id);
                    }
                    else
                    {
                        var serviceFile = WorkContext.Resolve <IShellDescriptorCache>();
                        var st          = WorkContext.Resolve <ShellSettings>();
                        serviceFile.Store(st.Name, setting);
                    }
                    setting.Features.Add(new ShellFeature {
                        Name = assemblyName
                    });
                    service.UpdateShellDescriptor(0, setting.Features);

                    sections.Add(element);
                    configuration.Save(ConfigurationSaveMode.Modified);
                    #endregion

                    #region Upload Module
                    var folderSource = Server.MapPath("~/Media/Temp/");
                    var fullUrl      = Path.Combine(folderSource, file.FileName);
                    file.SaveAs(fullUrl);

                    var    folderRoot     = Path.GetFileNameWithoutExtension(fullUrl);
                    string lastFolderName = folderSource + folderRoot;
                    Directory.CreateDirectory(lastFolderName);
                    using (ZipFile zip = ZipFile.Read(fullUrl))
                    {
                        zip.ExtractAll(lastFolderName, ExtractExistingFileAction.OverwriteSilently);
                    }

                    foreach (var path in Directory.GetDirectories(lastFolderName))
                    {
                        var folderName = new DirectoryInfo(path).Name;
                        if (folderName == "bin")
                        {
                            string[] files = Directory.GetFiles(path);
                            foreach (var filePath in files)
                            {
                                System.IO.File.Copy(filePath, Server.MapPath("~/bin/" + Path.GetFileName(filePath)), true);
                            }
                        }
                        else
                        {
                            var sourceFolder      = lastFolderName + "\\" + folderName;
                            var destinationFolder = Server.MapPath(string.Format("~/{0}", folderName));
                            CopyDirectories(sourceFolder, destinationFolder);
                        }
                    }

                    if (System.IO.File.Exists(fullUrl))
                    {
                        System.IO.File.Delete(fullUrl);
                    }

                    if (Directory.Exists(lastFolderName))
                    {
                        Directory.Delete(lastFolderName, true);
                    }

                    #endregion
                }
                else
                {
                    var model = new MessageErrorModel
                    {
                        ExceptionError = new Exception(T("Cannot find file upload.")),
                        TitleForm      = T("Messages"),
                        Messages       = T("Cannot find file upload."),
                        GoBackText     = T("Back")
                    };

                    return(View("ErrorPage", model));
                }
            }
            catch (Exception ex)
            {
                var model = new MessageErrorModel
                {
                    ExceptionError = ex,
                    TitleForm      = T("Messages"),
                    Messages       = ex.Message,
                    GoBackText     = T("Back")
                };

                return(View("ErrorPage", model));
            }

            return(Redirect(Url.Action("Index")));
        }