public ActionResult <FiscalYearDTO> Put([FromBody] FiscalYearDTO fiscalYearDto) { try { if (!ModelState.IsValid) { _logger.LogError("Invalid model state."); return(BadRequest()); } else { var fiscalYear = _mapper.Map <FiscalYear>(fiscalYearDto); _fiscalYearRepo.UpdateFiscalYear(fiscalYear); _fiscalYearRepo.Save(); return(Ok(fiscalYearDto)); } } catch (Exception e) { _logger.LogError("Exception occurred while attempting to update a Fiscal Year.\nError: " + e.Message); return(BadRequest()); } }
public ActionResult <FiscalYearDTO> Post([FromBody] FiscalYearDTO fiscalYearDto) { try { if (!ModelState.IsValid) { _logger.LogError("Invalid model state."); return(BadRequest()); } else { var fiscalYear = _mapper.Map <FiscalYear>(fiscalYearDto); _fiscalYearRepo.AddFiscalYear(fiscalYear); _fiscalYearRepo.Save(); return(Created($"/api/FiscalYears/{fiscalYear.FiscalYearId}", fiscalYearDto)); } } catch (Exception e) { _logger.LogError("Exception occurred while attempting to add a Fiscal Year.\nError: " + e.Message); return(BadRequest()); } }
public void MapFromDomainEntity_NullContent_ReturnNull() { //Act var response = FiscalYearDTO.MapFromDatabaseEntity(null); //Assert Assert.IsNull(response); }
public static FiscalYear MapFromDomainEntity(FiscalYearDTO fiscalYear) { if (fiscalYear == null) { return(null); } return(new FiscalYear() { Id = fiscalYear.Id, Value = fiscalYear.Value, Position = fiscalYear.Position }); }
public void MapFromDomainEntity_ValidEntity_ReturnDTOEntity() { //Arrange var fiscalYear = new FiscalYearDTO() { Id = Guid.NewGuid(), Value = "2016", Position = 0 }; var response = FiscalYear.MapFromDomainEntity(fiscalYear); Assert.IsNotNull(response); Assert.AreEqual(fiscalYear.Id, response.Id); Assert.AreEqual(fiscalYear.Value, response.Value); Assert.AreEqual(fiscalYear.Position, response.Position); }