コード例 #1
0
        public string Post([FromUri] string action, [FromBody] object value)
        {
            ResultObject result = new ResultObject();

            if (value == null)
            {
                result.Message = "Data null";
                return(JsonConvert.SerializeObject(result));
            }

            try
            {
                if ("search".Equals(action))
                {
                    var searchObj = JsonConvert.DeserializeObject <SearchPaging>(value.ToString());
                    result.Data = service.Search(searchObj);
                    if (result.Data != null)
                    {
                        result.Success = 1;
                    }
                    return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSetting));
                }
                if ("fillter".Equals(action))
                {
                    var filterObject = JsonConvert.DeserializeObject <QuestionFillterModel>(value.ToString());
                    result.Data = service.Filter(filterObject);
                    if (result.Data != null)
                    {
                        result.Success = 1;
                    }
                    return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSetting));
                }
            }
            catch (Exception e)
            {
                result.Message = "EXCEPTION: " + e.Message + "Stack: " + e.StackTrace;
                return(JsonConvert.SerializeObject(result));
            }
            result.Message = "Action not allow";
            return(JsonConvert.SerializeObject(result));
        }
コード例 #2
0
        public string Post([FromUri] string action, [FromBody] object value)
        {
            var jsonSetting = new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            };
            ResultObject result = new ResultObject();

            if (value == null && !"import".Equals(action.ToLower()))
            {
                result.Message = "Data null";
                return(JsonConvert.SerializeObject(result));
            }

            try
            {
                if ("search".Equals(action))
                {
                    var searchObj = JsonConvert.DeserializeObject <SearchPaging>(value.ToString());
                    result.Data = service.Search(searchObj);
                    if (result.Data != null)
                    {
                        result.Success = 1;
                    }
                    return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSetting));
                }
                if ("fillter".Equals(action))
                {
                    var filterObject = JsonConvert.DeserializeObject <QuestionFillterModel>(value.ToString());
                    result.Data = service.Filter(filterObject);
                    if (result.Data != null)
                    {
                        result.Success = 1;
                    }
                    return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSetting));
                }
                if ("export".Equals(action.ToLower()))
                {
                    result.Message = Export(service.GetAll().ToList());
                    if (!"".Equals(result.Message))
                    {
                        result.Success = 1;
                    }
                    return(JsonConvert.SerializeObject(result));
                }
                if ("import".Equals(action.ToLower()))
                {
                    string _tempUploadFolder = ConfigurationManager.AppSettings["MediaTempUploadFolder"];
                    string _storeFolder      = ConfigurationManager.AppSettings["MediaUploadFolder"];
                    if (HttpContext.Current.Request.Files.Count < 1)
                    {
                        result.Message = "Not file upload";
                        return(JsonConvert.SerializeObject(result));
                    }
                    HttpPostedFile file = HttpContext.Current.Request.Files[0];
                    if (file.ContentLength <= 0)
                    {
                        result.Message = "content file null";
                        return(JsonConvert.SerializeObject(result));
                    }
                    else
                    {
                        result = importZip(file, _tempUploadFolder, _storeFolder);
                        return(JsonConvert.SerializeObject(result));
                    }
                }
            }
            catch (Exception e)
            {
                result.Message = "EXCEPTION: " + e.Message + "Stack: " + e.StackTrace;
                return(JsonConvert.SerializeObject(result));
            }
            result.Message = "Action not allow";
            return(JsonConvert.SerializeObject(result));
        }