Пример #1
0
        public Like Create(Like like)
        {
            if (_context.Likes.Any(x => x.Id == like.Id))
            {
                throw new AppException("this post is Like \"" + like.Id + "\" is already taken");
            }

            _context.Likes.Add(like);
            _context.SaveChanges();

            return(like);
        }
Пример #2
0
        public Deslike Create(Deslike deslike)
        {
            if (_context.Deslikes.Any(x => x.Id == deslike.Id))
            {
                throw new AppException("this post is DesLike \"" + deslike.Id + "\" is already taken");
            }

            _context.Deslikes.Add(deslike);
            _context.SaveChanges();

            return(deslike);
        }
        public Post Create(Post post)
        {
            if (_context.Posts.Any(x => x.Id == post.Id))
            {
                throw new AppException("this friendship \"" + post.Id + "\" is already taken");
            }

            _context.Posts.Add(post);
            _context.SaveChanges();

            return(post);
        }
        public Friendship Create(Friendship friendship)
        {
            if (_context.Friendships.Any(x => x.Id == friendship.Id))
            {
                throw new AppException("this friendship \"" + friendship.Id + "\" is already taken");
            }

            _context.Friendships.Add(friendship);
            _context.SaveChanges();

            return(friendship);
        }
        public void LogInformation(string message, string msgTemplate)
        {
            Log log = new Log
            {
                Message         = message,
                MessageTemplate = msgTemplate,
                Level           = "Information",
                TimeStamp       = DateTime.Now,
            };

            _context.Logs.Add(log);
            _context.SaveChanges();
        }
Пример #6
0
        public User Create(User user, string password)
        {
            // validation
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("Password is required");
            }

            if (_context.Users.Any(x => x.Username == user.Username))
            {
                throw new AppException("Username \"" + user.Username + "\" is already taken");
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            _context.Users.Add(user);
            _context.SaveChanges();

            return(user);
        }