public IActionResult CreateCheckoutRecord([FromBody] CheckoutRecordForCreationDto checkoutRecordForCreation) { try { if (checkoutRecordForCreation == 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")); } CheckoutRecord createdCheckoutRecord = _checkoutRecordServices.CreateCheckoutRecord(checkoutRecordForCreation); return(CreatedAtRoute("CheckoutRecordById", new { id = createdCheckoutRecord.CheckoutRecordId }, createdCheckoutRecord)); } catch (Exception ex) { _logger.LogError($"Something went wrong inside CreateOwner action: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public CheckoutRecord Create(CheckoutRecord checkoutRecord) { _repositoryContext.CheckoutRecords.InsertOne(checkoutRecord); //_repositoryContext.Tools.UpdateOne Console.WriteLine("checkoutRecord after inserting:" + checkoutRecord.CheckoutRecordId); // return(checkoutRecord); }
/* * 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;} */ public void DeleteCheckoutRecord(CheckoutRecord checkoutRecordToDelete) { _checkoutRecordRepository.Remove(checkoutRecordToDelete); //todo shouldn't these return true or false? or deal with an exception }
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); }
public void Remove(CheckoutRecord checkoutRecordIn) { _repositoryContext.CheckoutRecords.DeleteOne(checkoutRecord => checkoutRecord.CheckoutRecordId == checkoutRecordIn.CheckoutRecordId); }
public void Update(string id, CheckoutRecord checkoutRecordIn) { _repositoryContext.CheckoutRecords.ReplaceOne(checkoutRecord => checkoutRecord.CheckoutRecordId == id, checkoutRecordIn); }