コード例 #1
0
            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));
            }
コード例 #2
0
            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));
            }
コード例 #3
0
            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));
            }
コード例 #4
0
            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
                });
            }