Esempio n. 1
0
        public async Task ImportAsync(Guid competitionId, string name, Stream stream, CultureInfo cultureInfo)
        {
            var data = VantageXml.Load(stream);

            using (var context = contextFactory())
                using (var transaction = context.BeginTransaction(IsolationLevel.Serializable))
                    try
                    {
                        if (data.Competition != null)
                        {
                            var competition = await context.Competitions.FirstOrDefaultAsync(c => c.Id == competitionId);

                            if (competition == null)
                            {
                                throw new CompetitionNotFoundException();
                            }

                            if (data.Competition.Id != competitionId)
                            {
                                throw new VantageImportException(Resources.CompetitionIdDoesNotMatch);
                            }

                            await ImportCompetitionResultsAsync(context, competition, data.Competition);
                        }

                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                        throw;
                    }
        }
Esempio n. 2
0
        public async Task ImportAsync(string name, Stream stream, bool importPeople = true, Func <Competition, int> overrideClass = null)
        {
            var data        = VantageXml.Load(stream);
            var competition = data.Competition;

            if (competition != null && overrideClass != null)
            {
                competition.Class = overrideClass(competition);
            }

            using (var context = contextFactory())
                using (var transaction = context.BeginTransaction(IsolationLevel.Serializable))
                    try
                    {
                        if (data.People != null && importPeople)
                        {
                            await ImportPeopleAsync(context, data.People);
                        }

                        if (competition != null)
                        {
                            var current = await context.Competitions.FirstOrDefaultAsync(c => c.Id == competition.Id);

                            if (current != null)
                            {
                                await ImportCompetitionResultsAsync(context, current, competition);
                            }
                            else
                            {
                                await ImportReportTemplateAsync(context, competition);

                                context.Competitions.Add(competition);
                                await context.SaveChangesAsync();
                            }
                        }

                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                        throw;
                    }
        }