Пример #1
0
        public ActionResult Detali(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Charging_station charging_station = db.Charging_station.Find(id);

            if (charging_station == null)
            {
                return(HttpNotFound());
            }
            return(View(charging_station));
        }
Пример #2
0
        protected override void Seed(SkopjeCS.Models.ApplicationDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.
            System.IO.StreamReader file = new System.IO.StreamReader("C:\\Users\\Blagica\\Desktop\\finalen_csv.csv");
            string line = file.ReadLine();

            while ((line = file.ReadLine()) != null)
            {
                string[] parts = line.Split(',');

                Charging_station scs = new Charging_station();
                int id = Int32.Parse(parts[0].ToString());
                scs.id           = id;
                scs.longitude    = Double.Parse(parts[1]);
                scs.latitude     = Double.Parse(parts[2]);
                scs.amenity      = parts[3];
                scs.fee          = parts[4];
                scs.openingHours = parts[5];
                scs.operatorCS   = parts[6];
                scs.socket       = parts[7];
                scs.tip          = parts[8];
                scs.address      = parts[9];
                scs.municipality = parts[10];

                var existsInDb = context.Charging_station
                                 .Where(c => c.id == scs.id)
                                 .SingleOrDefault();
                if (existsInDb != null)
                {
                    context.Charging_station.AddOrUpdate(scs);
                }
                else
                {
                    context.Charging_station.Add(scs);
                }
            }
        }
    public static void Initialize(Demo.Data.ApplicationDbContext context)
    {
        context.Database.EnsureCreated();

        if (context.Charging_station.Any())
        {
            return;
        }

        System.IO.StreamReader file = new System.IO.StreamReader("C:\\Users\\Blagica\\Desktop\\finalen_csv.csv");
        string line = "";

        file.ReadLine();
        while ((line = file.ReadLine()) != null)
        {
            if (line == null || line.StartsWith(" "))
            {
                break;
            }
            string[]         parts = line.Split(',');
            Charging_station scs   = new Charging_station();
            // int id = Int32.Parse(parts[0].ToString());
            // scs.id = id;
            scs.longitude    = Double.Parse(parts[1]);
            scs.latitude     = Double.Parse(parts[2]);
            scs.amenity      = parts[3];
            scs.fee          = parts[4];
            scs.openingHours = parts[5];
            scs.operatorCS   = parts[6];
            scs.socket       = parts[7];
            scs.tip          = parts[8];
            scs.address      = parts[9];
            scs.municipality = parts[10];

            context.Charging_station.Add(scs);
        }
        //_ = context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT dbo.atm ON;");
        context.SaveChanges();
    }