Exemplo n.º 1
0
        public IHttpActionResult DeleteExternalLogin(int id)
        {
            // Allow only for authorized user
            var userToCheck = _userRepository.FirstOrDefault(u => u.UserName == User.Identity.Name);

            if (!userToCheck.Authorized)
            {
                return(Unauthorized());
            }

            // Get the DB externalLogin corresponding to the externalLogin ID
            ExternalLogin dbExternalLogin = _externalLoginRepository.GetByID(id);

            if (dbExternalLogin == null)
            {
                return(NotFound());
            }

            // Remove the externalLogin
            _externalLoginRepository.Delete(dbExternalLogin);

            try
            {
                _unitOfWork.Commit();
            }
            catch (Exception e)
            {
                throw new Exception("Unable to delete the externalLogin from the database", e);
            }

            return(Ok(Mapper.Map <ExternalLoginModel>(dbExternalLogin)));
        }
Exemplo n.º 2
0
        public IHttpActionResult DeleteUser(int id)
        {
            // Allow only for authorized user
            var userToCheck = _userRepository.FirstOrDefault(u => u.UserName == User.Identity.Name);

            if (!userToCheck.Authorized)
            {
                return(Unauthorized());
            }

            // Get the DB user corresponding to the user ID
            User dbUser = _userRepository.GetByID(id);

            if (dbUser == null)
            {
                return(NotFound());
            }

            // Remove any external logins corresponding to user
            var dbExternalLogins = _externalLoginRepository.Where(el => el.UserID == id);

            if (dbExternalLogins.Count() > 0)
            {
                foreach (var dbExternalLogin in dbExternalLogins)
                {
                    _externalLoginRepository.Delete(dbExternalLogin);
                }
            }

            // Remove the user
            _userRepository.Delete(dbUser);

            try
            {
                _unitOfWork.Commit();
            }
            catch (Exception e)
            {
                throw new Exception("Unable to delete the user from the database", e);
            }

            return(Ok(Mapper.Map <UserModel>(dbUser)));
        }