/// <summary> /// Verifies that the given <see cref="WolfItem"/> contains the correct data. The method will exit early if any of the verfication steps fail. /// </summary> /// <param name="wolfToVerify">The <see cref="WolfItem"/> to verify the data of.</param> /// <returns>A boolean that is true if everything is correct, and false otherwise.</returns> private bool VerifyGivenData(WolfItem wolfToVerify) { bool dataIsValid = true; //TODO: //Verify that the birthdate is correct. dataIsValid = VerifyGivenDate(wolfToVerify.BirthDate); if (!dataIsValid) { return(dataIsValid); } //Verify that the gender is one of the five allowed numbers (0, 1, 2, 3, 9). dataIsValid = VALID_GENDERS.Any(gender => wolfToVerify.Gender == gender); if (!dataIsValid) { return(dataIsValid); } //Verify that the location data is correct. dataIsValid = VerifyLocationData(wolfToVerify.Location); if (!dataIsValid) { return(dataIsValid); } return(dataIsValid); }
public async Task <IActionResult> PutWolfItem(long id, WolfItem wolfItem) { if (id != wolfItem.Id) { return(BadRequest()); } if (VerifyGivenData(wolfItem) == false) { return(UnprocessableEntity()); } _context.Entry(wolfItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WolfItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <WolfItem> > PostWolfItem(WolfItem wolfItem) { if (VerifyGivenData(wolfItem) == false) { return(UnprocessableEntity()); } _context.WolfItems.Add(wolfItem); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetWolfItem), new { id = wolfItem.Id }, wolfItem)); }