コード例 #1
0
        public ActionResult <Response> EditCupon(Guid id, CouponModel model)
        {
            var couponToEdit = _couponRepository.GetById(id);

            if (couponToEdit == null)
            {
                return(BadRequest(ResponseHelper.CreateResponse("Cupom não encontrado", model.Code)));
            }

            if (!couponToEdit.ChangeInfo(model.Code, model.Percentage, model.ExpiryDate))
            {
                return(BadRequest(ResponseHelper.CreateResponse("Não foi possível alterar o cupom", couponToEdit.Notifications)));
            }

            if (_couponRepository.Exist(couponToEdit))
            {
                return(BadRequest(ResponseHelper.CreateResponse("Este cupom já se encontra cadastrado", couponToEdit.Id)));
            }

            _couponRepository.Edit(couponToEdit);
            return(Ok(ResponseHelper.CreateResponse("Cupom alterado com sucesso")));
        }
コード例 #2
0
        public bool EditCoupon(CouponDto couponDto)
        {
            var entity = _dtoMapper.Map(couponDto);

            return(_couponRepository.Edit(entity));
        }