Пример #1
0
        private Student CreateStudent(StudentDTO studentDto, int localeId)
        {
            var studentRes = Database.Students.Get(new FilterExpression <Student>(s => s.Email == studentDto.Email)).FirstOrDefault();

            if (studentRes == null)
            {
                var student = Mapper.Map <StudentDTO, Student>(studentDto);

                student.StatusCreationDate = DateTime.Now;
                student.GroupId            = 1;
                student.Login =
                    $"{studentDto.GetLastName(localeId)}{studentDto.GetFirstName(localeId).Substring(0, 1).ToUpper()}{studentDto.GetPatronymic(localeId).Substring(0, 1).ToUpper()}";
                student.Password = CreateRandomPassword(8);

                Database.Students.Add(student);
                studentRes = student;
            }
            else
            {
                if (string.IsNullOrWhiteSpace(studentRes.Login))
                {
                    studentRes.Login =
                        $"{studentDto.GetLastName(localeId)}{studentDto.GetFirstName(localeId).Substring(0, 1).ToUpper()}{studentDto.GetPatronymic(localeId).Substring(0, 1).ToUpper()}";
                    Database.Students.Update(studentRes);
                }
                if (string.IsNullOrWhiteSpace(studentRes.Password))
                {
                    studentRes.Password = CreateRandomPassword(8);
                    Database.Students.Update(studentRes);
                }
            }
            return(studentRes);
        }