Exemple #1
0
        public async Task <Guid> AddAsync(TeamDto dto)
        {
            var reference = await context.References.FirstOrDefaultAsync(x =>
                                                                         x.Competition == dto.Competition &&
                                                                         x.Type == ReferenceType.Team &&
                                                                         x.ReferenceValue == dto.ReferenceId);

            if (reference != null)
            {
                throw new ItemAlreadyExistException($"Team with id {dto.ReferenceId} already exsits.");
            }

            if (dto.Id == Guid.Empty)
            {
                dto.Id = Guid.NewGuid();
            }

            await context.References.AddAsync(new Reference
            {
                Competition    = dto.Competition,
                Type           = ReferenceType.Team,
                LocalValue     = dto.Id.ToString().ToLowerInvariant(),
                ReferenceValue = dto.ReferenceId,
                Timestamp      = DateTime.Now
            });

            await context.Teams.AddAsync(mapper.Map <Team>(dto));

            await context.SaveChangesAsync();

            return(dto.Id);
        }
Exemple #2
0
        public async Task <Guid> AddAsync(JobDto jobDto)
        {
            var job = await context.Jobs.SingleOrDefaultAsync(x => x.Id == jobDto.Id);

            if (job != null)
            {
                throw new ItemAlreadyExistException($"Job {jobDto.Id} not found!");
            }

            job    = mapper.Map <Job>(jobDto);
            job.Id = Guid.NewGuid();
            context.Jobs.Add(job);

            await context.SaveChangesAsync();

            return(job.Id);
        }
Exemple #3
0
        public async Task <Guid> AddAsync(GameDto dto)
        {
            var game = await context.Games.SingleOrDefaultAsync(x => x.Id == dto.Id);

            if (game != null)
            {
                throw new ItemAlreadyExistException($"Game {game.Id} not found!");
            }

            game    = mapper.Map <Game>(dto);
            game.Id = Guid.NewGuid();
            context.Games.Add(game);

            await context.SaveChangesAsync();

            return(game.Id);
        }
Exemple #4
0
        public async Task <ReferenceDto> TryGetAsync(Competition competition, ReferenceType type, string value)
        {
            var reference = await context.References.SingleAsync(x => x.Competition == competition && x.Type == type && x.LocalValue == value);

            if (reference != null)
            {
                return(mapper.Map <ReferenceDto>(reference));
            }

            reference = new Reference
            {
                Type           = type,
                Competition    = competition,
                LocalValue     = value,
                ReferenceValue = Guid.NewGuid().ToString(),
                Timestamp      = DateTime.Now
            };

            await context.References.AddAsync(reference);

            await context.SaveChangesAsync();

            return(mapper.Map <ReferenceDto>(reference));
        }