Exemple #1
0
        public async Task <bool> UnlikeImagePost(int imagePostId, string userEmail)
        {
            using (ShowNTellDbContext context = _contextFactory.CreateDbContext())
            {
                bool success = false;

                try
                {
                    Like like = new Like()
                    {
                        ImagePostId = imagePostId,
                        UserEmail   = userEmail
                    };

                    context.Entry(like).State = EntityState.Deleted;
                    await context.SaveChangesAsync();

                    success = true;
                }
                catch (Exception)
                {
                    success = false;
                }

                return(success);
            }
        }
Exemple #2
0
        public async Task <bool> UnfollowUser(string userUsername, string followerEmail)
        {
            using (ShowNTellDbContext context = _contextFactory.CreateDbContext())
            {
                bool success = false;

                try
                {
                    User user = await context.Users.FirstOrDefaultAsync(u => u.Username == userUsername);

                    if (user != null)
                    {
                        Follow existingFollow = new Follow()
                        {
                            UserEmail     = user.Email,
                            FollowerEmail = followerEmail
                        };

                        context.Entry(existingFollow).State = EntityState.Deleted;
                        await context.SaveChangesAsync();

                        success = true;
                    }
                }
                catch (Exception)
                {
                    success = false;
                }

                return(success);
            }
        }