Ejemplo n.º 1
0
        public async Task <IActionResult> TeamCreate([Bind("Id,TeamName,TeamCode,SubDivisionId")]
                                                     Team team)
        {
            if (!ModelState.IsValid)
            {
                var divisionList = await _wpbService.GetSubDivisionDropListAsync();

                ViewData["SubDivision"] = new SelectList(divisionList, "Id", "SubDivisionTitle");
                return(View(team));
            }

            team.TeamCode = team.TeamCode.ToUpper();

            var subDivCodeExist = _wpbService.TeamCodeExist(team.TeamCode);

            if (subDivCodeExist)
            {
                var divisionList = await _wpbService.GetSubDivisionDropListAsync();

                ViewData["SubDivision"] = new SelectList(divisionList, "Id", "SubDivisionTitle");
                ModelState.AddModelError("", "$Team code: {team.TeamCode} is already in use.");
                return(View(team));
            }


            await _wpbService.CreateTeamAsync(team);

            return(RedirectToAction(nameof(TeamsAll)));
        }