public IActionResult UpdateTool(string id, [FromBody] ToolForUpdateDto toolForUpdate) { try { if (toolForUpdate == 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")); } _toolServices.UpdateTool(id, toolForUpdate); return(NoContent()); } catch (Exception ex) { _logger.LogError($"Something went wrong inside UpdateOwner action: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public async Task <IActionResult> UpdateTool(Guid id, ToolForUpdateDto tool) { var existentTool = HttpContext.Items["tool"] as Tool; _mapper.Map(tool, existentTool); await _unitOfWork.SaveChanges(); return(NoContent()); }
public void UpdateTool(string id, ToolForUpdateDto toolForUpdate) { // 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 tool = GetToolById(id); if (tool == 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 tool //_mapper.Map(owner, ownerEntity); tool.Name = toolForUpdate.Name; tool.Description = toolForUpdate.Description; tool.DailyCost = toolForUpdate.DailyCost; tool.ReplacementCost = toolForUpdate.ReplacementCost; tool.QuantityAvailable = toolForUpdate.QuantityAvailable; _toolRepository.Update(tool.ToolId, tool); }
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); }
public CheckoutRecord CreateCheckoutRecord(CheckoutRecordForCreationDto checkoutRecordForCreation) { //***Validate input; //TODO //map the creation dto to regular checkoutRecord CheckoutRecord checkoutRecord = new CheckoutRecord() { ItemCheckedOutId = checkoutRecordForCreation.ItemCheckedOutId, CustomerId = checkoutRecordForCreation.CustomerId, DateCheckedOut = checkoutRecordForCreation.DateCheckedOut, DateDue = checkoutRecordForCreation.DateDue, AgreedDailyCost = checkoutRecordForCreation.AgreedDailyCost, Notes = checkoutRecordForCreation.Notes, //Just need a placeholder for return date DateReturned = DateTime.MinValue, AmountPaid = 0, HasBeenReturned = false }; /* * public string ItemCheckedOutId {get;set;} * public string CustomerId {get;set;} * public DateTime DateCheckedOut {get;set;} * public DateTime DateDue {get;set;} * public IList<string> Notes {get;set;} * public Decimal AgreedDailyCost {get;set;} */ /* * public string CheckoutRecordId {get;set;} * * public string ItemCheckedOutId {get;set;} * * public string CustomerId {get;set;} * * public DateTime DateCheckedOut {get;set;} * public DateTime DateDue {get;set;} * public DateTime DateReturned {get;set;} * public IList<string> Notes {get;set;} * public decimal AgreedDailyCost {get;set;} * public decimal AmountPaid {get;set;} * * public Boolean HasBeenReturned {get;set;} */ CheckoutRecord createdCheckoutRecord = _checkoutRecordRepository.Create(checkoutRecord); //decrement the item id quantity string itemId = createdCheckoutRecord.ItemCheckedOutId; //later, generalize to be items instead of tools Tool originalTool = _toolServices.GetToolById(itemId); ToolForUpdateDto tool = new ToolForUpdateDto() { Name = originalTool.Name, Description = originalTool.Description, DailyCost = originalTool.DailyCost, ReplacementCost = originalTool.ReplacementCost, QuantityAvailable = --originalTool.QuantityAvailable }; _toolServices.UpdateTool(itemId, tool); return(createdCheckoutRecord); }