public IActionResult UpdateRssFeed(int id, [FromBody] RssFeedDomainObj feedToBeUpdated) { if (feedToBeUpdated == null) { return(BadRequest()); } if (feedToBeUpdated.Description == feedToBeUpdated.Source) { ModelState.AddModelError("Description", "The provided description should be different from the Source."); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_rssFeedService.FeedExists(id)) { return(NotFound()); } var feedToBeUpdatedDto = Mapper.Map <RssFeedDto>(feedToBeUpdated); _rssFeedService.UpdateRssFeed(id, feedToBeUpdatedDto); return(NoContent()); }
public IActionResult CreateRssFeed([FromBody] RssFeedDomainObj feedToBeCreated) { if (feedToBeCreated == null) { return(BadRequest()); } if (feedToBeCreated.Source == feedToBeCreated.Description) { ModelState.AddModelError("Data", "The provided Data cannot be same as source"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var feedToBeCreatedDto = Mapper.Map <Models.RssFeedDto>(feedToBeCreated); _rssFeedService.CreateRssFeed(feedToBeCreatedDto); return(Ok()); } catch (Exception exception) { _logger.LogCritical($"Exception while saving Rss Feed", exception); return(StatusCode(500, "A problem happened while handling your request.")); } }