public async Task <ObjectResult> Get([FromBody] Guid id) { var entity = await _couponRepository.GetAsync(id); var dto = MapToDto(entity); return(Ok(dto)); }
public virtual async Task HandleEventAsync(OrderCanceledEto eventData) { if (!Guid.TryParse(eventData.Order.GetProperty <string>(CouponsConsts.OrderCouponIdPropertyName), out var couponId)) { return; } var coupon = await _couponRepository.GetAsync(couponId); coupon.SetOrderId(null); coupon.SetUsed(null, null, null); await _couponRepository.UpdateAsync(coupon, true); }
public virtual async Task HandleEventAsync(OrderCanceledEto eventData) { var couponId = eventData.Order.GetProperty <Guid?>(CouponsConsts.OrderCouponIdPropertyName); if (couponId is null) { return; } var coupon = await _couponRepository.GetAsync(couponId.Value); coupon.SetOrderId(null); coupon.SetUsed(null, null, null); await _couponRepository.UpdateAsync(coupon, true); }
public virtual async Task HandleEventAsync(EntityCreatedEto <OrderEto> eventData) { if (!Guid.TryParse(eventData.Entity.GetProperty <string>(CouponsConsts.OrderCouponIdPropertyName), out var couponId)) { return; } var discountAmount = eventData.Entity.GetProperty <decimal>(CouponsConsts.OrderCouponDiscountAmountPropertyName); var coupon = await _couponRepository.GetAsync(couponId); if (coupon.OrderId != eventData.Entity.Id) { throw new InvalidCouponOrderIdException(eventData.Entity.Id, coupon.OrderId); } coupon.SetUsed(_clock.Now, discountAmount, eventData.Entity.Currency); await _couponRepository.UpdateAsync(coupon, true); }
public async Task <ApiRequestResult> GetAsync(Guid id) { var result = await _couponRepository.GetAsync(id); return(ApiRequestResult.Success(result, "")); }