public LecturerEntity Create(LecturerExcelModel lecturerExcelModel) { var userEntity = new UserEntity(); userEntity.Password = lecturerExcelModel.Password; userEntity.Username = lecturerExcelModel.Username.Trim(); UserService.Create(userEntity); var users = context.Users.Where(u => u.Username == userEntity.Username).ToList(); if (users.Count > 1) { throw new BadRequestException("Lecture was existed!"); } var user = users.FirstOrDefault(); user.Role = 4; context.SaveChanges(); //Create User var newLecturerEntity = new LecturerEntity(); newLecturerEntity = lecturerExcelModel.ToEntity(newLecturerEntity); newLecturerEntity.Id = user.Id; var newLecturer = new Lecturer(newLecturerEntity); context.Lecturers.Add(newLecturer); context.SaveChanges(); return(newLecturerEntity); }
public LecturerEntity Create([FromBody] LecturerExcelModel LecturerExcelModel) { return(LecturerService.Create(LecturerExcelModel)); }