コード例 #1
0
        public IActionResult Create([FromBody] PaymentTypeRequest request)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(request.Code))
                {
                    return(BadRequest("Invalid code"));
                }

                if (string.IsNullOrWhiteSpace(request.Description))
                {
                    return(BadRequest("Invalid description"));
                }

                var type = new PaymentType
                {
                    Code        = request.Code,
                    Description = request.Description,
                    CreateDate  = DateTime.Now,
                    UpdateDate  = null,
                    UserId      = UserID
                };

                _repository.Insert(type);

                var response = _mapper.Map <PaymentType, PaymentTypeResponse>(type);
                return(Ok(response));
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #2
0
        public IActionResult Update([FromRoute] string id, [FromBody] PaymentTypeRequest request)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(request.Code))
                {
                    return(BadRequest("Invalid code"));
                }

                if (string.IsNullOrWhiteSpace(request.Description))
                {
                    return(BadRequest("Invalid description"));
                }

                var type = _repository.GetByUserID(UserID, id);
                if (type == null)
                {
                    return(BadRequest("Invalid payment type"));
                }

                if (type.Code != request.Code && _paymentRepository.ListPayment(UserID, type.Id).Any())
                {
                    return(BadRequest("Can't change type code becaure the folder is already created"));
                }

                type.Description = request.Description;
                type.UpdateDate  = DateTime.Now;

                _repository.Update(id, type);

                var response = _mapper.Map <PaymentType, PaymentTypeResponse>(type);
                return(Ok(response));
            }
            catch (Exception)
            {
                throw;
            }
        }