Exemple #1
0
        public IActionResult UpdateDeathDate(Dtos.UpdateDeathDate updateDeathDateDto)
        {
            if (updateDeathDateDto == null)
            {
                return(BadRequest("Dto object cannot be null."));
            }

            IEnumerable <Models.Reference> references = nyTimesService.GetReferencesByArticleTitle(updateDeathDateDto.ArticleTitle);

            if (references.Count() == 0)
            {
                return(NotFound($"Reference(s) not found. Requested article title = {updateDeathDateDto.ArticleTitle}."));
            }
            try
            {
                var reference = nyTimesService.UpdateDeathDate(references, updateDeathDateDto);

                return(Ok(MapModelToDto(reference, reference.DeathDate)));
            }
            catch (Exception e)
            {
                string message = $"Updating the reference(s) failed. Article title = {updateDeathDateDto.ArticleTitle}.";
                logger.LogError($"{message} Exception:\r\n{e}", e);
                return(BadRequest(message));
            }
        }
        public Reference UpdateDeathDate(IEnumerable <Reference> references, Dtos.UpdateDeathDate updateDeathDateDto)
        {
            // mini mapper
            references.ToList().ForEach(r => r.DeathDate = updateDeathDateDto.DeathDate);

            context.UpdateRange(references);

            context.SaveChanges();

            return(references.First());
        }