示例#1
0
        private Result register(User newUser, Specialization specialization)
        {
            if (loginAlreadyExists(newUser.Login))
            {
                return(new Result(false, Properties.Resources.LoginIsAlreadyTaken));
            }
            if (mailAlreadyExists(newUser.MailAddress))
            {
                return(new Result(false, Properties.Resources.MailIsAlreadyTaken));
            }

            var user = newUser;

            user.Password = encrypter.Encrypt(user.Password);

            // Muszę zapisać użytkownika do bazy, a potem go pobrać, żeby miał przydzielony przez bazę ID
            UsersRepository.Add(user);
            user = UsersRepository.GetList().Where(x => x.Login == user.Login && x.Password == user.Password).First();

            var userSpecialization = new UserSpecialization(user.Id, specialization.Id);

            UsersSpecializationsRepository.Add(userSpecialization);

            return(new Result(true));
        }
示例#2
0
 public bool Subscribe(User user, Specialization specialization)
 {
     try
     {
         var userSpecialization = new UserSpecialization(user.Id, specialization.Id);
         UsersSpecializationsRepository.Add(userSpecialization);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }