public async Task <ClubModel> Handle(CreateClubCommand request, CancellationToken cancellationToken) { var club = mapper.Map <Club>(request); await dbContext.Clubs.AddAsync(club, cancellationToken); await dbContext.SaveChangesAsync(cancellationToken); return(mapper.Map <ClubModel>(club)); }
public async Task <UserModel> Handle(CreateUserCommand request, CancellationToken cancellationToken) { var user = mapper.Map <User>(request); user.Role = await dbContext.Roles.FirstAsync(r => r.Name == "sportsman", cancellationToken); await dbContext.Users.AddAsync(user, cancellationToken); await dbContext.SaveChangesAsync(cancellationToken); return(mapper.Map <UserModel>(user)); }
public async Task <ClubModel> Handle(UpdateClubCommand request, CancellationToken cancellationToken) { var club = mapper.Map <Club>(request); var clubInBd = dbContext.Clubs.Find(request.Id); if (clubInBd is null) { return(null); } dbContext.Clubs.Remove(clubInBd); dbContext.Clubs.Add(club); await dbContext.SaveChangesAsync(cancellationToken); return(mapper.Map <ClubModel>(club)); }
public async Task <DeleteModel> Handle(DeleteClubCommand request, CancellationToken cancellationToken) { var clubInBd = dbContext.Clubs.Find(request.Id); if (clubInBd is null) { return(new DeleteModel { IsDeletionSuccessful = false }); } dbContext.Clubs.Remove(clubInBd); await dbContext.SaveChangesAsync(cancellationToken); return(new DeleteModel { IsDeletionSuccessful = true }); }