コード例 #1
0
        public IActionResult UpdateCheckoutRecord(string id, [FromBody] CheckoutRecordForCheckInUpdateDto checkoutRecordForUpdate)
        {
            try
            {
                if (checkoutRecordForUpdate == null)
                {
                    _logger.LogError("Owner object sent from client is null.");
                    return(BadRequest("Owner object is null"));
                }

                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid owner object sent from client.");
                    return(BadRequest("Invalid model object"));
                }

                _checkoutRecordServices.UpdateCheckoutRecord(id, checkoutRecordForUpdate);

                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside UpdateOwner action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
コード例 #2
0
        public void UpdateCheckoutRecord(string id, CheckoutRecordForCheckInUpdateDto checkoutRecordForUpdate)
        {
            // Want to try to find the owner first before updating. Throw error if the owner does not exist.
            // What if the user attempts to modify the id field for the owner? Throw error.
            var checkoutRecord = GetCheckoutRecordById(id);

            if (checkoutRecord == null)
            {
                //_logger.LogError($"Owner with id: {id}, hasn't been found in db.");
                return;
                // TODO: need to return notfound to the user
            }

//TODO validate new checkoutRecord
            //_mapper.Map(owner, ownerEntity);
            checkoutRecord.DateReturned    = checkoutRecordForUpdate.DateReturned;
            checkoutRecord.AmountPaid      = checkoutRecordForUpdate.AmountPaid;
            checkoutRecord.Notes           = checkoutRecordForUpdate.Notes;
            checkoutRecord.HasBeenReturned = true;
            //leave all the rest unchanged from after the retrieve

            Tool             originalTool = _toolServices.GetToolById(checkoutRecord.ItemCheckedOutId);
            ToolForUpdateDto tool         = new ToolForUpdateDto()
            {
                Name              = originalTool.Name,
                Description       = originalTool.Description,
                DailyCost         = originalTool.DailyCost,
                ReplacementCost   = originalTool.ReplacementCost,
                QuantityAvailable = ++originalTool.QuantityAvailable
            };

            _toolServices.UpdateTool(checkoutRecord.ItemCheckedOutId, tool);


            _checkoutRecordRepository.Update(checkoutRecord.CheckoutRecordId, checkoutRecord);
        }