private void CreateAncestryForNewReply(Tweet tweetThatWasRepliedTo, Tweet tweetThatIsAReply)
        {
            var ancestors = GetAncestors(tweetThatWasRepliedTo);

            ancestors.Add(tweetThatWasRepliedTo.Id);
            foreach (var ancestorId in ancestors)
            {
                _context.Add(new Ancestry()
                {
                    ChildId    = tweetThatIsAReply.Id,
                    AncestorId = ancestorId,
                });
            }
            _context.SaveChanges();
        }
Example #2
0
        public User CreateUser(User user)
        {
            user.Joined = DateTime.Now;
            try
            {
                _context.Add(user);
                _context.SaveChanges();
            }
            catch (DbUpdateException e)
            {
                if (e.InnerException.Message.Contains("unique constraint")) // hmm
                {
                    var existingUser = _context.Users
                                       .FirstOrDefault(u => u.Credentials.Username == user.Credentials.Username);
                    if (existingUser != null)
                    {
                        existingUser.Deleted = false;
                        _context.Update(existingUser);
                        return(existingUser);
                    }
                }
            }

            return(user);
        }
Example #3
0
        public User CreateUser(User user)
        {
            user.Joined = DateTime.Now;
            try
            {
                _context.Add(user);
                _context.SaveChanges();
            }
            catch (DbUpdateException e)
            {
                if (e.InnerException.Message.Contains("unique constraint")) // hmm
                {
                    throw new UsernameTakenException();
                }
            }

            return(user);
        }
Example #4
0
 public async Task InsertPost(Post post)
 {
     _context.Add(post);
     await _context.SaveChangesAsync();
 }