Beispiel #1
0
        public void Configuration(IAppBuilder app)
        {
            Database.SetInitializer(
                new MigrateDatabaseToLatestVersion <DCDbContext, Configuration>());

            ConfigureAuth(app);

            DCDbContext.Create().Database.Initialize(true);
        }
 public DeviceController()
 {
     _userId  = System.Web.HttpContext.Current.User.Identity.GetUserId();
     _context = new DCDbContext();
 }
Beispiel #3
0
 public DataStoreRepository()
 {
     _context      = new DCDbContext();
     _modelFactory = new ModelFactory();
 }
 public DeviceRepository(string userId)
 {
     _context      = new DCDbContext();
     _userId       = userId;
     _modelFactory = new ModelFactory();
 }
        protected void SaveBtn_Click(object sender, EventArgs e)
        {
            var context = new DCDbContext();

            if (context.Warehouses.Any(w => w.Name == WarehouseNameTb.Text))
            {
                String URL = "Page2.aspx?Exception=" + 409;
                Response.Redirect(URL);
                return;
            }
            var wh = new Warehouse();

            wh.Name            = WarehouseNameTb.Text;
            wh.MaxCapacity     = int.Parse(WhCapTb.Text);
            wh.CurrentCapacity = 0;

            context.Warehouses.Add(wh);
            context.SaveChanges();

            var currentWh = context.Warehouses.FirstOrDefault(x => x.Name == WarehouseNameTb.Text);

            int    count   = 1;
            string shName  = "";
            string rowName = "";
            string boxName = "";

            for (int i = 1; i <= wh.MaxCapacity; i++)
            {
                var shelf = new Shelf();
                shName                = string.Concat("wh", currentWh.Id, "sh", count);
                shelf.Number          = shName;
                shelf.CurrentCapacity = 0;
                shelf.MaxCapacity     = int.Parse(ShCapTb.Text);
                shelf.WarehouseId     = currentWh.Id;

                context.Shelves.Add(shelf);
                context.SaveChanges();


                var currentShelf = context.Shelves.FirstOrDefault(s => s.Number == shName);

                for (int j = 1; j <= currentShelf.MaxCapacity; j++)
                {
                    var row = new Row();
                    rowName             = string.Concat(currentShelf.Number, "r", j);
                    row.Number          = rowName;
                    row.CurrentCapacity = 0;
                    row.MaxCapacity     = int.Parse(RowCapTb.Text);
                    row.ShelfId         = currentShelf.Id;

                    context.Rows.Add(row);
                    context.SaveChanges();

                    var currentRow = context.Rows.FirstOrDefault(r => r.Number == rowName);

                    for (int k = 1; k <= currentRow.MaxCapacity; k++)
                    {
                        var box = new Box();
                        boxName             = string.Concat(currentRow.Number, "b", k);
                        box.Number          = boxName;
                        box.CurrentCapacity = 0;
                        box.MaxCapacity     = int.Parse(BoxCapTb.Text);
                        box.RowId           = currentRow.Id;
                        context.Boxes.Add(box);
                        context.SaveChanges();
                    }
                }
                count++;
            }
            Response.Redirect("/Default.aspx");
        }