Пример #1
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));
        }
Пример #2
0
        public async Task <List <ReferenceDto> > GetAsync(Competition competition, ReferenceType type)
        {
            var result = await context.References.Where(x => x.Competition == competition && x.Type == type).ToListAsync();

            return(mapper.Map <List <ReferenceDto> >(result));
        }