Пример #1
0
        public async Task <ILecturerService.LecturerRegistrationResult> CreateLecturer(Lecturer lecturer, List <Course> courses)
        {
            ILecturerService.LecturerRegistrationResult result = ILecturerService.LecturerRegistrationResult.Success;
            using (DatabaseContext context = _contextFactory.CreateDbContext()) {
                User user1 = await _accountService.GetByEmail(lecturer.User.Email);

                if (user1 != null)
                {
                    result = ILecturerService.LecturerRegistrationResult.EmailAlreadyExists;
                }

                if (courses.Count < 1)
                {
                    result = ILecturerService.LecturerRegistrationResult.ZeroCourseFound;
                }

                if (result == ILecturerService.LecturerRegistrationResult.Success)
                {
                    lecturer.User.Type = (int)UserType.Lecturer;

                    User created = await _accountService.Create(lecturer.User);

                    Lecturer lecturerEntity = new Lecturer {
                        UserId = created.Id, Faculty = lecturer.Faculty
                    };
                    Lecturer lecturer1 = await Create(lecturerEntity);

                    foreach (var course in courses)
                    {
                        await _courseServices.AddLecturer(lecturer1, course);
                    }
                }
            }


            return(result);
        }