public void InsertTest() { OkNegotiatedContentResult <decimal?> pk4 = (OkNegotiatedContentResult <decimal?>)_controller.Insert(new OccupationsModel() { Name = "Pilot [TEST]", OccupationRating = new OccupationRatingsModel() { Id = 1 // Professional; 1.0 } }); _primaryKeyPool.Add(pk4.Content); var response = _controller.GetById((int)_primaryKeyPool[4]); Assert.IsNotNull(response); Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult <OccupationsModel>)); OkNegotiatedContentResult <OccupationsModel> result = (OkNegotiatedContentResult <OccupationsModel>)response; Assert.IsNotNull(result.Content); Assert.IsInstanceOfType(result.Content, typeof(OccupationsModel)); OccupationsModel content = (OccupationsModel)result.Content; Assert.AreEqual(content.Id, _primaryKeyPool[4]); }
public void UpdateByIdTest() { var response = _controller.GetById((int)_primaryKeyPool[2]); Assert.IsNotNull(response); Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult <OccupationsModel>)); OkNegotiatedContentResult <OccupationsModel> result = (OkNegotiatedContentResult <OccupationsModel>)response; Assert.IsNotNull(result.Content); Assert.IsInstanceOfType(result.Content, typeof(OccupationsModel)); OccupationsModel content = (OccupationsModel)result.Content; Assert.AreEqual(content.Id, _primaryKeyPool[2]); string originalName = content.Name; decimal originalOccupationRatingId = content.OccupationRating.Id; content.Name += " [Name Update]"; content.OccupationRating.Id = 2; // White Collar, 1.25 _controller.UpdateById(content); response = _controller.GetById((int)_primaryKeyPool[2]); Assert.IsNotNull(response); Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult <OccupationsModel>)); result = (OkNegotiatedContentResult <OccupationsModel>)response; Assert.IsNotNull(result.Content); Assert.IsInstanceOfType(result.Content, typeof(OccupationsModel)); content = (OccupationsModel)result.Content; Assert.AreEqual(content.Name, originalName + " [Name Update]"); Assert.AreEqual(content.OccupationRating.Id, 2); }
public decimal?Insert(OccupationsModel model) { try { if (string.IsNullOrEmpty(model.Name)) { throw new ApplicationException("Occupation name cannot be an empty string."); } if (model.OccupationRating == null || model.OccupationRating.Id <= 0) { throw new ApplicationException("Invalid occupation rating selected."); } return(_OccupationsRepository.Insert(model)); } catch (Exception ex) { while (ex.Message.IndexOf("See the inner exception for details.") > 0) { ex = ex.InnerException; } _logger.LogError(ex.Message); throw ex; } }
public void UpdateById(OccupationsModel model) { try { if (string.IsNullOrEmpty(model.Name)) { throw new ApplicationException($"Occupation name cannot be an empty string. Occupational Id was {model.Id}."); } if (model.OccupationRating == null || model.OccupationRating.Id <= 0) { throw new ApplicationException($"Invalid occupation rating selected. Occupational Id was {model.Id}."); } _OccupationsRepository.UpdateById(model); } catch (Exception ex) { while (ex.Message.IndexOf("See the inner exception for details.") > 0) { ex = ex.InnerException; } _logger.LogError(ex.Message); throw ex; } }
public IHttpActionResult UpdateById(OccupationsModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _occupationsService.UpdateById(model); return(Ok(true)); }
public IHttpActionResult Insert([FromBody] OccupationsModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = _occupationsService.Insert(model); return(Ok(result)); }
public void GetByIdTest() { var response = _controller.GetById((int)_primaryKeyPool[1]); Assert.IsNotNull(response); Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult <OccupationsModel>)); OkNegotiatedContentResult <OccupationsModel> result = (OkNegotiatedContentResult <OccupationsModel>)response; Assert.IsNotNull(result.Content); Assert.IsInstanceOfType(result.Content, typeof(OccupationsModel)); OccupationsModel content = (OccupationsModel)result.Content; Assert.AreEqual(content.Id, _primaryKeyPool[1]); }
public void UpdateById(OccupationsModel model) { _context.spOccupations_UpdateById(model.Id, model.Name, model.OccupationRating.Id); }
public decimal?Insert(OccupationsModel model) { return(_context.spOccupations_Insert(model.Name, model.OccupationRating.Id).FirstOrDefault()); }