public async Task <ContentResult> DeleteCustomer(GetCustomerInput input) { ReturnMessage returnmessage = new ReturnMessage(1, "Customer Deleted Succesfully"); try { var customer = await Task.Run(() => _unitOfWork.Customers.GetAsync(filter: w => w.Id == input.CustomerID)); if (customer.Count() == 0) { returnmessage.msgCode = -2; returnmessage.msg = "Customer Not Found"; } else { _unitOfWork.Customers.Remove(customer.First()); } _unitOfWork.Complete(); _logger.LogInformation("Log:Delete Customer for ID: {Id}", input.CustomerID); return(this.Content(returnmessage.returnMessage(null), "application/json")); } catch (Exception ex) { returnmessage.msg = ex.Message.ToString(); returnmessage.msgCode = -3; return(this.Content(returnmessage.returnMessage(null))); } }
public ActionResult Index(GetCustomerInput input) { var output = cusService.GetListCustomer(input); var model = ObjectMapper.Map <IndexViewModels>(output); return(View(model)); }
/// <summary> /// Executes the Use Case. /// </summary> /// <param name="input">Input Message.</param> /// <returns>Task.</returns> public async Task Execute(GetCustomerInput input) { if (input is null) { this._getCustomerOutputPort .WriteError(Messages.InputIsNull); return; } IUser user = this._userService.GetUser(); ICustomer customer; if (user.CustomerId is { } customerId) { customer = await this._customerRepository .GetBy(customerId) .ConfigureAwait(false); if (customer == null) { this._getCustomerOutputPort .NotFound(Messages.CustomerDoesNotExist); return; } }
public async Task <IActionResult> GetCustomer( [FromServices] IMediator mediator, [FromServices] GetCustomerDetailsPresenter presenter) { var input = new GetCustomerInput(); await mediator.PublishAsync(input) .ConfigureAwait(false); return(presenter.ViewModel); }
//public async Task<CustomerEditDto> GetCustomerByIdAsync(NullableIdDto input) //{ // var customer = await _customerRepository.GetAsync(input.Id.Value); // return customer.MapTo<CustomerListDto>(); //} //查询联系人,分页 public async Task <PagedResultDto <CustomerListDto> > GetPagedCustomersAsync(GetCustomerInput input) { var query = _customerRepository.GetAll(); var customerCount = await query.CountAsync(); var list = await query.OrderBy(input.Sorting).PageBy(input.SkipCount, input.MaxResultCount).ToListAsync(); var dtos = list.MapTo <List <CustomerListDto> >(); return(new PagedResultDto <CustomerListDto>(customerCount, dtos)); }
public ListResultDto <CustomerListDto> GetListCustomer(GetCustomerInput input) { var cutomers = repository .GetAll() .WhereIf( !input.Filter.IsNullOrEmpty(), p => p.CustName.Contains(input.Filter) ) .OrderBy(p => p.CustName) .ToList(); return(new ListResultDto <CustomerListDto>(ObjectMapper.Map <List <CustomerListDto> >(cutomers))); }
public async Task <ContentResult> GetCustomer(GetCustomerInput input) { try { ReturnMessage rm = new ReturnMessage(1, "Success"); var customers = await Task.Run(() => _unitOfWork.Customers.GetAsync(filter: w => input.CustomerID != 0? (w.Id == input.CustomerID):true)); var customersToReturn = _mapper.Map <IEnumerable <CustomerDto> >(customers); return(this.Content(rm.returnMessage(new PagedResultDto <CustomerDto> (customersToReturn.AsQueryable(), input.pagenumber, input.pagesize)), "application/json")); } catch (Exception ex) { return(this.Content(JsonConvert.SerializeObject(new { msgCode = -3, msg = ex.Message }), "application/json")); } }
/// <summary> /// 根据查询条件获取客户信息分页列表 /// </summary> public async Task <PagedResultDto <CustomerListDto> > GetPagedCustomersAsync(GetCustomerInput input) { var query = CustomerRepositoryAsNoTrack; query = query.WhereIf(!input.CompanyName.IsNullOrWhiteSpace(), c => c.CompanyName.Contains(input.CompanyName)) .WhereIf(!input.Contact.IsNullOrWhiteSpace(), c => c.Contact.Contains(input.Contact)) .WhereIf(!input.City.IsNullOrWhiteSpace(), c => c.City.Contains(input.City)) .WhereIf(!input.Mobile.IsNullOrWhiteSpace(), c => c.Mobile.Contains(input.Mobile)); var customerCount = await query.CountAsync(); var customers = await query .OrderBy(input.Sorting) .PageBy(input) .ToListAsync(); var customerListDtos = customers.MapTo <List <CustomerListDto> >(); return(new PagedResultDto <CustomerListDto>( customerCount, customerListDtos )); }
public async Task <ContentResult> GetCustomerById(GetCustomerInput input) { return(await GetCustomer(input)); }