public async Task <bool> Handle(CreateCourseCommand request, CancellationToken cancellationToken) { var entity = mapper.Map <Course>(request); var course = await this.context.Course.SingleOrDefaultAsync(c => c.Code == request.Code); if (course != null) { throw new ArgumentException($"The course already exisit with code: {request.Code} , code must be unique"); } context.Course.Add(entity); var result = await context.SaveChangesAsync(cancellationToken); return(result > 0); }
public async Task <bool> Handle(CreateStudentCommand request, CancellationToken cancellationToken) { var entity = await this.context.Student.SingleOrDefaultAsync(c => c.Id == request.Id); if (entity != null) { throw new ArgumentException($"The student already exisit with id: {request.Id}, id must be unique"); } var student = mapper.Map <Student>(request); context.Student.Add(student); var result = await context.SaveChangesAsync(cancellationToken); return(result > 0); }