public async Task <IActionResult> Create(int id) { Announcement announcement = await AnnouncementService.FindByIdAsync(id); if (announcement == null) { return(NotFound()); } var control = announcement.Likes.Exists(l => l.User.Equals(CurrentUser)); if (control) { return(BadRequest(new { message = "Zaten bu duyuruyu beğendiniz." })); } if (announcement.User.Equals(CurrentUser)) { return(BadRequest(new { message = "Kendi duyurunuzu beğenemezsiniz." })); } await LikeService.AddLikeAsync(CurrentUser, announcement); return(Ok()); }
public async Task AddAsync_AddLikeToAlreadyLikedAdvert() { Mock <IUnitOfWork> UOWMock = new Mock <IUnitOfWork>(); UOWMock.Setup(uow => uow.AdvertRepository.GetAsync(It.IsAny <int>())) .ReturnsAsync(new Advert { Likes = new List <Like> { new Like { UserId = "user_1", } } }); UOWMock.Setup(uow => uow.LikeRepository.Create(It.IsAny <Like>())); ILikeService likeService = new LikeService(_mapper, UOWMock.Object); await likeService.AddAsync(new CreateLikeDto { AdvertId = 1, UserId = "user_1" }); UOWMock.Verify(uow => uow.LikeRepository.Create(It.IsAny <Like>()), Times.Never); }
public AboutViewModel() { Title = "Profile"; Stories = new ObservableCollection <Story>(); LoadStoriesCommand = new Command(async() => await ExecuteLoadItemsCommand()); User = new ApplicationUser { Id = Services.Setting.UserId, Name = Services.Setting.Name, UserName = Services.Setting.UserName, Photo = Services.Setting.Photo }; MessagingCenter.Subscribe <AboutPage, int>(this, "ToggleLike", async(obj, id) => { var story = Stories.Where(s => s.Id == id).SingleOrDefault(); story.IsLike = !story.IsLike; story.LikeCount = story.IsLike ? story.LikeCount + 1 : story.LikeCount - 1; await LikeService.ToggleAsync(id, Services.Setting.UserId); }); MessagingCenter.Subscribe <AboutPage, MediaFile>(this, "ChangeProfile", async(obj, photoFile) => { Services.Setting.Photo = await UserService.Update(Services.Setting.UserId, Services.Setting.Name, photoFile); User.Photo = Services.Setting.Photo; }); }
public HomeController() { _articleService = new ArticleService(); _appUserService = new AppUserService(); _commentService = new CommentService(); _likeService = new LikeService(); }
public async Task DeleteTest() { var fakeRepository = Mock.Of <ILikeRepository>(); var likeService = new LikeService(fakeRepository); int likeId = 1; await likeService.Delete(likeId); }
public async Task AddLikeShoutAddItInDB() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); var postRepository = new EfDeletableEntityRepository <Post>(dbContext); var likeRepository = new EfRepository <Like>(dbContext); dbContext.Posts.Add(new Post { Id = "postId", Text = "text", CreatedOn = DateTime.UtcNow, UserId = "userId", UserName = "******", }); await dbContext.SaveChangesAsync(); var service = new LikeService(postRepository, likeRepository); await service.CreateLike("userId", "postId", "david"); Assert.Equal(1, dbContext.Likes.Count()); }
public async Task GetLikeTest() { var likes = new List <Like> { new Like() { Active = true, ProfileId = 1 }, new Like() { Active = false, ProfileId = 2 }, }; var fakeRepositoryMock = new Mock <ILikeRepository>(); fakeRepositoryMock.Setup(x => x.GetAll()).ReturnsAsync(likes); var likeService = new LikeService(fakeRepositoryMock.Object); var resultLikes = await likeService.GetLikes(); Assert.Collection(resultLikes, like => { Assert.True(like.Active); }, like => { Assert.Equal(2, like.ProfileId); }); }
public IHttpActionResult Get() { LikeService likeService = CreateNoteService(); var Like = likeService.GetAllLikes(); return(Ok(Like)); }
public IHttpActionResult Get(int postId) { LikeService likeService = CreateLikeService(); var likes = likeService.GetLikesByPostId(postId); return(Ok(likes)); }
public async Task Unlike(string surveyId, string userId, string authenticationToken) { try { LikeService likeService = new LikeService(); var response = await likeService.Unlike(surveyId, userId, authenticationToken); if (!response.IsSuccessStatusCode) { if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { throw new Exception("Unauthorized"); } else { throw new Exception(response.StatusCode.ToString() + " - " + response.ReasonPhrase); } } } catch (Exception ex) { throw new Exception(ex.Message); } }
public void ChangeLikeLess(string parameters) { int commentId = Convert.ToInt32(parameters); using (SampleContext context = new SampleContext()) { var rowComment = context.comments.SingleOrDefault(x => x.commentId == commentId); if (rowComment != null) { var rowUser = context.users.SingleOrDefault(x => x.userId == rowComment.userId); --rowUser.countLike; --rowComment.countLike; context.SaveChanges(); } var rowLike = context.likes.SingleOrDefault(x => x.userId == UserService.user.userId && x.commendId == commentId); if (rowLike != null) { rowLike.isLike = false; context.SaveChanges(); } else { LikeService.InsertNew(commentId, UserService.user.userId, false); } } }
public TweetController() { _commentService = new CommentService(); _appUserService = new AppUserService(); _likeService = new LikeService(); _tweetService = new TweetService(); }
public IHttpActionResult Get() { LikeService likeService = CreateLikeService(); var likes = likeService.GetLikes(); return(Ok(likes)); }
//GET LIKE BY ID public IHttpActionResult Get(int id) { LikeService likeService = CreateLikeService(); var like = likeService.GetLikeById(id); return(Ok(like)); }
private LikeService CreateLikeService() { var userId = Guid.Parse(User.Identity.GetUserId()); var likeService = new LikeService(userId); return(likeService); }
public IHttpActionResult PutLikeService(int id, LikeService likeService) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != likeService.likeId) { return(BadRequest()); } db.Entry(likeService).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!LikeServiceExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public CommentController() { _commentService = new CommentService(); _appUserService = new AppUserService(); _likeService = new LikeService(); _postService = new PostService(); }
public PostController() { _postService = new PostService(); _appUserService = new AppUserService(); _categoryService = new CategoryService(); _commentService = new CommentService(); _likeService = new LikeService(); }
public ArticleController() { _articleService = new ArticleService(); _categoryService = new CategoryService(); _appUserService = new AppUserService(); _commentService = new CommentService(); _likeService = new LikeService(); }
public IndexModel(ILogger <IndexModel> logger, [FromServices] PostService postService, [FromServices] CommentService commentService, [FromServices] UserService userService, [FromServices] LikeService likeService) { _logger = logger; _postService = postService; _commentService = commentService; _userService = userService; _likeService = likeService; }
public LikeController(LikeService likeService, CurrentUser currentUser, FriendService friendService, PostService postService) { this.friendService = friendService; this.currentUser = currentUser; this.likeService = likeService; this.postService = postService; }
public int likes(int id) { LikeService likeService = new LikeService(); int likess = likeService.nbrLike(id).Count(); return(likess); }
public ArticleController() { likedb = new LikeService(); db = new ArticleService(); userDb = new UserService(); cmdb = new CommentService(); msgdb = new MessageService(); }
public FeedController(UserService userService, PostService postService, CurrentUser currentUser, LikeService likeService, IMapper mapper, AppSettings settings) : base(settings, mapper) { this.likeService = likeService; this.currentUser = currentUser; this.postService = postService; this.userService = userService; }
public HomeController() { _tweetService = new TweetService(); _appUserService = new AppUserService(); _commentService = new CommentService(); _likeService = new LikeService(); _retweetService = new RetweetService(); _dMSendService = new DMSendService(); }
public async Task EditTest() { var fakeRepository = Mock.Of <ILikeRepository>(); var likeService = new LikeService(fakeRepository); var like = new Like() { ProfileId = 1, Active = false, PostId = 1 }; await likeService.Edit(like); }
public async Task <List <Like> > Index() { var settings = ConnectionSettings.CreateBasicAuth(Neo4JClient.uri, Neo4JClient.user, Neo4JClient.password); using (var client = new Neo4JClient(settings)) { LikeService myService = new LikeService(client); return(await myService.getAllLikes()); } }
public async Task AddTest() { var fakeRepository = Mock.Of <ILikeRepository>(); var likeService = new LikeService(fakeRepository); var like = new Like() { Active = true, ProfileId = 1 }; await likeService.AddAndSafe(like); }
public ProductController(ILogger <ProductController> logger, ProductService productservice, ProductCharacteristicService productCharacteristicService, CommentService commentService, LikeService likeService, UserManager <User> userManager, IMapper mapper) { _logger = logger; _productservice = productservice; _commentService = commentService; _categoryService = categoryService; this._productCharacteristicService = productCharacteristicService; _likeService = likeService; _userManager = userManager; _mapper = mapper; }
static void Main(string[] args) { LikeService userService = new LikeService(); userService.Like(); FollowService followService = new FollowService(); followService.Follow(); Console.ReadKey(); }