| | 1 | | using Syki.Back.Features.Cross.CreateUser; |
| | 2 | | using Syki.Back.Features.Cross.SendResetPasswordToken; |
| | 3 | |
|
| | 4 | | namespace Syki.Back.Features.Academic.CreateTeacher; |
| | 5 | |
|
| 384 | 6 | | public class CreateTeacherService(SykiDbContext ctx, CreateUserService service, SendResetPasswordTokenService sendServic |
| | 7 | | { |
| | 8 | | public async Task<OneOf<TeacherOut, SykiError>> Create(Guid institutionId, CreateTeacherIn data) |
| | 9 | | { |
| 118 | 10 | | await using var transaction = await ctx.Database.BeginTransactionAsync(); |
| | 11 | |
|
| 118 | 12 | | var userIn = CreateUserIn.NewTeacher(institutionId, data.Name, data.Email); |
| 118 | 13 | | var result = await service.Create(userIn); |
| | 14 | |
|
| 136 | 15 | | if (result.IsError()) return result.GetError(); |
| | 16 | |
|
| 100 | 17 | | var user = result.GetSuccess(); |
| | 18 | |
|
| 100 | 19 | | var teacher = new SykiTeacher(user.Id, institutionId, data.Name); |
| | 20 | |
|
| 100 | 21 | | ctx.Add(teacher); |
| 100 | 22 | | ctx.Add(SykiTask.LinkOldNotifications(user.Id, institutionId)); |
| | 23 | |
|
| 100 | 24 | | await sendService.Send(new(user.Email)); |
| | 25 | |
|
| 100 | 26 | | await transaction.CommitAsync(); |
| | 27 | |
|
| 100 | 28 | | return teacher.ToOut(); |
| 118 | 29 | | } |
| | 30 | | } |