public async Task <ActionResult> Add(AddSportViewModel sportModel) { var sport = new DomainClasses.Sport { Name = sportModel.SportName }; if (sportModel.SportCategories != null && sportModel.SportCategories.Any()) { foreach (var sportCategory in sportModel.SportCategories) { sport.SportCategories.Add(new SportCategory() { Name = sportCategory.Name }); } } if (sportModel.SportDetails != null && sportModel.SportDetails.Any()) { foreach (var sportDetail in sportModel.SportDetails) { sport.SportDetails.Add(new SportDetail() { Name = sportDetail.Name }); } } _sportService.Add(sport); await _dbContext.SaveChangesAsync(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public async Task<ActionResult> Add(AddSportViewModel sportModel) { var sport = new DomainClasses.Sport { Name = sportModel.SportName }; if (sportModel.SportCategories != null && sportModel.SportCategories.Any()) { foreach (var sportCategory in sportModel.SportCategories) { sport.SportCategories.Add(new SportCategory() { Name = sportCategory.Name }); } } if (sportModel.SportDetails != null && sportModel.SportDetails.Any()) { foreach (var sportDetail in sportModel.SportDetails) { sport.SportDetails.Add(new SportDetail() { Name = sportDetail.Name }); } } _sportService.Add(sport); await _dbContext.SaveChangesAsync(); return new HttpStatusCodeResult(HttpStatusCode.OK); }