Beispiel #1
0
        private static void CreateFakeData(AlbumManager albumManager)
        {
            if (albumManager.Query().Any() == false)
            {
                for (int i = 0; i < 5; i++)
                {
                    albumManager.Create(new Album
                    {
                        Name    = NameData.GetCompanyName(),
                        Price   = (decimal)NumberData.GetDouble() * NumberData.GetNumber(100, 4000),
                        IsSales = BooleanData.GetBoolean(),
                        Year    = NumberData.GetNumber(1980, DateTime.Now.Year)
                    });
                }

                Console.WriteLine("Sample data created. Please enter for continue..");
                Console.WriteLine();
                Console.ReadKey();
            }
        }
Beispiel #2
0
        protected override void Seed(ZeroDbContext context)
        {
            var admin = new ApplicationUser()
            {
                Id        = 1,
                FirstName = "Ekin",
                LastName  = "Memiş",
                Email     = "*****@*****.**",
                Password  = "******",
                Active    = true,
                Deleted   = false,
            };

            context.ApplicationUser.AddOrUpdate(admin);

            Random rnd = new Random();

            for (int i = 0; i < 100; i++)
            {
                Customer customer = new Customer
                {
                    Id                    = i,
                    Active                = true,
                    DateOfBirth           = DateTimeData.GetDatetime(),
                    Deleted               = false,
                    Email                 = NetworkData.GetEmail(),
                    FirstName             = NameData.GetFirstName(),
                    LastName              = NameData.GetSurname(),
                    PalceOfBirth          = FakeData.PlaceData.GetAddress(),
                    PhoneNumber           = PhoneNumberData.GetPhoneNumber(),
                    TurkishIdentityNumber = NumberData.GetDouble().ToString(),
                };
                context.Customer.AddOrUpdate(customer);

                Employee employee = new Employee
                {
                    Id                    = i,
                    Active                = true,
                    DateOfBirth           = DateTimeData.GetDatetime(),
                    Deleted               = false,
                    Email                 = NetworkData.GetEmail(),
                    FirstName             = NameData.GetFirstName(),
                    LastName              = NameData.GetSurname(),
                    PalceOfBirth          = FakeData.PlaceData.GetAddress(),
                    PhoneNumber           = PhoneNumberData.GetPhoneNumber(),
                    TurkishIdentityNumber = NumberData.GetDouble().ToString(),
                    Sallary               = NumberData.GetNumber(),
                    Title                 = NameData.GetCompanyName()
                };
                context.Employee.AddOrUpdate(employee);

                AppointmentType appointmentType = new AppointmentType
                {
                    Id = i,
                    DefaultSeanceQuantity = NumberData.GetNumber(1, 10),
                    Name    = TextData.GetAlphabetical(5),
                    Deleted = false,
                };
                context.AppointmentType.AddOrUpdate(appointmentType);

                Appointment appointment = new Appointment
                {
                    Id                  = i,
                    Deleted             = false,
                    StartDate           = DateTimeData.GetDatetime(),
                    EndDate             = DateTimeData.GetDatetime(),
                    Price               = NumberData.GetNumber(),
                    PriceIncludedTax    = NumberData.GetNumber(),
                    Name                = TextData.GetAlphabetical(5),
                    AppointmentStatusId = 0,
                    AppointmentTypeId   = rnd.Next(100),
                };
                context.Appointment.AddOrUpdate(appointment);
            }
        }
        private static AllTypesModel GenerateSimpleModel(Random random, int min, int max)
        {
            var itemToAdd = new AllTypesModel
            {
                Long         = NumberData.GetNumber(min, max),
                LongNullable = RandomiseNullable(NumberData.GetNumber(min, max)),
#if USE_UTYPES
                ULong         = (ulong)NumberData.GetNumber(0, max),
                ULongNullable = RandomiseNullable((ulong)NumberData.GetNumber(0, max)),
#else
                ULong         = (long)NumberData.GetNumber(0, max),
                ULongNullable = (long?)RandomiseNullable(NumberData.GetNumber(0, max)),
#endif
                Integer         = random.Next(min, max),
                IntegerNullable = RandomiseNullable(FakeData.NumberData.GetNumber(min, max)),

#if USE_UTYPES
                UInt         = (uint)NumberData.GetNumber(0, max),
                UIntNullable = (uint?)RandomiseNullable(NumberData.GetNumber(0, max)),
#else
                UInt         = (int)NumberData.GetNumber(0, max),
                UIntNullable = (int?)RandomiseNullable(NumberData.GetNumber(0, max)),
#endif
                DoubleProperty = NumberData.GetDouble(),
                DoubleNullable = RandomiseNullable(NumberData.GetDouble()),

                Float         = (float)NumberData.GetDouble(),
                FloatNullable = RandomiseNullable((float)NumberData.GetDouble()),

                DecimalProperty = (decimal)NumberData.GetDouble(),
                DecimalNullable = (decimal?)RandomiseNullable(NumberData.GetDouble()),

                Short         = (short)NumberData.GetNumber(min, max),
                ShortNullable = (short?)(NumberData.GetNumber(min, max)),
#if USE_UTYPES
                UShort         = (ushort)NumberData.GetNumber(0, max),
                UShortNullable = (ushort?)RandomiseNullable(NumberData.GetNumber(0, max)),
#else
                UShort         = (short)NumberData.GetNumber(0, max),
                UShortNullable = (short?)RandomiseNullable(NumberData.GetNumber(0, max)),
#endif
                ByteProperty = RandomByte(),
                ByteNullable = RandomiseNullable(RandomByte()),
#if USE_STYPES
                SByteProperty = RandomSByte(),
                SByteNullable = RandomiseNullable(RandomSByte()),
#else
                SByteProperty = RandomByte(),
                SByteNullable = RandomiseNullable(RandomByte()),
#endif

#if USE_CHARTYPE
                CharProperty = FakeData.TextData.GetAlphabetical(1)[0],
                CharNullable = RandomiseNullable(FakeData.TextData.GetAlphabetical(1)[0]),
#else
                CharProperty = FakeData.TextData.GetAlphabetical(1)[0].ToString(),
                CharNullable = RandomiseNullable(TextData.GetAlphaNumeric(1), 0.3),
#endif

                BooleanProperty = BooleanData.GetBoolean(),
                BooleanNullable = RandomiseNullable(BooleanData.GetBoolean()),

                StringProperty = RandomiseNullable(TextData.GetAlphaNumeric(NumberData.GetNumber(0, 20)), 0.3),

                DateTimeProperty = RandomDate(max),
                DateTimeNullable = RandomiseNullable(RandomDate(max)),
#if USE_DTOFFSET
                DateTimeOffsetProperty = RandomDateTimeOffset(max),
                DateTimeOffsetNullable = RandomiseNullable(RandomDateTimeOffset(max))
#else
                DateTimeOffsetProperty = RandomDate(max),
                DateTimeOffsetNullable = RandomiseNullable(RandomDate(max)),
#endif
            };

            return(itemToAdd);
        }
        public IActionResult ExcelExport()
        {
            // https://steemit.com/utopian-io/@haig/how-to-create-excel-spreadsheets-using-npoi

            var workbook = new HSSFWorkbook();
            var sheet    = workbook.CreateSheet("Sheet 1");

            IFont fontBold = workbook.CreateFont();

            fontBold.Boldweight = (short)FontBoldWeight.Bold;

            var headerCellStyle = workbook.CreateCellStyle();

            headerCellStyle.SetFont(fontBold);

            var   header = sheet.CreateRow(0);
            ICell col1   = header.CreateCell(0); col1.CellStyle = headerCellStyle; col1.SetCellValue("Fullname");
            ICell col2   = header.CreateCell(1); col2.CellStyle = headerCellStyle; col2.SetCellValue("Country");
            ICell col3   = header.CreateCell(2); col3.CellStyle = headerCellStyle; col3.SetCellValue("Email");
            ICell col4   = header.CreateCell(3); col4.CellStyle = headerCellStyle; col4.SetCellValue("Numbers");
            ICell col5   = header.CreateCell(4); col5.CellStyle = headerCellStyle; col5.SetCellValue("Datetime");
            ICell col6   = header.CreateCell(5); col6.CellStyle = headerCellStyle; col6.SetCellValue("Sentence");

            var currencyCellStyle = workbook.CreateCellStyle();

            currencyCellStyle.Alignment  = HorizontalAlignment.Right;
            currencyCellStyle.DataFormat = workbook.CreateDataFormat().GetFormat("₺#.##0,00");;

            int length = 50;

            for (int i = 0; i < length; i++)
            {
                var row = sheet.CreateRow(i + 1);
                row.CreateCell(0).SetCellValue(NameData.GetFullName());
                row.CreateCell(1).SetCellValue(PlaceData.GetCountry());
                row.CreateCell(2).SetCellValue(NetworkData.GetEmail());

                ICell numberCell = row.CreateCell(3);
                numberCell.CellStyle = currencyCellStyle;
                numberCell.SetCellValue(NumberData.GetDouble() * 1000);

                row.CreateCell(4).SetCellValue(DateTimeData.GetDatetime().ToShortDateString());
                row.CreateCell(5).SetCellValue(TextData.GetSentence());
            }

            var   totalRow  = sheet.CreateRow(length + 1);
            ICell totalCell = totalRow.CreateCell(3);

            ICellStyle totalCellStyle = workbook.CreateCellStyle();

            totalCellStyle.CloneStyleFrom(sheet.GetRow(length).GetCell(3).CellStyle);

            totalCell.CellStyle = totalCellStyle;
            totalCell.CellStyle.SetFont(fontBold);
            totalCell.SetCellType(CellType.Formula);
            totalCell.CellFormula = $"SUM(D2:D{length + 1})";   // Headercell den sonrası.

            string root     = _environment.WebRootPath;
            string folder   = Path.Combine(root, "Excels");
            string filename = "f_" + Guid.NewGuid().ToString() + ".xls";
            string file     = Path.Combine(folder, filename);

            if (Directory.Exists(folder) == false)
            {
                Directory.CreateDirectory(folder);
            }

            using (var fileStream = new FileStream(file, FileMode.Create))
            {
                workbook.Write(fileStream);
            }

            return(File("~/Excels/" + filename, "application/vnd.ms-excel"));
        }