public virtual ActionResult ImportRepository(string siteName, ImportRepositoryModel model, string @return) { var data = new JsonResultData(ModelState); var site = new Site(siteName).AsActual(); if (site != null && ModelState.IsValid) { data.RunWithTry((resultData) => { Kooboo.CMS.Content.Models.Repository repository = null; if (Request.Files.Count > 0) { repository = Kooboo.CMS.Content.Services.ServiceFactory.RepositoryManager.Create(model.Repository, Request.Files[0].InputStream); } else { repository = Kooboo.CMS.Content.Services.ServiceFactory.RepositoryManager.Create(model.Repository, model.File); } var oldRepository = site.Repository; if (repository != null) { site.Repository = repository.Name; ServiceFactory.SiteManager.Update(site); } try { if (model.DeleteTheOldRepository) { repository = new Kooboo.CMS.Content.Models.Repository(oldRepository); if (!Kooboo.CMS.Sites.Services.ServiceFactory.SiteManager.IfTheRepositoryUsedByOtherSites(site, oldRepository)) { Kooboo.CMS.Content.Services.ServiceFactory.RepositoryManager.Remove(repository); }; } } catch (Exception e) { Kooboo.HealthMonitoring.Log.LogException(e); } resultData.RedirectUrl = @return; }); } return Json(data); }
public virtual ActionResult ImportRepository(string siteName, ImportRepositoryModel model, bool uploadNew) { var entry = new JsonResultEntry(); try { var site = new Site(siteName).AsActual(); if (site != null && ModelState.IsValid) { Kooboo.CMS.Content.Models.Repository repository = null; if (uploadNew) { if (!Request.Files[0].FileName.EndsWith(".zip")) { throw new KoobooException("Please upload an zip file".Localize()); } repository = Kooboo.CMS.Content.Services.ServiceFactory.RepositoryManager.Create(model.Name, Request.Files[0].InputStream); } else { repository = Kooboo.CMS.Content.Services.ServiceFactory.RepositoryManager.Create(model.Name, model.File); } if (repository != null) { site.Repository = repository.Name; ServiceFactory.SiteManager.Update(site); } } else { entry.AddModelState(ModelState); } } catch (Exception e) { entry.AddException(e); } return Json(entry); }