public HttpResponseMessage SalesmanUpdate(DistributorSalesmanItem dSItem)
        {
            var response = new ResponseBool { Success = false };
            DistributorSalesman ds = null;
            try
            {
                ds = _distributorSalesmanRepository.GetById(dSItem.MasterId) as DistributorSalesman;
                ds.Name = dSItem.Name;
                ds.CostCentreCode = dSItem.CostCentreCode;
                _distributorSalesmanRepository.Save(ds);
                response.Success = true;
                response.ErrorInfo = "Successfully saved.";
            }
            catch (DomainValidationException dve)
            {
                string errorMsg = dve.ValidationResults.Results.Aggregate("Error: Invalid fields.\n",
                                                                          (current, msg) =>
                                                                          current + ("\t- " + msg.ErrorMessage + "\n"));
                response.ErrorInfo = errorMsg;
                _log.Error(errorMsg, dve);
            }
            catch (Exception ex) //any other
            {
                response.ErrorInfo = "Error: An error occurred when saving the distributor salesman.";
                _log.Error("Error: An error occurred when saving the distributor salesman.", ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK, response);
        }
Exemplo n.º 2
0
 public async Task<ResponseBool> SalesmanUpdateAsync(DistributorSalesmanItem distributorSalesmanItem)
 {
     ResponseBool _response = new ResponseBool { Success = false, ErrorInfo = "" };
     bool success = false;
     string url = string.Format("api/distributorservices/salesmanupdate");
     var httpClient = setupHttpClient();
     httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
     try
     {
         var response = await httpClient.PostAsJsonAsync(url, distributorSalesmanItem);
         _response = await response.Content.ReadAsAsync<ResponseBool>();
         if (response.IsSuccessStatusCode)
             success = true;
     }
     catch (Exception ex)
     {
         _log.Error("Failed to update salesman", ex);
     }
     return _response;
 }
        public HttpResponseMessage SalesmanAdd(DistributorSalesmanItem dSItem)
        {
            var response = new ResponseBool { Success = false };
            DistributorSalesman ds = null;
            try
            {
                ds = _costCentreFactory.CreateCostCentre(dSItem.MasterId, CostCentreType.DistributorSalesman,
                                                        _costCentreRepository.GetById(dSItem.ParentCostCentreId)) as DistributorSalesman;
                ds.Name = dSItem.Name;
                ds._SetStatus(EntityStatus.Active);
                _costCentreRepository.Save(ds);

                response.Success = true;
                response.ErrorInfo = "Successfully added salesman.";
            }
            catch (DomainValidationException dve)
            {
                string errorMsg =
                    dve.ValidationResults.Results.Aggregate("Error: Invalid distributor salesman fields.\n",
                                                            (current, msg) =>
                                                            current + ("\t- " + msg.ErrorMessage + "\n"));
                response.ErrorInfo = errorMsg;
                _log.Error(errorMsg, dve);
            }
            catch (Exception ex) //any other
            {
                response.ErrorInfo = "Error: An error occurred when updating the distributor salesman.";
                _log.Error("Error: An error occurred when updating the distributor salesman.", ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK, response);

        }