Exemplo n.º 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));
        }
Exemplo n.º 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;
 }
Exemplo n.º 4
0
 public ValidateBillRequest(BillFormModel billFormModel)
 {
     BillFormModel = billFormModel;
 }
 public CreateBillRequest(BillFormModel billFormModel)
 {
     BillFormModel = billFormModel;
 }