Exemple #1
0
        public async Task <IActionResult> PostAsync([FromBody] CouponRequest model, CancellationToken token)
        {
            var userId = _userManager.GetLongUserId(User);

            try
            {
                var command = new CreateCouponCommand(model.Code, model.CouponType, userId, model.Value, model.Expiration);
                await _commandBus.DispatchAsync(command, token);
            }
            catch (DuplicateRowException)
            {
                return(BadRequest("This coupon already exists"));
            }
            catch (SqlConstraintViolationException)
            {
                return(BadRequest("User need to be a tutor"));
            }
            catch (ArgumentOutOfRangeException)
            {
                return(BadRequest("Inavlid Value"));
            }
            catch (ArgumentException)
            {
                return(BadRequest("Value can not be more then 100%"));
            }
            return(Ok());
        }
Exemple #2
0
        public async Task <ActionResult <GenericCommandResult> > Create(
            [FromBody] CreateCouponCommand command,
            [FromServices] CouponHandler handler
            )
        {
            var result = handler.Handle(command);

            return(Ok(result));
        }
        public async Task <IActionResult> Post([FromBody] CreateCouponCommand command)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var response = await this._mediator.Send(command);

            return(this.Created(Url.RouteUrl("GetCouponById", new { id = response.Id }), new { }));
        }
 public async Task <IActionResult> Post([FromBody] CouponRequest model, CancellationToken token)
 {
     try
     {
         var command = new CreateCouponCommand(model.Code,
                                               model.CouponType,
                                               model.TutorId,
                                               model.Value,
                                               model.Expiration,
                                               model.Description,
                                               model.Owner,
                                               null,
                                               //model.Amount,
                                               1
                                               );
         await _commandBus.DispatchAsync(command, token);
     }
     catch (DuplicateRowException)
     {
         return(BadRequest("This coupon already exists"));
     }
     return(Ok());
 }