Beispiel #1
0
 public MemberService(
     ApplicationUserManager userManager,
     DanceClassDbContext dbContext,
     IMapper mapper,
     IConfigurationProvider mappingConfig) : base(userManager, dbContext, mapper, mappingConfig)
 {
 }
Beispiel #2
0
 public ClassService(
     DanceClassDbContext dbContext,
     IMapper mapper,
     IConfigurationProvider mappingConfig
     ) : base(dbContext, mapper)
 {
     _mappingConfig = mappingConfig;
 }
Beispiel #3
0
 public UserService(
     ApplicationUserManager userManager,
     DanceClassDbContext dbContext,
     IMapper mapper,
     IConfigurationProvider mappingConfig) : base(dbContext, mapper)
 {
     _userManager   = userManager;
     _mappingConfig = mappingConfig;
 }
Beispiel #4
0
 public BaseService(DanceClassDbContext dbContext, IMapper mapper)
 {
     _dbContext = dbContext;
     _mapper    = mapper;
 }
 public WeeklyScheduleReportService(DanceClassDbContext dbContext, IMapper mapper, IConfigurationProvider mappingConfig) : base(dbContext, mapper)
 {
     _mappingConfig = mappingConfig;
 }
 public ApplicationUserStore(DanceClassDbContext context) : base(context)
 {
 }
Beispiel #7
0
        static void Main(string[] args)
        {
            _Application app   = new Application();
            Workbook     book  = null;
            Worksheet    sheet = null;
            Range        range = null;

            try
            {
                app.Visible        = false;
                app.ScreenUpdating = false;
                app.DisplayAlerts  = false;

                string filePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"MasterSheet.xlsx");

                book = app.Workbooks.Open(filePath, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);

                sheet = (Worksheet)book.Worksheets[1];

                // get a range to work with
                range = sheet.get_Range("A2", Missing.Value);
                // get the end of values to the right (will stop at the first empty cell)
                range = range.get_End(XlDirection.xlToRight);
                // get the end of values toward the bottom, looking in the last column (will stop at first empty cell)
                range = range.get_End(XlDirection.xlDown);

                // get the address of the bottom, right cell
                string downAddress = range.get_Address(
                    false, false, XlReferenceStyle.xlA1,
                    Type.Missing, Type.Missing);

                // Get the range, then values from a1
                range            = sheet.get_Range("A2", downAddress);
                object[,] values = (object[, ])range.Value2;

                // Value2 is a two dimenial array dime one = row, dime two = column.
                Console.WriteLine("Col Count: " + values.GetLength(1).ToString());
                Console.WriteLine("Row Count: " + values.GetLength(0).ToString());

                using (DanceClassDbContext db = new DanceClassDbContext())
                {
                    var users       = new List <ApplicationUser>();
                    var memberships = new List <Membership>();
                    var packages    = new List <Package>();

                    var defaultPackages = db.DefaultPackages.ToList();

                    for (int i = 1; i <= values.GetLength(0); i++)
                    {
                        string fullName = values[i, 1].ToString().Trim();
                        if (!values[i, 2].ToString().Equals("0"))
                        {
                            fullName = values[i, 2].ToString().Trim() + " " + fullName;
                        }

                        DateTime?dob         = !values[i, 3].Equals("undefined") ? (DateTime?)DateTime.FromOADate((double)values[i, 3]) : null;
                        string   phoneNumber = "0" + values[i, 4].ToString().Trim();

                        int      numberOfSessions = int.Parse(values[i, 5].ToString());
                        int      months           = int.Parse(values[i, 6].ToString());
                        DateTime createdDate      = DateTime.FromOADate((double)values[i, 7]);
                        Console.WriteLine(createdDate);
                        DateTime expiryDate        = DateTime.FromOADate((double)values[i, 8]);
                        int      remainingSessions = int.Parse(values[i, 10].ToString());
                        double   price             = (double)values[i, 11];

                        ApplicationUser user = new ApplicationUser
                        {
                            FullName    = fullName,
                            UserName    = GenerateUserName(users, fullName),
                            PhoneNumber = phoneNumber,
                            Birthdate   = dob,
                            CreatedBy   = "Imported",
                            UpdatedBy   = "Imported",
                            CreatedDate = createdDate,
                            UpdatedDate = createdDate
                        };

                        Membership membership = new Membership
                        {
                            User = user,
                            RemainingSessions = remainingSessions,
                            ExpiryDate        = expiryDate,
                            CreatedBy         = "Imported",
                            UpdatedBy         = "Imported",
                            CreatedDate       = createdDate,
                            UpdatedDate       = createdDate
                        };

                        DefaultPackage defaultPackage = defaultPackages.FirstOrDefault(p => p.NumberOfSessions == numberOfSessions);
                        Package        package        = new Package
                        {
                            NumberOfSessions  = numberOfSessions,
                            RemainingSessions = remainingSessions,
                            Months            = months,
                            Price             = price,
                            DefaultPackageId  = defaultPackage != null ? (int?)defaultPackage.Id : null,
                            User        = user,
                            CreatedBy   = "Imported",
                            UpdatedBy   = "Imported",
                            CreatedDate = createdDate,
                            UpdatedDate = createdDate,
                            ExpiryDate  = expiryDate
                        };

                        users.Add(user);
                        memberships.Add(membership);
                        packages.Add(package);
                    }

                    ApplicationUserManager userManager = new ApplicationUserManager(new ApplicationUserStore(db));
                    using (DbContextTransaction transaction = db.Database.BeginTransaction())
                    {
                        try
                        {
                            Console.WriteLine("--------------------------------------");
                            Console.WriteLine("- ADDING USERS -------------------------");
                            Console.WriteLine("--------------------------------------");
                            foreach (var u in users)
                            {
                                Console.WriteLine("Adding user: "******"Mistake1234").GetAwaiter().GetResult();
                                if (result.Succeeded)
                                {
                                    result = userManager.AddToRoleAsync(u.Id, "Member").GetAwaiter().GetResult();
                                }

                                if (!result.Succeeded)
                                {
                                    throw new Exception(string.Join(". ", result.Errors));
                                }
                            }

                            Console.WriteLine("--------------------------------------");
                            Console.WriteLine("- ADDING MEMBERSHIPS -------------------------");
                            Console.WriteLine("--------------------------------------");
                            db.Memberships.AddRange(memberships);

                            Console.WriteLine("--------------------------------------");
                            Console.WriteLine("- ADDING PACKAGES -------------------------");
                            Console.WriteLine("--------------------------------------");
                            db.Packages.AddRange(packages);

                            Console.WriteLine("--------------------------------------");
                            Console.WriteLine("- SAVING CHANGES -------------------------");
                            Console.WriteLine("--------------------------------------");
                            db.SaveChanges();
                            transaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            transaction.Rollback();
                            Console.WriteLine(ex);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                range = null;
                sheet = null;
                if (book != null)
                {
                    try
                    {
                        book.Close(false, Missing.Value, Missing.Value);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                book = null;
                if (app != null)
                {
                    try
                    {
                        app.Quit();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

                app = null;
                Console.ReadKey();
            }
        }
 public RevenueReportService(DanceClassDbContext dbContext, IMapper mapper) : base(dbContext, mapper)
 {
 }
 public MembershipService(DanceClassDbContext dbContext, IMapper mapper) : base(dbContext, mapper)
 {
 }