Exemplo n.º 1
0
        public async Task <IActionResult> Add([FromBody] TransactionMasterModel newTransactionMaster)
        {
            ServiceResponseModel <TransactionMasterModel> response = new ServiceResponseModel <TransactionMasterModel>();

            try
            {
                if (string.IsNullOrWhiteSpace(newTransactionMaster.TrxId))
                {
                    throw new ArgumentNullException("TrxId is required");
                }
                response = await _transactionMasterService.Add(newTransactionMaster);

                if (response.Data == null)
                {
                    return(NotFound(response));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.StackTrace);
                response.Success = false;
                response.Message = ex.Message;
            }
            return(Ok(response));
        }
        public async Task <ServiceResponseModel <TransactionMasterModel> > GetByCode(string trxId)
        {
            ServiceResponseModel <TransactionMasterModel> serviceResponse = new ServiceResponseModel <TransactionMasterModel>();
            TransactionMaster editTransactionMaster = await UnitOfWork.TransactionMasters.SingleOrDefaultAsync(a =>
                                                                                                               a.TrxId == trxId);

            TransactionMasterModel TransactionMasterAll = _mapper.Map <TransactionMasterModel>(editTransactionMaster);

            serviceResponse.Data = TransactionMasterAll;
            return(serviceResponse);
        }
        public async Task <ServiceResponseModel <TransactionMasterModel> > Add(TransactionMasterModel newTransactionMaster)
        {
            ServiceResponseModel <TransactionMasterModel> serviceResponse = new ServiceResponseModel <TransactionMasterModel>();
            TransactionMaster transactionMaster = _mapper.Map <TransactionMaster>(newTransactionMaster);
            await UnitOfWork.TransactionMasters.AddAsync(transactionMaster);

            await UnitOfWork.Complete();

            serviceResponse.Data = newTransactionMaster;
            return(serviceResponse);
        }
        public async Task <ServiceResponseModel <TransactionMasterModel> > Edit(TransactionMasterModel editTransactionMasterModel)
        {
            ServiceResponseModel <TransactionMasterModel> serviceResponse = new ServiceResponseModel <TransactionMasterModel>();
            TransactionMaster editTransactionMaster = await UnitOfWork.TransactionMasters.SingleOrDefaultAsync(a =>
                                                                                                               a.TrxId == editTransactionMasterModel.TrxId);

            _mapper.Map <TransactionMasterModel, TransactionMaster>(editTransactionMasterModel, editTransactionMaster);
            serviceResponse.Data = editTransactionMasterModel;
            UnitOfWork.TransactionMasters.Update(editTransactionMaster);
            await UnitOfWork.Complete();

            return(serviceResponse);
        }
        public async Task <ServiceResponseModel <TransactionMasterModel> > Delete(string trxId)
        {
            ServiceResponseModel <TransactionMasterModel> serviceResponse = new ServiceResponseModel <TransactionMasterModel>();
            TransactionMaster delTransactionMaster = await UnitOfWork.TransactionMasters.SingleOrDefaultAsync(a =>
                                                                                                              a.TrxId == trxId);

            UnitOfWork.TransactionMasters.Remove(delTransactionMaster);
            await UnitOfWork.Complete();

            TransactionMasterModel delTransactionMasterModel = _mapper.Map <TransactionMasterModel>(delTransactionMaster);

            serviceResponse.Data = delTransactionMasterModel;

            return(serviceResponse);
        }
Exemplo n.º 6
0
        public async Task <IActionResult> GetAll([FromQuery] PageParams pageParams, [FromBody] TransactionMasterModel getTransactionMaster)
        {
            ServiceResponseModel <IEnumerable <TransactionMaster> > response = new ServiceResponseModel <IEnumerable <TransactionMaster> >();

            try
            {
                var transactionList = await _transactionMasterService.GetAll(pageParams, getTransactionMaster);

                Response.AddPaginationHeader(transactionList.CurrentPage, transactionList.PageSize, transactionList.TotalCount, transactionList.TotalPages);
                response.Data = transactionList;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.StackTrace);
                response.Success = false;
                response.Message = ex.Message;
            }
            return(Ok(response));
        }
        public async Task <PagedList <TransactionMaster> > GetAll(PageParams pageParams, TransactionMasterModel getTransactionMaster)
        {
            var query = _context.TransactionMasters.AsQueryable();

            switch (getTransactionMaster.OrderBy)
            {
            case "trxId":
                query = query.OrderBy(c => c.TrxId);
                break;

            default:
                query = query.OrderBy(c => c.TrxId);
                break;
            }

            return(await PagedList <TransactionMaster> .CreateAsync(query, pageParams.PageNumber, pageParams.PageSize));
        }