Ejemplo n.º 1
0
        public async Task <IActionResult> PutBill(int id, PublicApi.v1.DTO.Bill bill)
        {
            if (id != bill.Id)
            {
                return(BadRequest());
            }


            if (!await _bll.Bills.BelongsToUserAsync(id, User.GetUserId()))
            {
                return(NotFound());
            }

            _bll.Bills.Update(PublicApi.v1.Mappers.BillMapper.MapFromExternal(bill));
            await _bll.SaveChangesAsync();

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <PublicApi.v1.DTO.Bill> > PostBill(PublicApi.v1.DTO.Bill bill)
        {
            if (!await _bll.Bills.BelongsToUserAsync(bill.Id, User.GetUserId()))
            {
                return(NotFound());
            }

            bill = PublicApi.v1.Mappers.BillMapper.MapFromInternal(
                _bll.Bills.Add(PublicApi.v1.Mappers.BillMapper.MapFromExternal(bill)));

            await _bll.SaveChangesAsync();

            bill = PublicApi.v1.Mappers.BillMapper.MapFromInternal(
                _bll.Bills.GetUpdatesAfterUOWSaveChanges(
                    PublicApi.v1.Mappers.BillMapper.MapFromExternal(bill)));

            return(CreatedAtAction("GetBill", new
            {
                version = HttpContext.GetRequestedApiVersion().ToString(),
                id = bill.Id
            }, bill));
        }