示例#1
0
        public RedirectToRouteResult Like([Bind(Include = "Id,ReviewId,UserId")] ReviewLike reviewLike, [Bind(Include = "FacilityId")] int facilityId)
        {
            reviewLike.UserId = db.Users.Single(user => user.UserName == reviewLike.UserId).Id;
            db.ReviewLikes.Add(reviewLike);
            db.SaveChanges();

            return(RedirectToAction("Details", "Facilities", new { id = facilityId }));
        }
示例#2
0
        public static void WriteToDB(IList <CitiesImportModel> myList, string typeOfCity)
        {
            var countryCapitalQuery = (from s in myList
                                       where s.Capital.Equals(typeOfCity)
                                       orderby s.Country ascending
                                       select s);

            using (var dbContext = new CityContext())
            {
                dbContext.Database.Connection.Close();
            }
            var countryGroups = from city in countryCapitalQuery
                                group city by new
            {
                city.Country,
                city.ISO2,
                city.ISO3
            }
            into countryGroup
            orderby countryGroup.Key.Country
            select countryGroup;

            using (var db = new CityContext())
            {
                foreach (var country in countryGroups)
                {
                    var countryName   = country.Key.Country;
                    var ISO2          = country.Key.ISO2;
                    var ISO3          = country.Key.ISO3;
                    var CountryEntity = new CountryEntity
                    {
                        Name = countryName,
                        ISO2 = ISO2,
                        ISO3 = ISO3
                    };
                    db.Countries.Add(CountryEntity);
                    db.SaveChanges();
                    int id = CountryEntity.CountryID;
                    foreach (var city in country)
                    {
                        var CityEntity = new CityEntity
                        {
                            City_name  = city.City_name,
                            Admin_name = city.Admin_name,
                            City_ascii = city.City_ascii,
                            Lat        = city.Lat,
                            Lng        = city.Lng,
                            Capital    = city.Capital,
                            CountryId  = id,
                            Population = city.Population
                        };
                        db.Cities.Add(CityEntity);
                        db.SaveChanges();
                    }
                }
            }
        }
示例#3
0
        public ActionResult Create([Bind(Include = "Id,FacilityId,UserId,Rating,Text,Release")] Review review)
        {
            if (ModelState.IsValid)
            {
                db.Reviews.Add(review);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.FacilityId = new SelectList(db.Facilities, "Id", "Name", review.FacilityId);
            return(View(review));
        }
示例#4
0
        public ActionResult Create([Bind(Include = "Id,ParentId,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ParentId = new SelectList(db.Categories, "Id", "Name", category.ParentId);
            return(View(category));
        }
示例#5
0
        public ActionResult Create([Bind(Include = "Id,CategoryId,Name,Address,Website,Phone")] Facility facility)
        {
            if (ModelState.IsValid)
            {
                db.Facilities.Add(facility);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", facility.CategoryId);
            return(View(facility));
        }
示例#6
0
        private static void SeedDB()
        {
            var ctx = new CityContext();

            ctx.Cities.Add(new City {
                Name = "Kiev", Latitude = 1, Longitude = 1
            });
            ctx.Cities.Add(new City {
                Name = "Lviv", Latitude = 1, Longitude = 1
            });

            ctx.Doctors.Add(new Doctor {
                CityId = 1, Name = "name1", Specialization = "spec1"
            });
            ctx.Doctors.Add(new Doctor {
                CityId = 1, Name = "name2", Specialization = "spec2"
            });
            ctx.Doctors.Add(new Doctor {
                CityId = 1, Name = "name3", Specialization = "spec3"
            });
            ctx.Doctors.Add(new Doctor {
                CityId = 1, Name = "name4", Specialization = "spec4"
            });

            ctx.Engineers.Add(new Engineer {
                CityId = 1, Name = "name4", FavoriteVideogame = "game1"
            });

            ctx.SaveChanges();
        }
示例#7
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "")
            {
                MessageBox.Show("Поля пустые, внесите данные в оба поля.");
            }
            else
            {
                Person person = new Person();
                using (var context = new CityContext())
                {
                    var cities = context.Cities.ToList();

                    for (int i = 0; i < cities.Count; i++)
                    {
                        if (cities[i].NameSeed == comboBox1.Text)
                        {
                            person = new Person {
                                FullName = textBox1.Text, Phone = textBox2.Text, City = cities[i]
                            }
                        }
                    }
                    ;

                    context.People.AddRange(new List <Person> {
                        person
                    });
                    context.SaveChanges();

                    textBox1.Text = "";
                    textBox2.Text = "";
                    MessageBox.Show("Контакт внесен!");
                }
            }
        }
示例#8
0
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                int  index     = dataGridView1.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = int.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                City city = context.Cities.Find(id);
                try
                {
                    context.Cities.Remove(city);
                    context.SaveChanges();
                    dataGridView1.Refresh();
                    MessageBox.Show("Объект удален", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message, exception.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#9
0
        public static void Initialize(CityContext context)
        {
            if (!context.Cities.Any())
            {
                context.Cities.AddRange(
                    new City
                {
                    name = "Paris"
                },
                    new City
                {
                    name = "Tokyo"
                },
                    new City
                {
                    name = "Soul"
                }
                    );
                context.SaveChanges();

                context.Pilots.AddRange(
                    new Pilot
                {
                    name    = "John",
                    company = "USA Airlines",
                    exp     = 3
                },
                    new Pilot
                {
                    name    = "Leon",
                    company = "Aeroflot",
                    exp     = 2
                },
                    new Pilot
                {
                    name    = "Hiro",
                    company = "Korean Air",
                    exp     = 8
                }
                    );
                context.SaveChanges();
            }
        }
示例#10
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBoxName.Text.Length > 0 &&
                    textBoxCode.Text.Length > 0)
                {
                    if (Text == "Добавление")
                    {
                        city = new City
                        {
                            Name      = textBoxName.Text,
                            PhoneCode = textBoxCode.Text
                        };
                        if (DuplicationCheck(city.Name, city.PhoneCode))
                        {
                            throw new Exception("Город с такими данными уже существует");
                        }
                        context.Cities.Add(city);
                    }
                    else if (Text == "Изменение")
                    {
                        city = context.Cities
                               .Where(c => c.Id == Form1.city.Id).FirstOrDefault();

                        city.Name      = textBoxName.Text;
                        city.PhoneCode = textBoxCode.Text;
                        if (DuplicationCheck(city))
                        {
                            throw new Exception("Город с такими данными уже существует");
                        }
                    }

                    context.SaveChanges();
                    MessageBox.Show("Операция прошла успешно", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    throw new Exception("Один или обе полей пустые, отказано в действии");
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, exception.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Hide();
                Form1 form = new Form1();
                form.ShowDialog();
                Close();
            }
        }
示例#11
0
 public ActionResult AddCity(string country, string cityname)
 {
     using (var db = new CityContext())
     {
         db.Cities.Add(new City()
         {
             Name = cityname, CountryId = db.Countries.FirstOrDefault(w => w.Name == country).Id
         });
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
示例#12
0
        public ActionResult Create([Bind(Include = "Id,ReviewId,Image")] ReviewImage reviewImage)
        {
            HttpPostedFileBase file = Request.Files["Image"];

            if (file != null && file.ContentLength > 0)
            {
                reviewImage.Image = file.FileName;
            }
            ModelState.Clear();
            TryValidateModel(reviewImage);
            if (ModelState.IsValid)
            {
                file.SaveAs(HttpContext.Server.MapPath("~/Images/" + reviewImage.Image));

                db.ReviewImages.Add(reviewImage);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ReviewId = new SelectList(db.Reviews, "Id", "Text", reviewImage.ReviewId);
            return(View(reviewImage));
        }
示例#13
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (var context = new CityContext())
            {
                Person p2 = context.People.FirstOrDefault(p => p.Phone == textBox3.Text || p.FullName == textBox1.Text);

                p2.FullName = textBox2.Text;
                p2.Phone    = textBox4.Text;
                context.SaveChanges();
            }
            textBox1.Text = textBox2.Text = textBox3.Text = textBox4.Text = "";
            Close();
        }
示例#14
0
 static void Main()
 {
     using (var context = new CityContext())
     {
         context.Cities.Add(new City
         {
             Name      = "Алматы",
             PhoneCode = "+7(727)"
         });
         context.SaveChanges();
     }
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new Form1());
 }
示例#15
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (textBox1.Text == "")
     {
         MessageBox.Show("Внесите данные поле ФИО.");
     }
     else
     {
         using (var context = new CityContext())
         {
             Person person = context.People.FirstOrDefault(p => p.FullName == textBox1.Text);
             if (person != null)
             {
                 context.People.Remove(person);
                 context.SaveChanges();
             }
         }
         textBox1.Text = "";
         textBox2.Text = "";
         MessageBox.Show("Контакт удален!");
     }
 }
示例#16
0
        private void button2_Click(object sender, EventArgs e)
        {
            using (var context = new CityContext())
            {
                Person p1 = context.People.FirstOrDefault(p => p.FullName == textBox1.Text);

                if (textBox1.Text != "" && textBox3.Text == "")
                {
                    if (p1 == null)
                    {
                        MessageBox.Show("Контакт не найден");
                    }
                    else
                    {
                        textBox3.Text = p1.Phone;
                    }
                }

                Person p2 = context.People.FirstOrDefault(p => p.Phone == textBox3.Text);

                if (textBox1.Text == "" && textBox3.Text != "")
                {
                    if (p2 == null)
                    {
                        MessageBox.Show("Контакт не найден");
                    }
                    else
                    {
                        textBox1.Text = p2.FullName;
                    }
                }

                p2.FullName = textBox2.Text;
                p2.Phone    = textBox4.Text;
                context.SaveChanges();
            }
        }
示例#17
0
        public void CreateCities()
        {
            List <City> cities = new List <City>();

            cities.Add(new City()
            {
                Name = "Florianópolis", Population = 500973, Borders = new string[] { "São José" }
            });
            cities.Add(new City()
            {
                Name = "São José", Population = 242927, Borders = new string[] { "Florianópolis", "Antônio Carlos" }
            });
            cities.Add(new City()
            {
                Name = "Antônio Carlos", Population = 8411, Borders = new string[] { "São José", "São Pedro de Alcântara" }
            });
            cities.Add(new City()
            {
                Name = "São Pedro de Alcântara", Population = 5139, Borders = new string[] { "Antônio Carlos" }
            });

            _context.Cities.AddRange(cities);
            _context.SaveChanges();
        }
示例#18
0
 public ActionResult Create(People people)
 {
     city.peoples.Add(people);
     city.SaveChanges();
     return(RedirectToAction("Index"));
 }
示例#19
0
        static void Main(string[] args)
        {
            int Stored  = 0;
            int Errored = 0;
            int Skipped = 0;
            // Get CSV with cities
            TextReader reader = new StreamReader("CityList.csv");

            List <String> Urls = new List <string>();

            // Skip the first header line
            reader.ReadLine();


            while (reader.Peek() >= 0)
            {
                var line = reader.ReadLine().Split(",");
                try
                {
                    var url = line[2];
                    Urls.Add(url);
                }
                catch (Exception err)
                {
                }
            }



            foreach (var url in Urls)
            {
                Console.Title = $"{((double)(Stored + Errored + Skipped) / (double)Urls.Count)*100}% - Record {Stored+Errored+Skipped} of {Urls.Count}";
                try
                {
                    using (var db = new CityContext())
                    {
                        var cityCount = db.Cities
                                        .Where(x => x.CityUrl == url)
                                        .Count();

                        if (cityCount == 0)
                        {
                            var newCity = ProcessUrl(url);

                            if (newCity != null)
                            {
                                db.Cities.Add(newCity);
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.WriteLine($"Added '{newCity.CityName}' into the db");
                                Console.ResetColor();
                                db.SaveChanges();
                                Stored++;
                            }
                            else
                            {
                                Errored++;
                            }
                        }
                        else
                        {
                            var cityName = db.Cities.Where(x => x.CityUrl == url).Select(x => x.CityName).FirstOrDefault();
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine($"Skipped '{cityName}'. Already in DB. ");
                            Console.ResetColor();
                            Skipped++;
                        }
                    }
                    Task.Delay(TimeSpan.FromMilliseconds(250));
                }
                catch (Exception err)
                {
                    Console.WriteLine($"Error: '{err.Message}'");
                    Errored++;
                    Console.ResetColor();
                }
            }
            Console.WriteLine($"Stored: {Stored} | Skipped: {Skipped} | Error: {Errored}");
            Console.ReadLine();
        }
示例#20
0
 public bool Save()
 {
     return(_cityContext.SaveChanges() >= 0);
 }
示例#21
0
        public void AllCSVTest()
        {
            var path = "c://csvfiles//worldcities.csv";
            var doubleTypeConversion         = new DoubleConversion();
            IList <CitiesImportModel> myList = ReadCsv.ReadCsvFile <CitiesImportModel, CityMap>(path, doubleTypeConversion);
            var countryCapitalQuery          = (from s in myList
                                                where s.Capital.Equals("primary")
                                                orderby s.Country ascending
                                                select s);

            /*
             * foreach (CityModelImport city in countryCapitalQuery)
             * {
             *  Debug.Write(city.Country + ": " + city.City_name + Environment.NewLine);
             *
             * var queryName = nameof(countryCapitalQuery);
             * var writePath = "c://csvfiles//" + queryName + ".csv";
             * using (var writer = new StreamWriter(writePath))
             * using (var csv = new CsvWriter(writer))
             * {
             *  csv.WriteRecords(countryCapitalQuery);
             * }
             * Assert.IsTrue(File.Exists(writePath));
             * }
             * var QSCount = (from city in countryCapitalQuery
             *             select city).Count();
             * //Debug.Write(QSCount);
             * Assert.AreEqual(15493, myList.Count());
             */
            using (var dbContext = new CityContext())
            {
                dbContext.Database.Connection.Close();
            }
            var countryGroups = from city in countryCapitalQuery
                                group city by new
            {
                city.Country,
                city.ISO2,
                city.ISO3
            }
            into countryGroup
            orderby countryGroup.Key.Country
            select countryGroup;

            using (var db = new CityContext())
            {
                foreach (var country in countryGroups)
                {
                    var countryName   = country.Key.Country;
                    var ISO2          = country.Key.ISO2;
                    var ISO3          = country.Key.ISO3;
                    var CountryEntity = new CountryEntity
                    {
                        Name = countryName,
                        ISO2 = ISO2,
                        ISO3 = ISO3
                    };
                    db.Countries.Add(CountryEntity);
                    db.SaveChanges();
                    int id = CountryEntity.CountryID;
                    Debug.Write(country);
                    foreach (var city in country)
                    {
                        var CityEntity = new CityEntity
                        {
                            City_name  = city.City_name,
                            Admin_name = city.Admin_name,
                            City_ascii = city.City_ascii,
                            Lat        = city.Lat,
                            Lng        = city.Lng,
                            Capital    = city.Capital,
                            CountryId  = id,
                            Population = city.Population
                        };
                        db.Cities.Add(CityEntity);
                        db.SaveChanges();
                    }
                }
            }
            // countryQuery = records.Where(city => city.Country.Equals("United States"));

            /*
             * foreach (CityModel city in countryQuery)
             * {
             *  var name = city.City_name.ToString();
             * }
             */
        }
示例#22
0
 public ActionResult Edit(City city)
 {
     db.Entry(city).State = EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
示例#23
0
 public ActionResult Edit_pilot(Pilot pilot)
 {
     db.Entry(pilot).State = EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index_pilot"));
 }
示例#24
0
 public void Create(City city)
 {
     _context.Cities.Add(city);
     _context.SaveChanges();
 }