コード例 #1
0
        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)));
            }
        }
コード例 #2
0
        public ActionResult Index(GetCustomerInput input)
        {
            var output = cusService.GetListCustomer(input);
            var model  = ObjectMapper.Map <IndexViewModels>(output);

            return(View(model));
        }
コード例 #3
0
        /// <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;
                }
            }
コード例 #4
0
        public async Task <IActionResult> GetCustomer(
            [FromServices] IMediator mediator,
            [FromServices] GetCustomerDetailsPresenter presenter)
        {
            var input = new GetCustomerInput();
            await mediator.PublishAsync(input)
            .ConfigureAwait(false);

            return(presenter.ViewModel);
        }
コード例 #5
0
        //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));
        }
コード例 #6
0
        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)));
        }
コード例 #7
0
        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"));
            }
        }
コード例 #8
0
        /// <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
                       ));
        }
コード例 #9
0
 public async Task <ContentResult> GetCustomerById(GetCustomerInput input)
 {
     return(await GetCustomer(input));
 }