public async Task <EditFeedResponse> AddFeedAsync(FeedDto feed) { var response = new EditFeedResponse(); try { var now = DateTime.Now; var newFeed = new Feed { Class = feed.Class, Mappings = feed.Mappings, Created = now, Updated = now }; var addedArticle = this.feedRepository.Insert(newFeed); await this.unitOfWork.CommitAsync(); response.Status = ResponseStatus.OK; } catch (Exception ex) { //this.logService.LogError(ex, new HttpContextWrapper(HttpContext.Current)); response.Status = ResponseStatus.SystemError; } return(response); }
public FeedDto Create(FeedDto feedDto, int userId) { if (string.IsNullOrWhiteSpace(feedDto.Name)) { throw new ValidationException("Feed name is empty"); } var collection = _database.Collections.GetById(feedDto.CollectionId); if (collection == null || collection.UserId != userId) { throw new ValidationException("Collection not found"); } var feeds = _database.Feeds.GetAll(f => f.CollectionId == feedDto.CollectionId).ToList(); if (feeds.Any(f => f.Name == feedDto.Name)) { throw new ValidationException($"Feed name \"{feedDto.Name}\" is already exists"); } var feed = _mapper.Map <Feed>(feedDto); _database.Feeds.Create(feed); _database.Save(); return(_mapper.Map <FeedDto>(feed)); }
public async Task ShouldContainsNewBetInFollowersFeed() { //arrange var memberId = Guid.NewGuid(); var betId = Guid.NewGuid(); var member = new Member(new(memberId), "toto", 0); var subscriptionId = Guid.NewGuid(); var subscriptionId2 = Guid.NewGuid(); member.Subscribe(new Subscription(new(subscriptionId))); member.Subscribe(new Subscription(new(subscriptionId2))); var bet = Bet.Create(new BetId(betId), new DateTime(2022, 2, 3), "desc1", 10, new(new(memberId), "toto", 300), new DateTime(2021, 3, 2)); var feed = new FeedDto(subscriptionId.ToString(), new List <BetDto>()); var feed2 = new FeedDto(subscriptionId2.ToString(), new List <BetDto>()); var betRepository = new InMemoryBetRepository(null, bet.State); var memberRepository = new InMemoryMemberRepository(new() { member }); var feedRepository = new InMemoryFeedRepository(new List <FeedDto>() { feed, feed2 }); var handler = new UpdateFeedMemberNotificationHandler(betRepository, memberRepository, feedRepository); var notification = new InsertBetQuerySideNotification(betId, memberId); //act await handler.Handle(notification, default); //assert AssertFeedSubscription(betId, subscriptionId, bet, feedRepository); AssertFeedSubscription(betId, subscriptionId2, bet, feedRepository); }
public PotatoFeed(FeedDto other) { Name = other.Name; FeedId = other.FeedId; Location = new GeoJsonPoint <GeoJson2DGeographicCoordinates>( new GeoJson2DGeographicCoordinates(other.Location.Longitude, other.Location.Latitude)); }
private FeedDto BindingFeed(SyndicationItem item) { var feedDto = new FeedDto(); feedDto.title = item.Title.Text; feedDto.text = Regex.Replace(item.Summary.Text, @"<[^>]*>", String.Empty); feedDto.id = Regex.Match(item.Id, @"\d+").Value; return(feedDto); }
public IActionResult ResponseForGet(FeedDto feedDto) { if (feedDto == null) { return(new NotFoundResult()); } var feedModel = _mapper.Map <FeedModel>(feedDto); return(new OkObjectResult(feedModel)); }
private List <NewsFromFeed> GetNewsFromFeed(FeedDto feed) { Logger.Log.Info($"Start pull news from {feed.Link}!"); List <IFeedItem> news = _remoteLoaderFeed.GetRemoteFeed(feed.Link) .Where(a => a.PublishedDate > (feed.LastNewsDate ?? DateTime.MinValue)) .OrderBy(a => a.PublishedDate) .ToList(); Logger.Log.Info($"Founded {news.Count} new news"); return(Mapper.Map <List <IFeedItem>, List <NewsFromFeed> >(news)); }
public void NewFeed(FeedDto feedDto) { Feed feeds = new Feed() { Agency = feedDto.Agency, Source = feedDto.Source, Description = feedDto.Description, DateAt = DateTime.Now }; Database.Feeds.Create(feeds); }
public async Task <Unit> Handle(GenerateFeedCommand request, CancellationToken cancellationToken) { var member = await _memberRepository.GetByIdAsync(new MemberId(Guid.Parse(request.MemberId))) ?? throw new MemberNotFoundException($"Member with id: {request.MemberId} is not found"); var bets = await _betRepository.GetBetsForFeedAsync(); var feedDto = new FeedDto(member.Id.ToString(), bets.Select(x => new BetDto(x.State))); await _feedRepository.SaveAsync(feedDto); return(Unit.Value); }
private async void UpdateFeedInDb(int feedId, DateTime?datePulling) { if (datePulling.HasValue) { Logger.Log.Info("Update feed in database!"); Logger.Log.Info($"Date the last added news {datePulling}!"); FeedDto feed = await _feederService.GetById(feedId); await _feederService.Remove(feedId); feed.LastNewsDate = datePulling; await _feederService.Create(feed); } }
public IActionResult Put(Guid id, [FromBody] CreateFeedRequest request) { var collection = _collections.Find(Builders <CollectionDto> .Filter.Eq(c => c.Id, id)).SingleOrDefault(); if (collection == null) { return(NotFound("Collection is not exist")); } var feed = new FeedDto { Id = Guid.NewGuid(), CollectionId = id, Summary = request.Summary, Text = request.Text }; _feeds.InsertOne(feed); _cache.Remove(id); return(Ok(feed)); }
public async Task <int> CreateOrUpdate(FeedDto input) { if (input.Id != 0) { var found = _repository.Get(input.Id); var mapped = input.MapTo(found); await _repository.InsertOrUpdateAndGetIdAsync(mapped); return(mapped.Id); } else { var mapped = input.MapTo <Feed>(); await _repository.InsertOrUpdateAndGetIdAsync(mapped); return(mapped.Id); } }
public void Update(FeedDto feedDto, int userId) { if (string.IsNullOrWhiteSpace(feedDto.Name)) { throw new ValidationException("Feed name is empty"); } var currentFeed = _database.Feeds.GetById(feedDto.Id); if (currentFeed == null) { throw new ValidationException("Feed not found"); } var collection = _database.Collections.GetById(feedDto.CollectionId); if (collection == null || collection.UserId != userId) { throw new ValidationException("Feed not found"); } if (feedDto.Name != currentFeed.Name) { // name of feed has changed so check if the new name of feed is already taken var userCollectonFeeds = _database.Feeds.GetAll(f => f.CollectionId == feedDto.CollectionId).ToList(); if (userCollectonFeeds.Any(f => f.Name == feedDto.Name)) { throw new ValidationException($"Feed name \"{feedDto.Name}\" is already exists"); } } // update feed properties currentFeed.Name = feedDto.Name; currentFeed.Description = feedDto.Description; currentFeed.Url = feedDto.Url; _database.Save(); }
public async Task AddFeedAsyncTest() { // arrange var unitOfWork = new MockUnitOfWork(); var feedService = new FeedService(unitOfWork); var mappings = new int[] { 5, 2, 3, 1, 4 }; var feed = new FeedDto { Class = "TestClass", Mappings = string.Join(",", mappings) }; // act var result = await feedService.AddFeedAsync(feed); // assert Assert.AreEqual(ResponseStatus.OK, result.Status); var repositoryItems = unitOfWork.FeedRepository.Get().ToList(); Assert.AreEqual(1, repositoryItems.Count()); }
public async Task <FeedDto> Update(FeedDto item) { Feed fedd = await _database.FeedRepository.Update(_mapper.Map <FeedDto, Feed>(item)); return(_mapper.Map <Feed, FeedDto>(fedd)); }
public async Task SaveAsync(FeedDto feed) { await _collection.InsertOneAsync(feed).ConfigureAwait(false); }
public Task SaveAsync(FeedDto feed) { _feeds.Add(feed); return(Task.CompletedTask); }
public FeedDto SendFeed(FeedDto feed) { feed.Id = _feeds.Count + 1; _feeds.Insert(0, feed); return(feed); }