示例#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);
     }
 }
示例#3
0
        public void AddUserToDivisions(UserForRegisterDto userForRegister, User user, UserForDetailedDto userForDetailed)
        {
            if (userForRegister.Year != 0)
            {
                var specialization = _specializationsRepo.GetSpecializationByName(userForRegister.Specialization);

                var group = _groupsRepo.GetGroupByName(userForRegister.Group);

                var subGroup = _subGroupsRepo.GetSubGroupByName(userForRegister.SubGroup);

                UserSpecialization userSpecialization = new UserSpecialization
                {
                    UserId           = user.Id,
                    SpecializationId = specialization.Id
                };

                _genericsRepo.Add(userSpecialization);

                UserGroup userGroup = new UserGroup
                {
                    UserId  = user.Id,
                    GroupId = group.Id
                };

                _genericsRepo.Add(userGroup);

                UserSubGroup userSubGroup = new UserSubGroup
                {
                    UserId     = user.Id,
                    SubGroupId = subGroup.Id
                };

                _genericsRepo.Add(userSubGroup);

                userForDetailed.Specialization = specialization.Name;
                userForDetailed.Group          = group.Name;
                userForDetailed.SubGroup       = subGroup.Name;

                _genericsRepo.SaveAll();
            }
        }