Exemplo n.º 1
0
        public HttpResponseMessage Post([FromBody] PostObj postObj)
        {
            try
            {
                ////Get json string from body of request
                //string json = Request.Content.ReadAsStringAsync().Result;
                ////Replace single char '\' on double char '\\' for correct work JObject.Parse
                //json = Regex.Replace(json, @"([^\\])\\([^\\])", m => m.Groups[1].Value + "\\\\" + m.Groups[2].Value);
                //var jsonData = JObject.Parse(json);
                //string path = jsonData["Path"].ToString();
                //string format = jsonData["Format"].ToString();

                string path   = postObj.Path;
                string format = postObj.Format;

                logger.Info("The request came. Method: '{0}', Request path: '{1}', File path: '{2}', File format: '{3}'",
                            Request.Method,
                            Request.RequestUri.AbsolutePath,
                            path,
                            format);

                var fileName = Path.GetFileNameWithoutExtension(path);
                var repoPath = GetRepoPath(fileName, format);

                EExportResult result = logic.ExportToFormat(path, repoPath, format);
                switch (result)
                {
                case EExportResult.Accepted:
                    return(new HttpResponseMessage(HttpStatusCode.Accepted));

                case EExportResult.FileNotFond:
                    return(new HttpResponseMessage(HttpStatusCode.NotFound));

                case EExportResult.Created:
                    return(new HttpResponseMessage(HttpStatusCode.Created));

                case EExportResult.InProcessing:
                    return(new HttpResponseMessage(HttpStatusCode.NoContent));

                case EExportResult.Locked:
                    return(new HttpResponseMessage((HttpStatusCode)423));

                default:
                    return(new HttpResponseMessage(HttpStatusCode.BadRequest));
                }
            }
            catch (Exception e)
            {
                logger.Error(e.Message);
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, e.Message));
            }
        }
        public bool DeleteOne(PostObj <long> idObj)
        {
            try
            {
                var userid = Convert.ToInt32(this.User.Identity.Name);

                return(_service.provider.DeleteOne(idObj.id, userid));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "DeleteOne");
                throw new Exception("Unable to fetch");
            }
        }