Beispiel #1
0
 public List<User> GetUsers(ParametersForUsers parameters)
 {
     using (var db = new TSPDSContext())
     {
         var query = db.User.AsQueryable();
         if (!string.IsNullOrWhiteSpace(parameters.FirstName))
             query = query.Where(x => x.FirstName.ToLower() == parameters.FirstName.ToLower());
         if (!string.IsNullOrWhiteSpace(parameters.LastName))
             query = query.Where(x => x.LastName.ToLower() == parameters.LastName.ToLower());
         if (!string.IsNullOrWhiteSpace(parameters.Institute))
             query = query.Where(x => x.Institute.ToLower() == parameters.Institute.ToLower());
         if (!string.IsNullOrWhiteSpace(parameters.Email))
             query = query.Where(x => x.Email.ToLower() == parameters.Email.ToLower());
         if (!string.IsNullOrWhiteSpace(parameters.PhoneNumber))
             query = query.Where(x => x.PhoneNumber == parameters.PhoneNumber);
         if (parameters.WaitingOnPromotion == true)
             query = query.Where(x => x.Permission.Id == 2);
         query = query.Include(x => x.Permission);
         return query.ToList();
     }
 }
Beispiel #2
0
        public void UpdateUserPermission(User user, Permission perm)
        {
            ValidateUser(user);
            ValidatePermission(perm);
            if (perm == null)
                throw new DALInfoNotSpecifiedException("User permission was not specified");
            if (perm.Id == 0)
                throw new DALInfoNotSpecifiedException("Permission id was not speciified");
            if (user.Id == 0)
                throw new DALInfoNotSpecifiedException("User id was not speciified");
            var param = new ParametersForUsers();
            param.Email = user.Email;
            var temp = GetUsers(param)[0];

            if (temp.Email != user.Email)
            {
                throw new DALInfoNotSpecifiedException("The user was not found in the databse");
            }

            using (var db = new TSPDSContext())
            {
                user.Permission = perm;
                user.PermissionPermissionId = perm.Id;
                db.User.AddOrUpdate(user);
                db.SaveChanges();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Method creates user and inserts it into database
        /// </summary>
        /// <param name="email">User email</param>
        /// <param name="confirmEmail">user email confirmed</param>
        /// <param name="Pass">user password</param>
        /// <param name="confirmPass">user password confirmed</param>
        /// <param name="fName">user first name</param>
        /// <param name="lName">user last name</param>
        public bool Create(string email, string confirmEmail, string pass, string confirmPass, string fName, string lName)
        {
            if (_confirmPass != _Pass)
            {
                return false;
            }

            try
            {
                IDalUserManagement dalUserManage = new MSSQLModelDAL();

                ParametersForUsers parameters = new ParametersForUsers()
                { Email = email };

                if (dalUserManage.GetUsers(parameters).Any())
                {
                    return false;
                }

                User user = new User()
                {
                    Email = email,
                    FirstName = fName,
                    LastName = lName,
                    Password = pass
                };

                Permission perm = dalUserManage.GetPermByAccessLevel(AccessLevel.Submitter);
                dalUserManage.InsertUser(user, perm);
                return true;
            }
            catch (NullReferenceException e)
            {

                return false;
            }
        }