Ejemplo n.º 1
0
        public IHttpActionResult Import()
        {
            try
            {
                var request = Context.AuthenticatedRequest;

                var pollInfo = PollManager.GetPollInfo(request);
                if (pollInfo == null)
                {
                    return(NotFound());
                }
                if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(pollInfo.SiteId, PollUtils.PluginId))
                {
                    return(Unauthorized());
                }

                foreach (string name in HttpContext.Current.Request.Files)
                {
                    var postFile = HttpContext.Current.Request.Files[name];

                    if (postFile == null)
                    {
                        return(BadRequest("Could not read zip from body"));
                    }

                    var filePath = Context.UtilsApi.GetTemporaryFilesPath("poll.zip");
                    PollUtils.DeleteFileIfExists(filePath);

                    if (!PollUtils.EqualsIgnoreCase(Path.GetExtension(postFile.FileName), ".zip"))
                    {
                        return(BadRequest("zip file extension is not correct"));
                    }

                    postFile.SaveAs(filePath);

                    var directoryPath = Context.UtilsApi.GetTemporaryFilesPath("poll");
                    PollUtils.DeleteDirectoryIfExists(directoryPath);
                    Context.UtilsApi.ExtractZip(filePath, directoryPath);

                    var isHistoric = PollBox.IsHistoric(directoryPath);
                    PollBox.ImportFields(pollInfo.SiteId, pollInfo.Id, directoryPath, isHistoric);

                    //FieldManager.Import(pollInfo.SiteId, pollInfo.Id, filePath);
                }

                return(Ok(new
                {
                    Value = true
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Ejemplo n.º 2
0
        public static bool IsHistoric(string directoryPath)
        {
            if (!PollUtils.IsFileExists(PollUtils.PathCombine(directoryPath, VersionFileName)))
            {
                return(true);
            }

            PollUtils.DeleteFileIfExists(PollUtils.PathCombine(directoryPath, VersionFileName));

            return(false);
        }