Inheritance: Database.Entities.Match
示例#1
0
        private void AddOrUpdate(Lag lag, Match match, DataContext context, MatchImport.ExcelMatch excelMatch, List <Vaapen> våpen)
        {
            var existing = (from l in context.Lag
                            where l.LagId == lag.LagId
                            select l).FirstOrDefault();

            if (existing == null)
            {
                context.Lag.Add(lag);
            }
            else
            {
                existing.Navn         = lag.Navn;
                existing.HemmeligKode = lag.HemmeligKode;
                existing.Farge        = lag.Farge;
            }

            if (!match.DeltakendeLag.Any(x => x.Lag.LagId == lag.LagId))
            {
                var lagIMatch = match.LeggTil(existing ?? lag);

                // Legg til våpen bare på nye lag i matcher (dvs. ikke få flere våper ved flere importer)
                var felle = våpen.Single(x => x.VaapenId == Constants.Våpen.Felle);
                for (int i = 0; i < excelMatch.PrLagFelle.GetValueOrDefault(); i++)
                {
                    lagIMatch.LeggTilVåpen(felle);
                }

                var bombe = våpen.Single(x => x.VaapenId == Constants.Våpen.Bombe);
                for (int i = 0; i < excelMatch.PrLagBombe.GetValueOrDefault(); i++)
                {
                    lagIMatch.LeggTilVåpen(bombe);
                }
            }
        }
示例#2
0
 public void SkrivTilExcel(MatchImport.ExcelMatch match, List <Lag> lagListe = null, List <PostImport.ExcelPost> poster = null)
 {
     SkrivMatch(match);
     SkrivLag(lagListe);
     SkrivDeltakere(lagListe);
     SkrivPoster(poster);
 }
示例#3
0
        private List <ExcelPost> LesFra(ExcelWorksheet excelWorksheet, MatchImport.ExcelMatch excelMatch)
        {
            var poster = new Dictionary <string, ExcelPost>();

            var sheet = excelWorksheet;

            for (int row = 2; row <= sheet.Dimension.End.Row; row++)
            {
                var post = new ExcelPost
                {
                    PostId            = Guid.NewGuid(),
                    Navn              = sheet.GetValue(ExcelSheet.Poster.Navn, row),
                    Beskrivelse       = sheet.GetValue(ExcelSheet.Poster.Beskrivelse, row),
                    HemmeligKode      = sheet.GetValue(ExcelSheet.Poster.HemmeligKode, row),
                    Omraade           = sheet.GetValue(ExcelSheet.Poster.Område, row),
                    Latitude          = double.Parse(sheet.GetValue <string>(ExcelSheet.Poster.Latitude, row)),
                    Longitude         = double.Parse(sheet.GetValue <string>(ExcelSheet.Poster.Longitude, row)),
                    Image             = sheet.GetValue <string>(ExcelSheet.Poster.BildeUrl, row),
                    DefaultPoengArray = sheet.GetValue <string>(ExcelSheet.Poster.PoengFordeling, row),
                };

                var altitude = sheet.GetValue <string>(ExcelSheet.Poster.Altitude, row);

                if (!string.IsNullOrEmpty(altitude))
                {
                    post.Altitude = double.Parse(altitude);
                }

                if (string.IsNullOrEmpty(post.DefaultPoengArray) && !string.IsNullOrEmpty(excelMatch.DefaultPoengFordeling))
                {
                    post.DefaultPoengArray = excelMatch.DefaultPoengFordeling;
                }

                var synligFra = sheet.GetValue <string>(ExcelSheet.Poster.SynligFra, row);
                var synligTil = sheet.GetValue <string>(ExcelSheet.Poster.SynligTil, row);

                if (!string.IsNullOrEmpty(synligFra))
                {
                    post.SynligFra = DateTime.Parse(synligFra);
                }

                if (!string.IsNullOrEmpty(synligTil))
                {
                    post.SynligTil = DateTime.Parse(synligTil);
                }

                // Siste rad gjelder hvis duplikater
                var nøkkel = LagNøkkel(post);
                if (poster.ContainsKey(nøkkel))
                {
                    poster.Remove(nøkkel);
                }

                poster.Add(nøkkel, post);
            }

            return(poster.Values.ToList());
        }
        public void Les(ExcelWorksheet excelWorksheet, MatchImport.ExcelMatch excelMatch)
        {
            var matchId   = excelMatch.MatchId;
            var deltakere = LesFra(excelWorksheet);

            using (var context = _dataContextFactory.Create())
            {
                //var match = (from m in context.Matcher.Include(x => x.DeltakendeLag.Select(y => y.Lag).Select(z => z.Deltakere))
                //             where m.MatchId == matchId
                //             select m).FirstOrDefault();

                AddOrUpdate(deltakere, context);

                context.SaveChanges();
            }
        }
示例#5
0
        public void Les(ExcelWorksheet excelWorksheet, MatchImport.ExcelMatch excelMatch)
        {
            var matchId = excelMatch.MatchId;

            var import = LesFra(excelWorksheet, excelMatch);

            using (var context = _dataContextFactory.Create())
            {
                var match = (from m in context.Matcher.Include(x => x.Poster.Select(y => y.Post))
                             where m.MatchId == matchId
                             select m).FirstOrDefault();

                AddOrUpdate(import, match, context);

                context.SaveChanges();
            }
        }
示例#6
0
        public void LesInn(byte[] excelBytes)
        {
            using (var stream = new MemoryStream(excelBytes))
            {
                stream.Position = 0;
                using (ExcelPackage excelFile = new ExcelPackage(stream))
                {
                    var excel = excelFile.Workbook;

                    var excelMatch = new MatchImport.ExcelMatch();

                    Les(excel, "Match", x => excelMatch = _matchImport.Les(x));
                    Les(excel, "Poster", x => _postImport.Les(x, excelMatch));
                    Les(excel, "Lag", x => _lagImport.Les(x, excelMatch));
                    Les(excel, "Deltakere", x => _deltakerImport.Les(x, excelMatch));
                }
            }
        }
        public void LesInn(byte[] excelBytes)
        {
            using (var stream = new MemoryStream(excelBytes))
            {
                stream.Position = 0;
                using (ExcelPackage excelFile = new ExcelPackage(stream))
                {
                    var excel = excelFile.Workbook;

                    var excelMatch = new MatchImport.ExcelMatch();

                    Les(excel, "Match", x => excelMatch = _matchImport.Les(x));
                    Les(excel, "Poster", x => _postImport.Les(x, excelMatch));
                    Les(excel, "Lag", x => _lagImport.Les(x, excelMatch));
                    Les(excel, "Deltakere", x => _deltakerImport.Les(x, excelMatch));
                }
            }
        }
示例#8
0
 protected static MatchImport.ExcelMatch GetMatch()
 {
     var match = new MatchImport.ExcelMatch
     {
         MatchId = Guid.NewGuid(),
         Navn = "Testing",
         StartTid = DateTime.Today.AddDays(-1),
         SluttTid = DateTime.Today.AddDays(1),
         GeoboxNWLatitude = 51,
         GeoboxNWLongitude = 11,
         GeoboxSELatitude = 52,
         GeoboxSELongitude = 12,
         DefaultPoengFordeling = "100,90,80",
         PrLagFelle = 1,
         PrLagBombe = 2
     };
     return match;
 }
示例#9
0
        public void Les(ExcelWorksheet excelWorksheet, MatchImport.ExcelMatch excelMatch)
        {
            var matchId  = excelMatch.MatchId;
            var lagListe = LesFra(excelWorksheet);

            using (var context = _dataContextFactory.Create())
            {
                var match = (from m in context.Matcher.Include(x => x.DeltakendeLag.Select(y => y.Lag))
                             where m.MatchId == matchId
                             select m).FirstOrDefault();

                var våpen = context.Våpen.ToList();

                foreach (var lag in lagListe)
                {
                    AddOrUpdate(lag, match, context, excelMatch, våpen);
                }

                context.SaveChanges();
            }
        }
示例#10
0
        private void SkrivMatch(MatchImport.ExcelMatch match)
        {
            var sheet = _excel.Workbook.Worksheets["Match"];

            // Headers
            for (var i = 0; i < ExcelSheet.Match.Kolonner.Length; i++)
            {
                sheet.SetValue(1, i + 1, ExcelSheet.Match.Kolonner[i]);
            }

            sheet.Set(2, ExcelSheet.Match.MatchId, match.MatchId.ToString());
            sheet.Set(2, ExcelSheet.Match.Navn, match.Navn);
            sheet.Set(2, ExcelSheet.Match.Starttid, match.StartTid.ToString());
            sheet.Set(2, ExcelSheet.Match.Sluttid, match.SluttTid.ToString());
            sheet.Set(2, ExcelSheet.Match.DefaultPostPoengfordeling, match.DefaultPoengFordeling);
            sheet.Set(2, ExcelSheet.Match.GeoBox_NW_latitude, match.GeoboxNWLatitude.ToString());
            sheet.Set(2, ExcelSheet.Match.GeoBox_NW_longitude, match.GeoboxNWLongitude.ToString());
            sheet.Set(2, ExcelSheet.Match.GeoBox_SE_latitude, match.GeoboxSELatitude.ToString());
            sheet.Set(2, ExcelSheet.Match.GeoBox_SE_longitude, match.GeoboxSELongitude.ToString());
            sheet.Set(2, ExcelSheet.Match.Pr_lag_FELLE, match.PrLagFelle.ToString());
            sheet.Set(2, ExcelSheet.Match.Pr_lag_BOMBE, match.PrLagBombe.ToString());
        }