Example #1
0
        public async Task <ActionResult <BillItemDto> > Post([FromBody] BillFormModel bill)
        {
            if (null == bill)
            {
                throw new ArgumentNullException(nameof(bill), "The bill details submitted is null.");
            }

            var validateResult = await _mediator.Send(new ValidateBillRequest(bill));

            if (!validateResult.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var createResult = await _mediator.Send(new CreateBillRequest(bill));

            return(CreatedAtAction(nameof(this.Get), new { id = createResult.Id }, createResult));
        }
Example #2
0
        public async Task <ActionResult> Put(int id, [FromBody] BillFormModel bill)
        {
            if (null == bill)
            {
                throw new ArgumentNullException(nameof(bill), "The bill details submitted is null.");
            }

            var validateResult = await _mediator.Send(new ValidateBillRequest(bill));

            if (!validateResult.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var updated = await _mediator.Send(new UpdateBillRequest(id, bill));

            if (updated)
            {
                return(NoContent());
            }

            return(BadRequest("The bill cannot be updated"));
        }
 public UpdateBillRequest(int id, BillFormModel billFormModel)
 {
     Id            = id;
     BillFormModel = billFormModel;
 }
Example #4
0
 public ValidateBillRequest(BillFormModel billFormModel)
 {
     BillFormModel = billFormModel;
 }
 public CreateBillRequest(BillFormModel billFormModel)
 {
     BillFormModel = billFormModel;
 }