Пример #1
0
 public void DeleteUser(User user)
 {
     if (user.Id == 0)
         return;
     user.FirstName = "DeletedUser" + user.Id.ToString();
     user.LastName = null;
     user.Institute = null;
     user.Password = Encryption.EncryptPassword(DateTime.Now.ToString());
     var perm = new Permission {Id = 1};
     user.Permission = perm;
     user.PermissionPermissionId = perm.Id;
     user.Picture = null;
     user.PhoneNumber = null;
     user.Email = null;
     using (var db = new TSPDSContext())
     {
         db.Entry(user).State = EntityState.Modified;
         db.User.AddOrUpdate(user);
         db.SaveChanges();
     }
 }
Пример #2
0
 private void ValidatePermission(Permission perm)
 {
     using (var db = new TSPDSContext())
     {
         var query = from b in db.Permission where b.Id == perm.Id select b;
         if (!query.Any())
             throw new DALOutOfRangeException("Permission id is out of range");
     }
 }
Пример #3
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();
            }
        }
Пример #4
0
 public void InsertUser(User user, Permission perm)
 {
     ValidateUser(user);
     ValidatePermission(perm);
     using (var db = new TSPDSContext())
     {
         var query = from s in db.User where s.Email.ToLower() == user.Email.ToLower() select s;
         if (query.Any())
             throw new DALAlreadyExistsException("User already exists");
         user.Permission = perm;
         user.PermissionPermissionId = perm.Id;
         db.Entry(user).State = EntityState.Modified;
         db.User.Add(user);
         db.SaveChanges();
     }
 }