コード例 #1
0
ファイル: GroupRepository.cs プロジェクト: sergiygladkyy/mbo
        public GroupUser AddGroupUser(GroupUser groupUser, long groupId, OldUser curator)
        {
            using (var groupUserRepository = new BaseRepository<GroupUser>())
            {
                var group = groupUserRepository.Context.Groups.FirstOrDefault(x => x.Id == groupId);

                if (group == null)
                {
                    throw new PersonsGroupDoesNotExistException();
                }

                if (!String.Equals(curator.Role.Name, Constraints.KCuratorRoleName)
                    || curator.Id != group.Curator)
                {
                    throw new UserRightsException();
                }

                if (String.IsNullOrWhiteSpace(groupUser.Email) || String.IsNullOrWhiteSpace(groupUser.FirstName)
                    || String.IsNullOrWhiteSpace(groupUser.LastName) || String.IsNullOrWhiteSpace(groupUser.MiddleName))
                {
                    throw new RequireFieldException();
                }

                //TODO: Refactor, optimization
                var code = CodeGenerator.Generate();
                while (!CheckCodeUnique(code))
                {
                    code = CodeGenerator.Generate();
                }

                groupUser.Code = code;
                groupUser.Group = group;

                if (!groupUserRepository.Create(groupUser).Status)
                {
                    throw new CreateException();
                }

                return groupUser;
            }
        }
コード例 #2
0
ファイル: ResultConverter.cs プロジェクト: sergiygladkyy/mbo
        public ResultConverter(OldUser oldUser, Test test)
        {
            _dbOldUser = oldUser;
            _dbTest = test;

            _shPerson = new ShellPerson();
            _shPerson.ID = oldUser.Id;
            _shPerson.bMale = oldUser.Gender;
            _shPerson.BirthDate = oldUser.BirthDate;
            _shPerson.Age = DateTime.Now.Year - _shPerson.BirthDate.Year;
            _shPerson.FirstName = oldUser.FirstName;
            _shPerson.LastName = oldUser.LastName;
            _shPerson.MidName = oldUser.MiddleName;

            //TODO : add group

            _shAnswers = String.Empty;

            _shTestSettings = new TestSettings();
            _shTestSettings.Title = test.CodeName;
        }
コード例 #3
0
ファイル: GroupRepository.cs プロジェクト: sergiygladkyy/mbo
        public void UpdateGroupUser(GroupUser groupUser, long groupId, OldUser curator)
        {
            using (var groupUserRepository = new BaseRepository<GroupUser>())
            {
                var group = groupUserRepository.Context.Groups.FirstOrDefault(x => x.Id == groupId);

                if (group == null)
                {
                    throw new PersonsGroupDoesNotExistException();
                }

                if (!String.Equals(curator.Role.Name, Constraints.KCuratorRoleName)
                    || curator.Id != group.Curator)
                {
                    throw new UserRightsException();
                }

                var updatedGroupUser = groupUserRepository.GetAllItems.FirstOrDefault(x => x.Id == groupUser.Id);
                if (updatedGroupUser == null)
                {
                    throw new UserDoesNotExistException();
                }

                if (updatedGroupUser.Group.Id != groupId)
                {
                    throw new GroupUserException();
                }

                if (String.IsNullOrWhiteSpace(groupUser.Email) || String.IsNullOrWhiteSpace(groupUser.FirstName)
                    || String.IsNullOrWhiteSpace(groupUser.LastName) || String.IsNullOrWhiteSpace(groupUser.MiddleName))
                {
                    throw new RequireFieldException();
                }

                //update  all fields except Id, code, group
                updatedGroupUser.Email = groupUser.Email;
                updatedGroupUser.BirthDate = groupUser.BirthDate;
                updatedGroupUser.Gender = groupUser.Gender;
                updatedGroupUser.FirstName = groupUser.FirstName;
                updatedGroupUser.LastName = groupUser.LastName;
                updatedGroupUser.MiddleName = groupUser.MiddleName;
                updatedGroupUser.Note = groupUser.Note;

                if (!groupUserRepository.Update(updatedGroupUser).Status)
                {
                    throw new UpdateException();
                }

            }
        }
コード例 #4
0
ファイル: GroupRepository.cs プロジェクト: sergiygladkyy/mbo
 public List<Group> GetGroups(OldUser curator)
 {
     if (!String.Equals(curator.Role.Name, Constraints.KCuratorRoleName, StringComparison.CurrentCulture))
     {
         throw new UserRightsException();
     }
     using (var groupRepository = new BaseRepository<Group>())
     {
         return groupRepository.GetAllItems.Where(x => x.Curator == curator.Id).ToList();
     }
 }
コード例 #5
0
ファイル: GroupRepository.cs プロジェクト: sergiygladkyy/mbo
        public List<GroupUser> GetGroupUsers(long groupId, OldUser curator)
        {
            if (!String.Equals(curator.Role.Name, Constraints.KCuratorRoleName, StringComparison.CurrentCulture))
            {
                throw new UserRightsException();
            }
            using (var groupUserRepository = new BaseRepository<GroupUser>())
            {
                var group = groupUserRepository.Context.Groups.FirstOrDefault(x => x.Id == groupId);

                if (group == null)
                {
                    throw new PersonsGroupDoesNotExistException();
                }

                if (!String.Equals(curator.Role.Name, Constraints.KCuratorRoleName)
                    || curator.Id != group.Curator)
                {
                    throw new UserRightsException();
                }

                return groupUserRepository.GetAllItems.Where(x => x.Group.Id == groupId).ToList();

            }

            //return null;
        }
コード例 #6
0
ファイル: GroupRepository.cs プロジェクト: sergiygladkyy/mbo
        public void DeleteGroupUser(GroupUser groupUser, long groupId, OldUser curator)
        {
            using (var groupUserRepository = new BaseRepository<GroupUser>())
            {
                var group = groupUserRepository.Context.Groups.FirstOrDefault(x => x.Id == groupId);

                if (group == null)
                {
                    throw new PersonsGroupDoesNotExistException();
                }

                if (!String.Equals(curator.Role.Name, Constraints.KCuratorRoleName)
                    || curator.Id != group.Curator)
                {
                    throw new UserRightsException();
                }

                var deletedGroupUser = groupUserRepository.GetAllItems.FirstOrDefault(x => x.Id == groupUser.Id);
                if (deletedGroupUser == null)
                {
                    throw new UserDoesNotExistException();
                }

                if (deletedGroupUser.Group.Id != groupId)
                {
                    throw new GroupUserException();
                }

                if (!groupUserRepository.Delete(deletedGroupUser).Status)
                {
                    throw new DeleteException();
                }

            }
        }
コード例 #7
0
 private void WriteUserResultInConsul(Result result, OldUser oldUser, Test test, ShellResult shell)
 {
     var dbManager = new ConsulIntegratorManager();
     dbManager.AddShellResult(oldUser, result, test, shell);
 }
コード例 #8
0
        // TODO : Hack
        public OldUser RegisterNew(OldUser oldUser)
        {
            using (var userRepository = new BaseRepository<OldUser>())
            {

                // Check password Validation (6 sevbols at least)
                if (oldUser.Password.Length < 6)
                {
                    throw new UserPasswordException();
                }

                var foundedUser =
                    userRepository.Context.OldUsers.Include("Role").FirstOrDefault(
                        x => String.Equals(x.Login, oldUser.Login) && String.Equals(x.Email, oldUser.Email));
                if (foundedUser != null)
                {
                    // Update password and non required fields; Gender; BirthDate
                    foundedUser.Password = oldUser.Password;
                    foundedUser.FirstName = oldUser.FirstName;
                    foundedUser.LastName = oldUser.LastName;
                    foundedUser.MiddleName = oldUser.MiddleName;

                    foundedUser.Gender = oldUser.Gender;
                    foundedUser.BirthDate = oldUser.BirthDate;

                    foundedUser.Token = Guid.NewGuid();
                    foundedUser.ExpirationDate = DateTime.Now.AddMinutes(20);

                    if (!userRepository.Update(foundedUser).Status)
                    {
                        throw new UpdateException();
                    }

                    return foundedUser;
                }

                foundedUser = userRepository.Context.OldUsers.Include("Role").FirstOrDefault(x => String.Equals(x.Login, oldUser.Login));
                var emailUser = userRepository.Context.OldUsers.Include("Role").FirstOrDefault(x => String.Equals(x.Email, oldUser.Email));
                if (foundedUser != null && emailUser != null)
                {
                    var userWithNewEmail =
                        userRepository.Context.OldUsers.Include("Role").FirstOrDefault(x => String.Equals(x.Email, oldUser.Email));
                    if (userWithNewEmail != null)
                    {
                        // OldUser with new Email exists
                        throw new UserEmailException();
                    }

                    // Update all non-required credentials and Email, Gender, BirthDate
                    foundedUser.Email = oldUser.Email;

                    foundedUser.Password = oldUser.Password;
                    foundedUser.FirstName = oldUser.FirstName;
                    foundedUser.LastName = oldUser.LastName;
                    foundedUser.MiddleName = oldUser.MiddleName;

                    foundedUser.Gender = oldUser.Gender;
                    foundedUser.BirthDate = oldUser.BirthDate;

                    foundedUser.Token = Guid.NewGuid();
                    foundedUser.ExpirationDate = DateTime.Now.AddMinutes(20);

                    if (!userRepository.Update(foundedUser).Status)
                    {
                        throw new UpdateException();
                    }

                    return foundedUser;
                }

                foundedUser = userRepository.Context.OldUsers.Include("Role").FirstOrDefault(x => String.Equals(x.Email, oldUser.Email));
                if (foundedUser != null)
                {

                    var userWithNewLogin =
                        userRepository.GetAllItems.FirstOrDefault(x => String.Equals(x.Login, oldUser.Login));
                    if (userWithNewLogin != null)
                    {
                        // OldUser with new Login exists
                        throw new UserLoginException();
                    }

                    // Update all non-required credentials and Login, Gender, BirthDate
                    foundedUser.Login = oldUser.Login;

                    foundedUser.Password = oldUser.Password;
                    foundedUser.FirstName = oldUser.FirstName;
                    foundedUser.LastName = oldUser.LastName;
                    foundedUser.MiddleName = oldUser.MiddleName;

                    foundedUser.Gender = oldUser.Gender;
                    foundedUser.BirthDate = oldUser.BirthDate;

                    foundedUser.Token = Guid.NewGuid();
                    foundedUser.ExpirationDate = DateTime.Now.AddMinutes(20);

                    if (!userRepository.Update(foundedUser).Status)
                    {
                        throw new UpdateException();
                    }

                    return foundedUser;
                }

                // Login and Email does not matched, register new OldUser
                oldUser.Token = Guid.NewGuid();
                oldUser.ExpirationDate = DateTime.Now.AddMinutes(20);
                oldUser.Role = userRepository.Context.Roles.FirstOrDefault(x => x.Name == Constraints.KClientRoleName);
                if (!userRepository.Create(oldUser).Status)
                {
                    throw new CreateException();
                }
                return oldUser;

            }
        }
コード例 #9
0
        public void Register(OldUser oldUser)
        {
            using (var userRepo = new BaseRepository<OldUser>())
            {

                if (userRepo.GetAllItems.Any(x => String.Compare(x.Login, oldUser.Login) == 0))
                {
                    throw new UserLoginException();
                    // TODO : Hack
                    //return;
                }
                if (userRepo.GetAllItems.Any(x => String.Compare(x.Email, oldUser.Email) == 0))
                {
                    throw new UserEmailException();
                    // TODO : Hack
                    //return;
                }

                oldUser.Token = Guid.NewGuid();
                oldUser.ExpirationDate = DateTime.Now.AddMinutes(20);
                oldUser.Role = userRepo.Context.Roles.FirstOrDefault(x => x.Name == Constraints.KClientRoleName);
                if (!userRepo.Create(oldUser).Status)
                {
                    throw new CreateException();
                }
            }
        }
コード例 #10
0
        public void AddShellResult(OldUser oldUser, Result result, Test test, ShellResult shellResut)
        {
            try
            {
                _connection.Open();
                int count = -1;

                // Check OldUser exists
                String name = oldUser.FirstName + " " + oldUser.LastName;
                if (name.Length == 1)
                {
                    name = String.Empty;
                }
                String login = oldUser.Login;
                String gender = String.Empty;
                if (oldUser.Gender)
                {
                    gender = "M";
                }
                else
                {
                    gender = "F";
                }
                var query = String.Empty;
                if (name.Length > 0)
                {
                    query = @"SELECT count(*) FROM [USER] where [NAME] = '" + name + "'" +
                           " AND [GENDER] = '" + gender + "' AND [DATE] = #" + oldUser.BirthDate.ToString("yyyy-MM-dd") + "#";
                }
                else
                {
                    query = @"SELECT count(*) FROM [USER] where [NAME] = '" + login + "'" +
                           " AND [GENDER] = '" + gender + "' AND [DATE] = #" + oldUser.BirthDate.ToString("yyyy-MM-dd") + "#";
                }

                //query = @"SELECT count(*) FROM [USER] where [NAME] IN ('" + name + "','" + login + "') " +
                //            " AND [GENDER] = '" + gender + "' AND [DATE] = #" + OldUser.BirthDate.ToString("yyyy-MM-dd") + "#";

                var command = new OleDbCommand(query, _connection);
                var reader = command.ExecuteReader();
                while (reader.Read())
                {
                    count = reader.GetInt32(0);
                }
                if (count <= 0)
                {

                    // Select firstname + lastname ot login
                    var resName = String.Empty;
                    if (name.Length <= 0)
                    {
                        resName = login;
                    }
                    else
                    {
                        resName = name;
                    }
                    // Cut name to 30 symbols
                    if (resName.Length >= 30)
                    {
                        resName = resName.Remove(29);
                    }

                    // Create OldUser
                    query = "INSERT INTO [USER] (NAME, GENDER, [DATE]) VALUES('"
                        + resName + "', '" + gender +"', #" + oldUser.BirthDate.ToString("yyyy-MM-dd") + "#)";
                    command = new OleDbCommand(query, _connection);
                    if (command.ExecuteNonQuery() <= 0)
                    {
                        throw new ConsulDBException();
                    }

                }

                // GET id of OldUser
                int userId = -1;

                if (name.Length > 0)
                {
                    query = @"SELECT ID FROM [USER] where [NAME] = '" + name + "'" +
                           " AND [GENDER] = '" + gender + "' AND [DATE] = #" + oldUser.BirthDate.ToString("yyyy-MM-dd") + "#";
                }
                else
                {
                    query = @"SELECT ID FROM [USER] where [NAME] = '" + login + "'" +
                           " AND [GENDER] = '" + gender + "' AND [DATE] = #" + oldUser.BirthDate.ToString("yyyy-MM-dd") + "#";
                }

                //query = @"SELECT ID FROM [USER] where [NAME] = '" + name + "'" +
                //            " AND [GENDER] = '" + gender + "' AND [DATE] = #" + OldUser.BirthDate.ToString("yyyy-MM-dd") + "#";
                command = new OleDbCommand(query, _connection);
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    userId = reader.GetInt32(0);
                }

                var comment = result.TestDate.ToString("dd.MM.yyyy_HH.mm.ss") + "_"
                                  + oldUser.FirstName + "_"
                                  + oldUser.LastName + "_"
                                  + oldUser.BirthDate.ToString("dd.MM.yyyy") + "_"
                                  + test.CodeName;

                // Create result
                query = "INSERT INTO [RESULT] (U_ID, M_ID, DATA, COMMENT, [DATE]) VALUES ("
                        + userId + ", " + shellResut.MethodId + ", '" + shellResut.Answer + "', '" + comment + "', #" + result.TestDate.ToString("yyyy-MM-dd HH:mm:ss") + "#)";
                command = new OleDbCommand(query, _connection);
                if (command.ExecuteNonQuery() <= 0)
                {
                    throw new ConsulDBException();
                }

                _connection.Close();
            }
            catch (Exception)
            {
                throw new ConsulDBException();
            }
        }