コード例 #1
0
ファイル: RancherController.cs プロジェクト: windygu/CCSys
        public IHttpActionResult GetById(int id)
        {
            GetRancherResponse response = new GetRancherResponse();

            try
            {
                List <Rancher> ranchers = rancherBL.GetRancher(id);
                response.Ranchers = ranchers;
                response.Success  = true;
            }
            catch (RancherException ex)
            {
                response.ErrorCode    = ex.Error;
                response.ErrorMessage = "Error. " + ex.Error.ToString();
                response.Success      = false;
            }
            catch (Exception ex)
            {
                response.ErrorMessage = "Error. " + ex.Message;
                response.Success      = false;
            }
            return(Ok(response));
        }
コード例 #2
0
ファイル: RancherPresenter.cs プロジェクト: windygu/CCSys
 public void UpdateCurrentRancher()
 {
     if (rancherView.SelectedId == -1)
     {
         rancherView.CurrentRancher = new Rancher();
     }
     else
     {
         HttpClient client = new HttpClient();
         client.BaseAddress = new Uri(baseUrl);
         client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
         client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token.access_token);
         HttpResponseMessage response = client.GetAsync(string.Format("{0}?id={1}", getByIdAction, rancherView.SelectedId)).Result;
         if (response.IsSuccessStatusCode)
         {
             GetRancherResponse getRancherResponse = response.Content.ReadAsAsync <GetRancherResponse>().Result;
             if (getRancherResponse.Success)
             {
                 PropertyCopier.CopyProperties(getRancherResponse.Ranchers[0], rancherView.CurrentRancher);
                 rancherView.CurrentRancher.RaiseUpdateProperties();
             }
         }
     }
 }