public async Task <string> SaveCustomer(CustomerDto customer) { await Task.Factory.StartNew(() => { lock (m_SyncObject) { if (string.IsNullOrEmpty(customer.Id)) { string newCustomerId = IdGenerator.GetNextCustomerId(); customer.Id = newCustomerId; Customer customerToSave = customer.FromDto(); _customerRepository.Add(customerToSave); } else { Customer customerToSave = customer.FromDto(); _customerRepository.Update(customer.Id, customerToSave); } } }); return(customer.Id); }
private async Task <string> ProcessGetCustomerRequest(GetCustomerRequest request) { try { CustomerDto customerDto = await _orderService.CustomerService.GetCustomer(request.Customer); string result; if (customerDto == null) { WebMessageBase response = new WebMessageBase("get_customer"); response.Status = MessageStatus.FAIL; response.Message = "Customer with ID: " + request.Customer + " not found"; result = JsonConvert.SerializeObject(response, Formatting.Indented); return(result); } GetCustomerResponse customerResponse = new GetCustomerResponse("get_customer", customerDto.FromDto()); result = JsonConvert.SerializeObject(customerResponse, Formatting.Indented); return(result); } catch (Exception e) { WebMessageBase response = new WebMessageBase(); response.Status = MessageStatus.FAIL; response.Message = "Could not get customer."; string result = JsonConvert.SerializeObject(response, Formatting.Indented); _log("During processing get_customer requst an error occured: " + e.Message); return(result); } }