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);
        }
Beispiel #2
0
        public User DeleteUser(Credentials credentials)
        {
            // Get user if username matches and user is not deleted
            var user = GetAndValidateUser(credentials);

            user.Deleted = true;
            _context.Update(user);
            _context.SaveChanges();
            return(user);
        }