Exemplo n.º 1
0
        public async Task <ActionResult> EditGlobalCompetitions(int id, GlobalCompetitionDto competitionDto)
        {
            var check = await _competitionLogic.Edit(id, competitionDto);

            if (!check)
            {
                return(BadRequest());
            }
            return(Ok());
        }
Exemplo n.º 2
0
        public async Task <ActionResult> AddGlobalCompetitions(GlobalCompetitionDto competitionDto)
        {
            var check = await _competitionLogic.Add(competitionDto);

            if (!check)
            {
                return(BadRequest());
            }
            return(Ok());
        }
        public async Task <bool> Edit(int id, GlobalCompetitionDto competitionDto)
        {
            if (string.IsNullOrWhiteSpace(competitionDto.Name))
            {
                return(false);
            }
            var competition = await _context.GlobalCompetitions.FindAsync(id);

            if (competition == null)
            {
                return(false);
            }

            competition.Name = competitionDto.Name;
            await _context.SaveChangesAsync();

            return(true);
        }
        public async Task <bool> Add(GlobalCompetitionDto competitionDto)
        {
            if (string.IsNullOrWhiteSpace(competitionDto.Name))
            {
                return(false);
            }
            var region = await _context.Regions.FindAsync(competitionDto.RegionId);

            if (region == null)
            {
                return(false);
            }

            var competition = new GlobalCompetition
            {
                Name   = competitionDto.Name,
                Region = region,
            };

            _context.GlobalCompetitions.Add(competition);
            await _context.SaveChangesAsync();

            return(true);
        }