public async Task <IActionResult> Create() { SportsCenterCreateReq req = new SportsCenterCreateReq(); IEnumerable <SportGetListResItem> sports = await _sports.GetListAsync(new SportGetListReq { }); req.AvailableSports = new List <System.Web.Mvc.SelectListItem>(); foreach (SportGetListResItem sport in sports) { req.AvailableSports.Add(new System.Web.Mvc.SelectListItem { Text = sport.Name, Value = sport.Name }); } return(View(req)); }
public async Task <SportsCenterCreateRes> CreateAsync(SportsCenterCreateReq req) { SportsCenter sportsCenter = new SportsCenter { Name = req.Name, PhotoUrl = req.PhotoUrl, Description = req.Description, }; _dbContext.SportsCenters.Add(sportsCenter); await _dbContext.SaveChangesAsync(); #region Handle Fields IEnumerable <SportGetListResItem> sports = await _sports.GetListAsync(new SportGetListReq { }); foreach (string sport in req.SelectedSports) { int sportId = sports .Where(s => s.Name == sport) .Select(s => s.Id) .FirstOrDefault(); Field field = new Field { SportId = sportId, SportsCenterId = sportsCenter.Id }; _dbContext.Fields.Add(field); } await _dbContext.SaveChangesAsync(); #endregion return(new SportsCenterCreateRes { Id = sportsCenter.Id }); }
public async Task <IActionResult> List(SportGetListReq req) { IEnumerable <SportGetListResItem> res = await _sports.GetListAsync(req); return(View(res)); }