public HttpResponseMessage BankUpdate(BankItem bankItem)
 {
     var response = new ResponseBool { Success = false };
     try
     {
         var existingBank = _bankRepository.GetById(bankItem.MasterId);
         existingBank.Code = bankItem.Code;
         existingBank.Name = bankItem.Name;
         existingBank.Description = bankItem.Description;
         _bankRepository.Save(existingBank);
         response.Success = true;
     }
     catch (Exception ex)
     {
         _log.Error("Failed to update bank",ex);
     }
     return Request.CreateResponse(HttpStatusCode.OK, response);
 }
Ejemplo n.º 2
0
 public async Task<ResponseBool> BankUpdateAsync(BankItem bankItem)
 {
     ResponseBool _response = new ResponseBool { Success = false, ErrorInfo = "" };
     bool success = false;
     string url = string.Format("api/distributorservices/bankupdate");
     var httpClient = setupHttpClient();
     httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
     try
     {
         var response = await httpClient.PostAsJsonAsync(url, bankItem);
         _response = await response.Content.ReadAsAsync<ResponseBool>();
         if (response.IsSuccessStatusCode)
             success = true;
     }
     catch (Exception ex)
     {
         _log.Error("Failed to update bank", ex);
     }
     return _response;
 }
        public HttpResponseMessage BankAdd(BankItem bankItem)
        {
            var response = new ResponseBool { Success = false };
            try
            {
                var bank = new Bank(bankItem.MasterId)
                {
                    Name = bankItem.Name,
                    Code = bankItem.Code,
                    Description = bankItem.Code,
                };
                 _bankRepository.Save(bank).ToString();//return id
                response.Success = true;
            }
            catch (Exception ex)
            {
                _log.Error("Failed to add bank", ex);//return error message
            }
            return Request.CreateResponse(HttpStatusCode.OK, response);

        }