Ejemplo n.º 1
0
        public static Users UserFollowingCountMinus(PaintStoreContext db, int id)
        {
            var countTool = db.Users.First(x => x.Id == id);

            countTool.FollowingCount -= 1;
            return(countTool);
        }
Ejemplo n.º 2
0
        public SignInResult SignInCheck(SignInCommand signInCommand, PaintStoreContext db)
        {
            var userToSignIn = db.Users.FirstOrDefault(x => x.Email == signInCommand.Email);

            if (userToSignIn == null)
            {
                throw new UnauthorizedAccessException();
            }

            var soil          = _encoding.GetBytes(userToSignIn.PasswordSoil);
            var passwordBytes = _encoding.GetBytes(signInCommand.Password);

            var soiledPassword = Convert.ToBase64String(CredentialsHelpers.GenerateSaltedHash(passwordBytes, soil));

            if (soiledPassword != userToSignIn.PasswordHash)
            {
                throw new UnauthorizedAccessException();
            }

            if (userToSignIn.Token == null)
            {
                userToSignIn.Token = CredentialsHelpers.CreateSalt();
                return(new SignInResult()
                {
                    UserId = userToSignIn.Id, Token = userToSignIn.Token
                });
            }
            else
            {
                return(new SignInResult()
                {
                    UserId = userToSignIn.Id, Token = userToSignIn.Token
                });
            }
        }
Ejemplo n.º 3
0
        public static Users UserPostsCountPlus(PaintStoreContext db, int id)
        {
            var countTool = db.Users.First(x => x.Id == id);

            countTool.PostsCount += 1;
            return(countTool);
        }
Ejemplo n.º 4
0
        public static PostComments CommentLikesCountPlus(PaintStoreContext db, int id)
        {
            var countTool = db.PostComments.First(x => x.Id == id);

            countTool.LikeCount += 1;
            return(countTool);
        }
Ejemplo n.º 5
0
        public static Tags TagsCountPlus(PaintStoreContext db, int id)
        {
            var countTool = db.Tags.First(x => x.Id == id);

            countTool.Count += 1;
            return(countTool);
        }
Ejemplo n.º 6
0
        public static Posts ImageCommentCountMinus(PaintStoreContext db, int id)
        {
            var countTool = db.Posts.First(x => x.Id == id);

            countTool.CommentsCount -= 1;
            return(countTool);
        }
Ejemplo n.º 7
0
 public UsersService(PaintStoreContext ctx, IPostsService postsService, IFollowersService followersService, ISignInService signInService)
 {
     _paintStoreContext = ctx;
     _postsService      = postsService;
     _followersService  = followersService;
     _signInService     = signInService;
 }
Ejemplo n.º 8
0
        //To isolate
        private int PostRemover(int postId, PaintStoreContext db)
        {
            var tempPost = db.Posts.First(x => x.Id == postId);

            UsersManager.UserPostsCountMinus(db, tempPost.UserId);

            var tagsToRemove = db.PostTags.Where(x => x.PostId == postId).ToList();

            foreach (var tagToRemove in tagsToRemove)
            {
                db.PostTags.Remove(tagToRemove);
                TagsManager.TagsCountMinus(db, tagToRemove.TagId);
            }

            db.Posts.Remove(db.Posts.First(x => x.Id == postId));
            foreach (var like in db.PostLikes.Where(x => x.PostId == postId))
            {
                db.PostLikes.Remove(db.PostLikes.First(x => x.Id == like.Id));
            }

            foreach (var comment in db.PostComments.Where(x => x.PostId == postId))
            {
                db.PostComments.Remove(db.PostComments.First(x => x.Id == comment.Id));
                foreach (var like in db.CommentLikes.Where(x => x.CommentId == comment.Id))
                {
                    db.CommentLikes.Remove(db.CommentLikes.First(x => x.Id == like.Id));
                }
            }

            _cloudinaryService.DeleteImage(tempPost.ImgLink);

            return(postId);
        }
Ejemplo n.º 9
0
 private void CommentRemove(PostComments coment, PaintStoreContext db)
 {
     db.PostComments.Remove(db.PostComments.First(x => x.Id == coment.Id));
     ImagesManager.ImageCommentCountMinus(db, coment.PostId);
     foreach (var like in db.CommentLikes.Where(x => x.CommentId == coment.Id))
     {
         db.CommentLikes.Remove(db.CommentLikes.First(x => x.Id == like.Id));
     }
 }
Ejemplo n.º 10
0
        private int FollowRemove(int userIdFollowing, int userIdFollowed, PaintStoreContext db)
        {
            var followId = db.UserFollowers
                           .First(x => x.FollowingUserId == userIdFollowing && x.FollowedUserId == userIdFollowed).Id;

            var tempFollow = db.UserFollowers.First(x => x.Id == followId);

            FollowersManager.UserFollowedCountMinus(db, tempFollow.FollowedUserId);
            FollowersManager.UserFollowingCountMinus(db, tempFollow.FollowingUserId);
            db.UserFollowers.Remove(db.UserFollowers.First(x => x.Id == followId));
            return(followId);
        }
Ejemplo n.º 11
0
        public Tags GetOrAddTag(string tagName, PaintStoreContext db)
        {
            Tags tag = null;

            if (!db.Tags.Any(x => x.TagName == tagName))
            {
                tag = new Tags {
                    TagName = tagName
                };
                db.Tags.Add(tag);
                db.SaveChanges();
            }

            if (db.Tags.Any(x => x.TagName == tagName))
            {
                tag = db.Tags.First(x => x.TagName == tagName);
            }


            return(tag);
        }
Ejemplo n.º 12
0
 public TagsService(PaintStoreContext ctx)
 {
     _paintStoreContext = ctx;
 }
Ejemplo n.º 13
0
 public FollowersService(PaintStoreContext ctx, IMapper mapper)
 {
     _paintStoreContext = ctx;
     _mapper            = mapper;
 }
Ejemplo n.º 14
0
 public SignInService(PaintStoreContext ctx)
 {
     _paintStoreContext = ctx;
 }
Ejemplo n.º 15
0
 public PostCommentsService(PaintStoreContext ctx, IMapper mapper)
 {
     _paintStoreContext = ctx;
     _mapper            = mapper;
 }
Ejemplo n.º 16
0
 public StartChildImagesRmMessage(Users user, PaintStoreContext ctx)
 {
     UsersToRm = user;
     this.ctx  = ctx;
 }
Ejemplo n.º 17
0
 public SupervisorMessage_RmImages(Users user, PaintStoreContext ctx)
 {
     UserToRm = user;
     this.ctx = ctx;
 }
Ejemplo n.º 18
0
 public PostService(PaintStoreContext ctx, IMapper mapper, ICloudinaryService cloudinaryService)
 {
     _paintStoreContext = ctx;
     _mapper            = mapper;
     _cloudinaryService = cloudinaryService;
 }
Ejemplo n.º 19
0
 public LikesService(PaintStoreContext ctx)
 {
     _paintStoreContext = ctx;
 }
Ejemplo n.º 20
0
 public SearchController(PaintStoreContext paintStoreContext)
 {
     this.paintStoreContext = paintStoreContext;
 }