Beispiel #1
0
        public ActionResult <PaymentConditionDTO> Edit([FromBody] PaymentConditionDTO paymentConditionDTO)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(UnprocessableEntity(ModelState));
                }
                PaymentCondition paymentCondition = _mapper.Map <PaymentCondition>(_paymentConditionAppService.GetById((long)paymentConditionDTO.Id, this.User));

                if (paymentCondition == null)
                {
                    return(BadRequest());
                }

                paymentCondition.Description = paymentConditionDTO.Description;

                _paymentConditionAppService.UpdateEntity(paymentCondition);

                return(new ObjectResult(paymentConditionDTO));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Beispiel #2
0
 public static PaymentCondition Convert(PaymentConditionDTO obj)
 {
     return(new PaymentCondition
     {
         Id = obj.Id,
         Condition = obj.Condition
     });
 }
Beispiel #3
0
        public ActionResult <PaymentConditionDTO> GetById(long id)
        {
            try
            {
                PaymentConditionDTO paymentConditionDTO = _mapper.Map <PaymentConditionDTO>(
                    _paymentConditionAppService.GetById(id, this.User));

                if (paymentConditionDTO == null)
                {
                    return(NotFound());
                }

                return(Ok(paymentConditionDTO));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Beispiel #4
0
        public ActionResult <PaymentConditionDTO> Create([FromBody] PaymentConditionDTO paymentConditionDTO)
        {
            try
            {
                CurrentUser currentUser = new CurrentUser(this.User);
                if (!ModelState.IsValid || paymentConditionDTO.EstablishmentId != currentUser.EstablishmentId)
                {
                    return(BadRequest());
                }

                PaymentCondition paymentCondition = _mapper.Map <PaymentCondition>(paymentConditionDTO);

                if (_paymentConditionAppService.CreateEntity(paymentCondition) != null)
                {
                    return(Created("/api/v1/paymentcondition", HttpStatusCode.Created));
                }

                return(BadRequest());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }