Exemplo n.º 1
0
        public virtual ActionResult ImportSite(ImportSiteModel model, string @return)
        {
            var data = new JsonResultData(ModelState);

            if (ModelState.IsValid)
            {
                data.RunWithTry((resultData) =>
                {
                    Site parent = null;
                    if (!string.IsNullOrEmpty(model.Parent))
                    {
                        parent = new Site(model.Parent);
                    }
                    Site createdSite = null;
                    if (Request.Files.Count > 0)
                    {
                        createdSite = ServiceFactory.SiteManager.Create(parent, model.Name, model.Repository, Request.Files[0].InputStream, User.Identity.Name);
                    }
                    else
                    {
                        createdSite = ServiceFactory.SiteManager.Import(parent, model.Name, model.Repository, model.File, User.Identity.Name);
                    }

                    resultData.RedirectUrl = Url.Action("SiteMap", new { controller = "Home", siteName = createdSite.FullName });
                });
            }
            return Json(data);
        }
Exemplo n.º 2
0
        public virtual ActionResult ImportSite(ImportSiteModel model, string @return)
        {
            var data = new JsonResultData(ModelState);

            if (ModelState.IsValid)
            {
                data.RunWithTry((resultData) =>
                {
                    Site parent = null;
                    if (!string.IsNullOrEmpty(model.Parent))
                    {
                        parent = new Site(model.Parent);
                    }
                    var options = new CreateSiteOptions()
                        {
                            MembershipName = model.Membership,
                            RepositoryName = model.Repository,
                            UserName = User.Identity.Name
                        };
                    Site createdSite = null;
                    if (Request.Files.Count > 0)
                    {

                        createdSite = ServiceFactory.SiteManager.Create(parent, model.Name, Request.Files[0].InputStream, options);
                    }
                    else
                    {
                        var packageFile = _importedSiteManager.GetItemTemplate("", model.File);
                        createdSite = ServiceFactory.SiteManager.Create(parent, model.Name, packageFile.TemplateFile, options);
                    }

                    resultData.RedirectUrl = Url.Action("SiteMap", new { controller = "Home", siteName = createdSite.FullName });
                });
            }
            return Json(data);
        }
Exemplo n.º 3
0
        public virtual ActionResult ImportSite(ImportSiteModel model, bool uploadNew)
        {
            var entry = new JsonResultEntry();

            Site parent = null;
            if (!string.IsNullOrEmpty(model.Parent))
            {
                parent = new Site(model.Parent);
            }

            try
            {
                if (ModelState.IsValid)
                {

                    if (uploadNew)
                    {
                        if (!Request.Files[0].FileName.EndsWith(".zip"))
                        {
                            throw new KoobooException("Please upload an zip file".Localize());
                        }

                        ServiceFactory.SiteManager.Create(parent, model.Name, model.Repository, Request.Files[0].InputStream, User.Identity.Name);
                    }
                    else
                    {
                        ServiceFactory.SiteManager.Import(parent, model.Name, model.Repository, model.File, User.Identity.Name);
                    }
                }
                else
                {
                    entry.AddModelState(ModelState);
                }
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }
            return Json(entry);
        }