public async Task <int> CreateOrUpdate(PhanLoaiHoSo_FilterDto input)
        {
            try
            {
                if (input.Id > 0)
                {
                    // update
                    var updateData = await _setting_LoaiHoSo_FilterRepos.GetAsync(input.Id);

                    input.MapTo(updateData);
                    updateData.JsonFilter = LowercaseJsonSerializer.SerializeObject(input.Filter);
                    await _setting_LoaiHoSo_FilterRepos.UpdateAsync(updateData);

                    return(updateData.Id);
                }
                else
                {
                    var insertInput = input.MapTo <PhanLoaiHoSo_Filter>();
                    insertInput.JsonFilter = LowercaseJsonSerializer.SerializeObject(input.Filter);
                    int id = await _setting_LoaiHoSo_FilterRepos.InsertAndGetIdAsync(insertInput);

                    await CurrentUnitOfWork.SaveChangesAsync();

                    return(id);
                }
            }
            catch (Exception ex)
            {
                throw new UserFriendlyException("Xảy ra lỗi trong quá trình xử lý", ex.Message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 执行HTTP POST请求, post数据为json对象。
        /// </summary>
        /// <param name="url">请求地址</param>
        /// <param name="postBody">请求post的内容</param>
        /// <param name="header">请求地址头</param>
        /// <returns>HTTP响应</returns>
        public string DoPost(string url, Object postBody, string header)
        {
            var req = GetWebRequest(url, "POST", header);

            byte[] postData;
            var    body = postBody as byte[];

            if (body != null)
            {
                req.ContentType = "application/octet-stream;charset=utf-8";
                postData        = body;
            }
            else
            {
                req.ContentType = "application/json;charset=utf-8";
                var data = LowercaseJsonSerializer.SerializeObject(postBody);
                postData = Encoding.UTF8.GetBytes(data);
            }

            var reqStream = req.GetRequestStream();

            reqStream.Write(postData, 0, postData.Length);
            reqStream.Close();

            var rsp  = (HttpWebResponse)req.GetResponse();
            var cSet = rsp.CharacterSet;

            if (string.IsNullOrEmpty(cSet))
            {
                cSet = "utf-8";
            }
            var encoding = Encoding.GetEncoding(cSet);

            return(GetResponseAsString(rsp, encoding));
        }
Ejemplo n.º 3
0
        public void SerializeObject_Serializes_properties_and_enums_to_lowercase()
        {
            var someObject = new
            {
                MyEnum = TestEnum.SomeValue
            };
            var json = LowercaseJsonSerializer.SerializeObject(someObject);

            json.ShouldBe("{\"myEnum\":\"someValue\"}");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 执行HTTP PUT请求, put数据为json对象。
        /// </summary>
        /// <param name="url">请求地址</param>
        /// <param name="putContent">请求put的内容</param>
        /// <param name="header">请求地址头</param>
        /// <returns>HTTP响应</returns>
        public string DoPut(string url, Object putContent, string header)
        {
            var req = GetWebRequest(url, "PUT", header);

            req.ContentType = "application/json;charset=utf-8";
            var data      = LowercaseJsonSerializer.SerializeObject(putContent);
            var postData  = Encoding.UTF8.GetBytes(data);
            var reqStream = req.GetRequestStream();

            reqStream.Write(postData, 0, postData.Length);
            reqStream.Close();

            var rsp  = (HttpWebResponse)req.GetResponse();
            var cSet = rsp.CharacterSet;

            if (string.IsNullOrEmpty(cSet))
            {
                cSet = "utf-8";
            }
            var encoding = Encoding.GetEncoding(cSet);

            return(GetResponseAsString(rsp, encoding));
        }