private void ValidateIfObjectIsNotNull(ClubFullServiceModel club) { if (club is null) { throw new ArgumentNullException("The Club cannot be null and needs to have value."); } }
public async Task <ClubFullServiceModel> CreateClubAsync(ClubFullServiceModel club) { ValidateIfObjectIsNotNull(club); ValidateIfInputIsNotNullOrEmpty(club.Name); ValidateIfNameAlreadyExists(club.Name); Club clubToCreate = this.mapper.Map <Club>(club); await SetDefaultImagePathIfImagePathIsNull(clubToCreate); await SetDefaultDescriptionIfDescriptionIsNull(clubToCreate); await db.Clubs.AddAsync(clubToCreate); await db.SaveChangesAsync(); Club clubCreated = db.Clubs.FirstOrDefault(x => x.Name == club.Name && x.Description == clubToCreate.Description); return(this.mapper.Map <ClubFullServiceModel>(clubCreated)); }
public async Task <ClubFullServiceModel> UpdateClubAsync(ClubFullServiceModel club) { ValidateClubId(club.Id); ValidateIfClubIsDeleted(club.Id); ValidateIfInputIsNotNullOrEmpty(club.Name); ValidateIfInputIsNotNullOrEmpty(club.Description); var clubInDb = await db.Clubs.FindAsync(club.Id); clubInDb.Name = club.Name; clubInDb.Description = club.Description; clubInDb.Image = club.Image; await db.SaveChangesAsync(); var clubInDbUpdated = await db.Clubs .Include(x => x.Students) .ThenInclude(clubStudent => clubStudent.Student) .Include(x => x.Teachers) .ThenInclude(clubTeacher => clubTeacher.Teacher) .FirstOrDefaultAsync(x => x.Id == club.Id); return(this.mapper.Map <ClubFullServiceModel>(clubInDbUpdated)); }
public async Task <IActionResult> Post([FromBody] ClubFullServiceModel club) { var clubCreated = await this.clubService.CreateClubAsync(club); return(Ok(clubCreated)); }