public async Task<string> GenerateMySQLReport()
        {

            var list = new List<JObject>();
            using (WeaponSystemContext msSqlServerContext = new WeaponSystemContext())
            {
                await msSqlServerContext
                    .Weapons
                    .Select(w => new
                    {
                        Id = w.Id,
                        Name = w.Name,
                        Manufacturer = w.Manufacturer.Name
                    })
                    .ForEachAsync(w =>
                        list.Add(CreateJObject(w.Id, w.Name, w.Manufacturer))
                    );
            }

            using (WeaponReportsDbContext MySqlServerContext = new WeaponReportsDbContext())
            {
                MySqlActions.AddReports(list, MySqlServerContext);
            }

            return MySQLSuccessMessage;
        }
Example #2
0
        public async Task CreateDb()
        {
           Database.SetInitializer(new MigrateDatabaseToLatestVersion<WeaponSystemContext, Configuration>());

            using (var ctx = new WeaponSystemContext())
            {
                await ctx.Weapons.ToListAsync();
                await ctx.SaveChangesAsync();
            }

          //  return "success";
        }
        public async Task<string> TransferManufacturers()
        {
            var manufacturers = (await this.mongoRepository.GetManufacturers()).ToList();
            using (WeaponSystemContext ctx = new WeaponSystemContext())
            {
                foreach (var man in manufacturers)
                {
                    if (!ctx.Manufacturers.Any(c => c.Name == man.Name))
                    {
                        ctx.Manufacturers.Add(man);
                    }
                }

                ctx.SaveChanges();
            }

            return "Manufacturers" + MessageEnd;
        }
        public async Task<string> TransferCountries()
        {
            var countries = (await this.mongoRepository.GetCountries()).ToList();
            using (WeaponSystemContext ctx = new WeaponSystemContext())
            {
                foreach (var country in countries)
                {
                    if (!ctx.Countries.Any(c => c.Name == country.Name))
                    {
                        ctx.Countries.Add(country);
                    }
                }

                ctx.SaveChanges();
            }

            return "Countries" + MessageEnd;
        }
        public async Task<string> TransferTargetCategories()
        {
            var targetCategories = (await this.mongoRepository.GetTargetCategories()).ToList();
            using (WeaponSystemContext ctx = new WeaponSystemContext())
            {
                foreach (var cat in targetCategories)
                {
                    if (!ctx.TargetCategories.Any(c => c.Name == cat.Name))
                    {
                        ctx.TargetCategories.Add(cat);
                    }
                }

                ctx.SaveChanges();
            }

            return "Target Categories" + MessageEnd;
        }
        public async Task<string> GetXmlData()
        {
            var targets = XmlReader.ReadXmlCollectionFromFile(DataPath);

            var repo = new MongoDbRepository();

            await repo.InsertTargets(targets);

            using (WeaponSystemContext db = new WeaponSystemContext())
            {
                var targetCats = db.TargetCategories.ToList();

                foreach (var targetItem in targets)
                {
                    if (!targetCats.Any(c  => c.Name == targetItem[0]))
                    {
                        var newTargetCat = new Target()
                        {
                            Name = targetItem[0]
                        };
                    }

                    var target = new Target();
                    var targetItemName = targetItem[1];

                    var id = db.TargetCategories.
                        Where(c => c.Name == targetItemName)
                        .FirstOrDefault();
                  
                    if (id != null && !db.Targets.Any(t => t.Name == target.Name))
                    {
                        target.Name = targetItem[0];
                        target.TargetCategoryId = id.Id;

                        db.Targets.Add(target);
                    }
                }

                db.SaveChanges();
            }

            return "Targets from xml dispatched";
        }
Example #7
0
        public async Task<string> GenerateJsonReport()
        {
            using (WeaponSystemContext msSqlServerContext = new WeaponSystemContext())
            {
                await msSqlServerContext
                    .Weapons
                    .Select(w => new
                    {
                        Id = w.Id,
                        Name = w.Name,
                        Manufacturer = w.Manufacturer.Name
                    })
                    .ForEachAsync(w =>
                        WriteJsonObject(w.Id.ToString(), w.Name, w.Manufacturer)
                    );
            }

            return JsonSuccessMessage;
        }
Example #8
0
        public string GenerateXmlReport()
        {
            var msSqlServerContext = new WeaponSystemContext();

            var queryResult = msSqlServerContext
                    .Weapons
                    .Select(w => new
                    {
                        Id = w.Id,
                        Name = w.Name,
                        Manufacturer = w.Manufacturer.Name,
                        Category = w.WeaponCategory.Name
                    });

            string reportLocation = "../../../../Generated Reports/XML/Report.xml";
            var encoding = Encoding.GetEncoding("windows-1251");

            using (var writer = new XmlTextWriter(reportLocation, encoding))
            {
                writer.Formatting = Formatting.Indented;
                writer.IndentChar = '\t';
                writer.Indentation = 1;

                writer.WriteStartDocument();
                writer.WriteStartElement("weapons");

                foreach (var weapon in queryResult)
                {
                    writer.WriteStartElement("weapon");
                    writer.WriteAttributeString("id", weapon.Id.ToString());
                    writer.WriteAttributeString("name", weapon.Name);
                    writer.WriteAttributeString("manufacturer", weapon.Manufacturer);
                    writer.WriteAttributeString("category", weapon.Category);

                    writer.WriteEndElement();
                }

                writer.WriteEndDocument();
            }

            return XmlSuccessMessage;
        }
Example #9
0
        public async Task<string> GeneratePdfReport()
        {
            string reportLocation = "../../../../Generated Reports/PDF/Report.pdf";

            var fs = new FileStream(reportLocation, FileMode.Create);

            var document = new Document(PageSize.A4, 25, 25, 30, 30);

            var writer = PdfWriter.GetInstance(document, fs);
            document.Open();

            var table = new PdfPTable(4)
            {
                TotalWidth = 545f,
                LockedWidth = true
            };

            float[] widths = { 1f, 0.75f, 0.75f, 0.75f };
            table.SetWidths(widths);

            table.SpacingBefore = 20f;
            table.SpacingAfter = 30f;

            var header =
                new PdfPCell(new Phrase("WEAPONS CHEATSHEET", new Font(Font.FontFamily.HELVETICA, FontSize + 20, Font.BOLD)))
                {
                    Colspan = 4,
                    HorizontalAlignment = 1,
                    PaddingBottom = 14f,
                    PaddingTop = 14f
                };

            table.AddCell(header);

            var cellTitle1 =
                new PdfPCell(new Phrase("Thumb", new Font(Font.FontFamily.HELVETICA, FontSize + 5, Font.BOLD)))
                {
                    Padding = 4f
                };

            table.AddCell(cellTitle1);

            var cellTitle2 =
                new PdfPCell(new Phrase("Weapon Name", new Font(Font.FontFamily.HELVETICA, FontSize + 5, Font.BOLD)))
                {
                    PaddingBottom = 10f,
                    PaddingLeft = 10f,
                    PaddingTop = 4f
                };

            table.AddCell(cellTitle2);

            var cellTitle3 =
                new PdfPCell(new Phrase("Manufacturer", new Font(Font.FontFamily.HELVETICA, FontSize + 5, Font.BOLD)))
                {
                    PaddingBottom = 10f,
                    PaddingLeft = 10f,
                    PaddingTop = 4f
                };

            table.AddCell(cellTitle3);

            var cellTitle4 =
                new PdfPCell(new Phrase("Category", new Font(Font.FontFamily.HELVETICA, FontSize + 5, Font.BOLD)))
                {
                    PaddingBottom = 10f,
                    PaddingLeft = 10f,
                    PaddingTop = 4f
                };

            table.AddCell(cellTitle4);

           // var msSqlServerContext = new WeaponSystemContext();

            using (WeaponSystemContext msSqlServerContext = new WeaponSystemContext())
            {
                await msSqlServerContext
                    .Weapons
                    .Select(w => new
                    {
                        Name = w.Name,
                        Manufacturer = w.Manufacturer.Name,
                        Picrire = w.ImageUrl,
                        Category = w.WeaponCategory.Name
                    })
                    .ForEachAsync(w =>
                        FillPdfTable(table, w.Name, w.Category, w.Manufacturer, w.Picrire)
                    );
            }
          

                document.Add(table);

                // Close the document
                document.Close();

                // Close the writer instance
                writer.Close();

                // Close the File Stream
                fs.Close();
            

            return PdfSuccessMessage;
        }