public async Task <Response <KweetDto> > CreateKweetAsync(Guid profileId, string message) { var response = new Response <KweetDto>(); var profile = await _context.Profiles.FindAsync(profileId); if (profile == null) { return(response); } var kweet = new Kweet { Id = Guid.NewGuid(), Profile = profile, Message = message, DateOfCreation = DateTime.Now }; await _context.Kweets.AddAsync(kweet); var success = await _context.SaveChangesAsync() > 0; if (success) { response.Success = true; response.Data = _mapper.Map <KweetDto>(kweet); } return(response); }
private KweetViewModel MapKweet(Kweet kweet) { var vm = _mapper.Map <Kweet, KweetViewModel>(kweet); if (int.TryParse(User.FindFirst("sub")?.Value, out int userId)) { vm.IsLiked = kweet.Likes.Any(l => l.UserId.Equals(userId)); } return(vm); }
public async Task InsertRangeForKweet(Kweet kweet, ICollection <HashTag> hashTags) { foreach (var hashTag in hashTags) { await _repository.InsertAsync(new HashTagInKweet { HashTag = hashTag, HashTagId = hashTag.Id, Kweet = kweet, KweetId = kweet.Id }); } }
public async Task <CommandResponse> Handle(CreateKweetCommand request, CancellationToken cancellationToken) { ProfileAggregate aggregate = await _kweetRepository.GetAsync(request.UserId, cancellationToken); Kweet kweet = aggregate.CreateKweetAsync(request.Message); kweet = _kweetRepository.TrackKweet(kweet); var success = await _kweetRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken); return(new CommandResponse { Success = success }); }
public Task <Kweet> CreateKweet(Guid kweetModelUserid, string kweetModelUsername, string kweetModelContent, string jwt) { if (kweetModelUserid != _jwtIdClaimReaderHelper.getUserIdFromToken(jwt)) { throw new NotAuthenticatedException(); } var kweet = new Kweet { Content = kweetModelContent, DateTime = DateTime.Now, Writer = new User { Id = kweetModelUserid, Username = kweetModelUsername }, Likes = new List <User>() }; return(_repository.Create(kweet)); }
private async Task Seed() { user1 = new ApplicationUser { UserName = "******", FirstName = "user 1", LastName = "lastname" }; await _context.AddAsync(user1); await _context.SaveChangesAsync(); kweet1 = new Kweet { Date = DateTime.Now.AddDays(-6), Description = "Description 1", User = user1, UserId = user1.Id }; kweet2 = new Kweet { Date = DateTime.Now.AddDays(-6), Description = "Description 2", User = user1, UserId = user1.Id }; kweet3 = new Kweet { Date = DateTime.Now.AddDays(-8), Description = "Description 3", User = user1, UserId = user1.Id }; _kweetService.Insert(kweet2); _kweetService.Insert(kweet1); await _unitOfWork.SaveChangesAsync(); hashTag1 = new HashTag { Title = "HashTag 1" }; hashTag2 = new HashTag { Title = "HashTag 2" }; hashTag3 = new HashTag { Title = "HashTag 3" }; _hashTagService.Insert(hashTag1); _hashTagService.Insert(hashTag2); _hashTagService.Insert(hashTag3); await _unitOfWork.SaveChangesAsync(); var hashTagInKweet1 = new HashTagInKweet { HashTag = hashTag1, HashTagId = hashTag1.Id, Kweet = kweet1, KweetId = kweet1.Id }; var hashTagInKweet2 = new HashTagInKweet { HashTag = hashTag2, HashTagId = hashTag2.Id, Kweet = kweet1, KweetId = kweet1.Id }; var hashTagInKweet3 = new HashTagInKweet { HashTag = hashTag3, HashTagId = hashTag3.Id, Kweet = kweet1, KweetId = kweet1.Id }; var hashTagInKweet4 = new HashTagInKweet { HashTag = hashTag2, HashTagId = hashTag2.Id, Kweet = kweet2, KweetId = kweet2.Id }; var hashTagInKweet5 = new HashTagInKweet { HashTag = hashTag1, HashTagId = hashTag1.Id, Kweet = kweet3, KweetId = kweet3.Id }; _hashTagInKweetService.Insert(hashTagInKweet1); _hashTagInKweetService.Insert(hashTagInKweet2); _hashTagInKweetService.Insert(hashTagInKweet3); _hashTagInKweetService.Insert(hashTagInKweet4); _hashTagInKweetService.Insert(hashTagInKweet5); await _unitOfWork.SaveChangesAsync(); }
private async Task Seed() { user1 = new ApplicationUser { FirstName = "User1", MiddleName = "Middle", LastName = "Lastname" }; _userService.Insert(user1); user2 = new ApplicationUser { FirstName = "User2", MiddleName = "Middle", LastName = "Lastname" }; _userService.Insert(user2); await _unitOfWork.SaveChangesAsync(); kweet1 = new Kweet { Id = 1, User = user1, UserId = user1.Id, Description = "first kweet", Date = new DateTime(2018, 3, 7) }; _kweetService.Insert(kweet1); kweet2 = new Kweet { Id = 2, User = user1, UserId = user1.Id, Description = "second kweet", Date = new DateTime(2018, 3, 8) }; _kweetService.Insert(kweet2); _kweetService.Insert( new Kweet { Id = 3, User = user2, UserId = user2.Id, Description = "third kweet", Date = new DateTime(2018, 3, 6) }); _kweetService.Insert( new Kweet { Id = 4, User = user2, UserId = user2.Id, Description = "fourth kweet", Date = new DateTime(2018, 3, 6) }); _kweetService.Insert( new Kweet { Id = 5, User = user2, UserId = user2.Id, Description = "fifth kweet", Date = new DateTime(2018, 3, 6) }); await _unitOfWork.SaveChangesAsync(); like1 = new Like { Id = 1, Kweet = kweet1, KweetId = kweet1.Id, User = user1, UserId = user1.Id }; _likeService.Insert(like1); await _unitOfWork.SaveChangesAsync(); }
public Kweet TrackKweet(Kweet kweet) { return(_context.Kweets.Add(kweet).Entity); }
public async void Remove(Kweet kweetIn) => await _kweets.DeleteOneAsync(kweet => kweet.Id == kweetIn.Id);
public async Task Update(Guid id, Kweet kweetIn) => await _kweets.ReplaceOneAsync(kweet => kweet.Id == id, kweetIn);
public async Task <Kweet> Create(Kweet kweet) { await _kweets.InsertOneAsync(kweet); return(kweet); }
private async Task Seed() { user1 = new ApplicationUser { UserName = "******", FirstName = "user 1", LastName = "lastname" }; await _context.AddAsync(user1); await _context.SaveChangesAsync(); kweet1 = new Kweet { Date = DateTime.Now.AddDays(-6), Description = "Description 1", User = user1, UserId = user1.Id }; kweet2 = new Kweet { Date = DateTime.Now.AddDays(-6), Description = "Description 2", User = user1, UserId = user1.Id }; kweet3 = new Kweet { Date = DateTime.Now.AddDays(-8), Description = "Description 3", User = user1, UserId = user1.Id }; await _kweetRepository.InsertAsync(kweet2); await _kweetRepository.InsertAsync(kweet1); await _unitOfWork.SaveChangesAsync(); hashTag1 = new HashTag { Title = "HashTag 1" }; hashTag2 = new HashTag { Title = "HashTag 2" }; hashTag3 = new HashTag { Title = "HashTag 3" }; await _hashTagRepository.InsertRangeAsync(new List <HashTag> { hashTag1, hashTag2, hashTag3 }); await _unitOfWork.SaveChangesAsync(); var hashTagInKweet1 = new HashTagInKweet { HashTag = hashTag1, HashTagId = hashTag1.Id, Kweet = kweet1, KweetId = kweet1.Id }; var hashTagInKweet2 = new HashTagInKweet { HashTag = hashTag2, HashTagId = hashTag2.Id, Kweet = kweet1, KweetId = kweet1.Id }; var hashTagInKweet3 = new HashTagInKweet { HashTag = hashTag3, HashTagId = hashTag3.Id, Kweet = kweet1, KweetId = kweet1.Id }; var hashTagInKweet4 = new HashTagInKweet { HashTag = hashTag2, HashTagId = hashTag2.Id, Kweet = kweet2, KweetId = kweet2.Id }; var hashTagInKweet5 = new HashTagInKweet { HashTag = hashTag1, HashTagId = hashTag1.Id, Kweet = kweet3, KweetId = kweet3.Id }; await _hashTagInKweetRepository.InsertRangeAsync(new List <HashTagInKweet> { hashTagInKweet1, hashTagInKweet2, hashTagInKweet3, hashTagInKweet4, hashTagInKweet5 }); await _unitOfWork.SaveChangesAsync(); }