Ejemplo n.º 1
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;
            }
        }
        string ValidatePayment(string description, DateTime?paymentDate, string typeId, ref int year, ref int month, ref PaymentType type)
        {
            try
            {
                if (paymentDate == null || paymentDate == DateTime.MinValue)
                {
                    return("Invalid payment date");
                }

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

                type = _paymentTypeRepository.GetByUserID(UserID, typeId);
                if (type == null)
                {
                    return("Invalid payment type");
                }

                if (year == 0)
                {
                    year = paymentDate.Value.Year;
                }

                if (month == 0)
                {
                    month = paymentDate.Value.Month;
                }

                return(string.Empty);
            }
            catch (Exception)
            {
                throw;
            }
        }