コード例 #1
0
        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());
            }
        }
コード例 #2
0
        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());
            }
        }
コード例 #3
0
        public void MapFromDomainEntity_NullContent_ReturnNull()
        {
            //Act
            var response = FiscalYearDTO.MapFromDatabaseEntity(null);

            //Assert
            Assert.IsNull(response);
        }
コード例 #4
0
ファイル: FiscalYear.cs プロジェクト: rmohan20195/API-Mock
        public static FiscalYear MapFromDomainEntity(FiscalYearDTO fiscalYear)
        {
            if (fiscalYear == null)
            {
                return(null);
            }

            return(new FiscalYear()
            {
                Id = fiscalYear.Id,
                Value = fiscalYear.Value,
                Position = fiscalYear.Position
            });
        }
コード例 #5
0
        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);
        }