예제 #1
0
        public async Task <BLLResult <T> > PostJson <T>(Object obj)
        {
            using (var client = new HttpClient())
            {
                try
                {
                    string                  postJsonString          = JsonConvert.SerializeObject(obj);
                    StringContent           content                 = new StringContent(postJsonString, Encoding.UTF8, "application/json");
                    CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(20));
                    HttpResponseMessage     response                = await client.PostAsync("http://172.16.27.52:120/api/AGVMutual/Get", content, cancellationTokenSource.Token).ConfigureAwait(false);

                    response.EnsureSuccessStatusCode();//用来抛异常的
                    string responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    //AppSession.LogService.LogInterface(title, postJsonString, responseBody, LogLevel.Info, "", "");
                    var temp = JsonConvert.DeserializeObject <ApiResultModel <T> >(responseBody);
                    if (temp.Code == System.Net.HttpStatusCode.NoContent)//成功
                    {
                        return(BLLResultFactory <T> .Success(temp.Data, temp.Msg));
                    }
                    else
                    {
                        //AppSession.LogService.LogInterface(title, postJsonString, responseBody, LogLevel.Failure, "", "");
                        return(BLLResultFactory <T> .Error(temp.Data, temp.Msg));
                    }
                }
                catch (Exception ex)
                {
                    //Logger.Log($"请求错误:{ex.Message}", LogLevel.Exception);
                    //AppSession.LogService.WriteExceptionLog(title, ex);
                    return(BLLResultFactory <T> .Error(ex.Message));;
                }
            }
        }
예제 #2
0
 public BLLResult CreateUser(User user)
 {
     using (IDbConnection connection = AppSession.DAL.GetConnection())
     {
         IDbTransaction trans = null;
         try
         {
             connection.Open();
             trans = connection.BeginTransaction();
             var result = CreateUser(connection, trans, user);
             if (result.Success)
             {
                 trans.Commit();
                 return(BLLResultFactory.Success(result.Msg));
             }
             else
             {
                 trans.Rollback();
                 return(BLLResultFactory.Error(result.Msg));
             }
         }
         catch (Exception ex)
         {
             trans?.Rollback();
             return(BLLResultFactory.Error($"创建任务的时候出现异常{ex.Message}"));
         }
     }
 }
예제 #3
0
        private void Requse_Click(object sender, RoutedEventArgs e)
        {
            User user = new User();

            user.Id        = 121;
            user.UserName  = "******";
            user.UserCode  = "12";
            user.Address   = "311";
            user.Created   = null;
            user.CreatedBy = "FG";
            user.Disable   = false;
            user.Partment  = "4";
            user.Password  = "******";
            user.Phone     = "Cs";
            user.Remark    = "测试";
            user.Updated   = null;
            user.Updatedby = "CS";

            var temp = AppSession.CommonService.PostJson <User>(user).Result;

            if (temp.Success)
            {
                BLLResultFactory.Success(temp.Data, null);
            }
        }
예제 #4
0
        private BLLResult <User> SelectByUserId(int Id)
        {
            var temp = AppSession.DAL.GetCommonModelBy <User>($"where Id={Id}");

            if (temp.Success && temp.Data.Count > 0)
            {
                return(BLLResultFactory <User> .Success(temp.Data[0]));
            }
            return(BLLResultFactory <User> .Error(temp.Msg));
        }
예제 #5
0
        private BLLResult CreateUser(IDbConnection connection, IDbTransaction transaction, User user)
        {
            var temp = AppSession.DAL.InsertCommonModel <User>(user);

            if (temp.Success)
            {
                return(BLLResultFactory.Success());
            }
            {
                return(BLLResultFactory.Error(temp.Msg));
            }
        }
예제 #6
0
 public BLLResult <QueryUser> SelectUserById([FromBody] QueryUserId Id)
 {
     try
     {
         var result = AppSession.TaskService.SelectUser(Id.Id);
         return(result);
     }
     catch (Exception ex)
     {
         return(BLLResultFactory <QueryUser> .Error(ex.Message));
     }
 }
예제 #7
0
 public override BLLResult <int?> InsertCommonModel <T>(T model)
 {
     using (IDbConnection connection = GetConnection())
     {
         try
         {
             return(BLLResultFactory <int?> .Success(connection.Insert <T>(model), "成功"));
         }
         catch (Exception ex)
         {
             return(BLLResultFactory <int?> .Error("发生异常:" + ex.Message));
         }
     }
 }
예제 #8
0
        public async Task <BLLResult> add(User user)
        {
            using (var client = new HttpClient())
            {
                try
                {
                    user.Id        = 121;
                    user.UserName  = "******";
                    user.UserCode  = "12";
                    user.Address   = "311";
                    user.Created   = null;
                    user.CreatedBy = "fg";
                    user.Disable   = false;
                    user.Partment  = "4";
                    user.Password  = "******";
                    user.Phone     = "cs";
                    user.Remark    = "测试";
                    user.Updated   = null;
                    user.Updatedby = "cs";
                    string                  postjson = JsonConvert.SerializeObject(user);
                    StringContent           content  = new StringContent(postjson, Encoding.UTF8, "application/json");
                    CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(20));
                    HttpResponseMessage     response = await client.PostAsync("https://localhost:44367/api/AGVMutual/Get", content, cancellationTokenSource.Token).ConfigureAwait(false);

                    response.EnsureSuccessStatusCode();
                    string responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    //AppSession
                    var temp = JsonConvert.DeserializeObject <ApiResultModel>(responseBody);
                    if (temp.Code == HttpStatusCode.OK)
                    {
                        return(BLLResultFactory.Success(temp.Data, temp.Msg));
                    }
                    else
                    {
                        return(BLLResultFactory.Success(temp.Data, temp.Msg));
                    }
                }
                catch (Exception ex)
                {
                    return(BLLResultFactory.Error(ex.Message));;
                }

                //HttpResponseMessage response = await client.PostAsync("https://localhost:44367/api/AGVMutual/Get", content, cancellationTokenSource.Token).ConfigureAwait(false);
            }
        }
예제 #9
0
 public BLLResult CreateUser([FromBody] User user)
 {
     try
     {
         var result = AppSession.TaskService.CreateUser(user);
         if (result.Success)
         {
             return(result);
         }
         else
         {
             return(BLLResultFactory.Error(result.Msg));
         }
     }
     catch (Exception ex)
     {
         return(BLLResultFactory.Error(ex.Message));
     }
 }
예제 #10
0
 public override BLLResult <List <T> > GetCommonModelBy <T>(string v)
 {
     using (IDbConnection connection = GetConnection())
     {
         try
         {
             List <T> list = connection.GetList <T>(v).ToList();
             if (list != null && list.Count > 0)
             {
                 return(BLLResultFactory <List <T> > .Success(list, "成功"));
             }
             else
             {
                 return(BLLResultFactory <List <T> > .Error("未查询到数据"));
             }
         }
         catch (Exception ex)
         {
             return(BLLResultFactory <List <T> > .Error("发生异常:" + ex.Message));
         }
     }
 }
예제 #11
0
 public BLLResult <QueryUser> SelectUser(int Id)
 {
     try
     {
         var result = SelectByUserId(Id);
         if (result.Success)
         {
             QueryUser item = new QueryUser();
             var       data = result.Data;
             item.Password = data.Password;
             item.UserName = data.UserName;
             item.Address  = data.Address;
             return(BLLResultFactory <QueryUser> .Success(item));
         }
         else
         {
             return(BLLResultFactory <QueryUser> .Error(result.Msg));
         }
     }
     catch (Exception ex)
     {
         return(BLLResultFactory <QueryUser> .Error(ex.Message));
     }
 }