public CouponDto CreateCoupon(CreateCouponDto couponDto) { var coupon = _mapper.Map <Coupon>(couponDto); _couponRepository.Create(coupon); return(_mapper.Map <CouponDto>(coupon)); }
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()); } }
public void Create(CouponDto entity) { var model = _mapper.Map <Coupon>(entity); _couponRepository.Create(model); }