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());
        }
示例#2
0
        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);
        }
示例#3
0
        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;
            });
        }
示例#4
0
 public HomeController()
 {
     _articleService = new ArticleService();
     _appUserService = new AppUserService();
     _commentService = new CommentService();
     _likeService    = new LikeService();
 }
示例#5
0
 public async Task DeleteTest()
 {
     var fakeRepository = Mock.Of <ILikeRepository>();
     var likeService    = new LikeService(fakeRepository);
     int likeId         = 1;
     await likeService.Delete(likeId);
 }
示例#6
0
        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());
        }
示例#7
0
        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); });
        }
示例#8
0
        public IHttpActionResult Get()
        {
            LikeService likeService = CreateNoteService();
            var         Like        = likeService.GetAllLikes();

            return(Ok(Like));
        }
示例#9
0
        public IHttpActionResult Get(int postId)
        {
            LikeService likeService = CreateLikeService();
            var         likes       = likeService.GetLikesByPostId(postId);

            return(Ok(likes));
        }
示例#10
0
        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);
            }
        }
示例#11
0
        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();
 }
示例#13
0
        public IHttpActionResult Get()
        {
            LikeService likeService = CreateLikeService();
            var         likes       = likeService.GetLikes();

            return(Ok(likes));
        }
示例#14
0
        //GET LIKE BY ID
        public IHttpActionResult Get(int id)
        {
            LikeService likeService = CreateLikeService();
            var         like        = likeService.GetLikeById(id);

            return(Ok(like));
        }
示例#15
0
        private LikeService CreateLikeService()
        {
            var userId      = Guid.Parse(User.Identity.GetUserId());
            var likeService = new LikeService(userId);

            return(likeService);
        }
示例#16
0
        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();
 }
示例#18
0
 public PostController()
 {
     _postService     = new PostService();
     _appUserService  = new AppUserService();
     _categoryService = new CategoryService();
     _commentService  = new CommentService();
     _likeService     = new LikeService();
 }
示例#19
0
 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;
 }
示例#21
0
 public LikeController(LikeService likeService, CurrentUser currentUser,
                       FriendService friendService, PostService postService)
 {
     this.friendService = friendService;
     this.currentUser   = currentUser;
     this.likeService   = likeService;
     this.postService   = postService;
 }
示例#22
0
        public int likes(int id)
        {
            LikeService likeService = new LikeService();

            int likess = likeService.nbrLike(id).Count();

            return(likess);
        }
示例#23
0
 public ArticleController()
 {
     likedb = new LikeService();
     db     = new ArticleService();
     userDb = new UserService();
     cmdb   = new CommentService();
     msgdb  = new MessageService();
 }
示例#24
0
 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();
 }
示例#26
0
 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());
            }
        }
示例#28
0
 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);
 }
示例#29
0
 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;
 }
示例#30
0
        static void Main(string[] args)
        {
            LikeService userService = new LikeService();

            userService.Like();

            FollowService followService = new FollowService();

            followService.Follow();

            Console.ReadKey();
        }