示例#1
0
        public async Task <IActionResult> PutBill(Guid id, BillForCreateDto bill)
        {
            if (id != bill.Id)
            {
                return(BadRequest());
            }

            if (!await _billRepository.EntryExists(id))
            {
                return(NotFound());
            }

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

            var billFromRepo = await _billRepository.GetById(id, true);

            var categoryFromRepo = _categoryRepository.GetCategoryByName(bill.CategoryName);

            if (categoryFromRepo == null)
            {
                return(BadRequest());
            }

            var billToUpdate = Mapper.Map(bill, billFromRepo);

            billToUpdate.BudgetCategory = categoryFromRepo;

            await _billRepository.Update(id, billToUpdate);

            return(NoContent());
        }