//public bool CreateCustomer(CustomerServiceDto customerServiceDto) //{ // // List<CustomerService> customerServices = new List<CustomerService>(); // foreach(var item in customerServiceDto.LstServiceId) // { // Core.Models.CustomerService customerServices = new Core.Models.CustomerService(); // customerServices.FkCustomerId = customerServiceDto.CustomerId; // customerServices.FkServiceId = item; // _unitOfWork.CustomerService.AddAsync(customerServices); // } // _unitOfWork.CommitAsync(); // return true; //} /// <summary>used to create customer services for given customer Id and list of service ids</summary> /// <param name="customerServiceDto">customerService dto having customer id and list of services required</param> /// <returns></returns> public async Task <CustomerServiceDto> CreateCustomerService(CustomerServiceDto customerServiceDto) { foreach (var item in customerServiceDto.LstServiceId) { Core.Models.CustomerService customerServices = new Core.Models.CustomerService(); customerServices.FkCustomerId = customerServiceDto.CustomerId; customerServices.FkServiceId = item; customerServices.IsAssigned = false; await _unitOfWork.CustomerService.AddAsync(customerServices); } await _unitOfWork.CommitAsync(); return(customerServiceDto); }
public async Task <ActionResult <IEnumerable <Customer> > > AddCustomerService(CustomerServiceDto customerServiceDto) { if (!ModelState.IsValid) { return(Ok(new HttpResponseMessage(HttpStatusCode.BadRequest))); } return(Ok(await _customerServiceService.CreateCustomerService(customerServiceDto))); }