예제 #1
0
        public CouponDto CreateCoupon(CreateCouponDto couponDto)
        {
            var coupon = _mapper.Map <Coupon>(couponDto);

            _couponRepository.Create(coupon);

            return(_mapper.Map <CouponDto>(coupon));
        }
예제 #2
0
        public IActionResult Create(Coupon coupon)
        {
            coupon.CreatedAt = DateTime.Now;
            coupon.UpdatedAt = DateTime.Now;

            if (ModelState.IsValid)
            {
                _coupon.Create(coupon);
                return(RedirectToAction(nameof(Index)));
            }
            return(View(coupon));
        }
        public ActionResult <Coupon> Create([FromBody] Coupon coupon)
        {
            try
            {
                var result = _couponRepository.Create(coupon);

                return(CreatedAtRoute("GetCoupon", new { id = result.Id }, result));
            }
            catch (InvalidInputException ex)
            {
                _logger.LogError($"Failed to create new coupon:\n{ex}");

                return(BadRequest());
            }
        }
예제 #4
0
        public void Create(CouponDto entity)
        {
            var model = _mapper.Map <Coupon>(entity);

            _couponRepository.Create(model);
        }