public static List <PatientAtFoodPlace> CreatePatientAtFoodPlaces(int userinput)
        {
            WpfWebClient.ServiceReferenceEHEC.ServiceClient    client     = new WpfWebClient.ServiceReferenceEHEC.ServiceClient();
            List <WpfWebClient.ServiceReferenceEHEC.FoodPlace> foodPlaces = new List <ServiceReferenceEHEC.FoodPlace>(client.GetFoodPlaces());
            List <WpfWebClient.ServiceReferenceEHEC.Person>    patients   = new List <ServiceReferenceEHEC.Person>(client.GetPersons());



            int i = 0;

            do
            {
                PatientAtFoodPlace patfgen = new PatientAtFoodPlace();

                int       randnumFP = random.Next(0, foodPlaces.Count());
                FoodPlace foodpl    = foodPlaces[randnumFP];

                int    randnumP = random.Next(0, patients.Count());
                Person patient  = patients[randnumP];

                patfgen.FoodPlace   = foodpl;
                patfgen.Patient     = patient;
                patfgen.VistingDate = new DateTime(2005, 12, 20);

                PatientsAtFoodPlaces.Add(patfgen);

                i++;
            } while (i < userinput);

            client.Close();

            return(PatientsAtFoodPlaces);
        }
        public bool CreateFoodPlace(FoodPlace foodplace)
        {
            try
            {
                using (Context ctx = new Context())
                {
                    var city    = ctx.Cities.FirstOrDefault(c => c.CityID == foodplace.City.CityID);
                    var country = ctx.Countries.FirstOrDefault(c => c.CountryID == foodplace.City.Country.CountryID);

                    ctx.Cities.Attach(city);
                    ctx.Countries.Attach(country);

                    foodplace.City = city;

                    ctx.FoodPlaces.Add(foodplace);
                    ctx.SaveChanges();
                }
                return(true);
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine(e);
                return(false);
            }
        }
        public IActionResult Index()
        {
            List <string> foodPlaceList = new List <string>();

            foreach (FoodPlace fp in FoodPlace.GetFoodPlaces())
            {
                foodPlaceList.Add(string.Format($"#{fp.Rank}: Name: {fp.Name} Favorite: {fp.Fave} Address: {fp.Address} Link: {fp.WebLink}"));
            }
            return(View(foodPlaceList));
        }
示例#4
0
        private void btnAddFoodPlace_Click(object sender, RoutedEventArgs e)
        {
            WpfWebClient.ServiceReferenceEHEC.ServiceClient client = new WpfWebClient.ServiceReferenceEHEC.ServiceClient();

            // create new foodplace from user input

            FoodPlace fp = new FoodPlace();

            // check if any box is empty

            if (ComboBoxFPCities.SelectedIndex == -1)
            {
                System.Windows.MessageBox.Show("Please select a city", "INFO", MessageBoxButton.OK, MessageBoxImage.Information);
            }

            if (txtFoodPlaceName.Text == null)
            {
                System.Windows.MessageBox.Show("Please enter a name for the food place", "INFO", MessageBoxButton.OK, MessageBoxImage.Information);
            }

            if (txtFoodPlaceHouseNumber.Text == null)
            {
                System.Windows.MessageBox.Show("Please enter a house number", "INFO", MessageBoxButton.OK, MessageBoxImage.Information);
            }

            if (txtFoodPlaceStreetName.Text == null)
            {
                System.Windows.MessageBox.Show("Please enter a street name", "INFO", MessageBoxButton.OK, MessageBoxImage.Information);
            }

            else
            {
                fp.Streetname   = txtFoodPlaceStreetName.Text;
                fp.Streetnumber = txtFoodPlaceHouseNumber.Text;
                fp.Name         = txtFoodPlaceName.Text;
                fp.Description  = txtFoodPlaceDescription.Text;
                fp.City         = (City)ComboBoxFPCities.SelectedValue;

                client.WriteFoodPlace(fp);

                // Show success msgbox
                System.Windows.MessageBox.Show("Success", "INFO", MessageBoxButton.OK, MessageBoxImage.Information);
            }

            client.Close();
        }
 public bool DeleteFoodPlace(FoodPlace foodplace)
 {
     try
     {
         using (Context ctx = new Context())
         {
             ctx.FoodPlaces.Attach(foodplace);
             ctx.FoodPlaces.Remove(foodplace);
             ctx.SaveChanges();
         }
         return(true);
     }
     catch (Exception e)
     {
         System.Diagnostics.Trace.WriteLine(e);
         return(false);
     }
 }
 public bool UpdateFoodPlace(FoodPlace foodplace)
 {
     try
     {
         using (Context ctx = new Context())
         {
             ctx.FoodPlaces.Attach(foodplace);
             ctx.Entry(foodplace).State = System.Data.Entity.EntityState.Modified;
             ctx.SaveChanges();
         }
         return(true);
     }
     catch (Exception e)
     {
         System.Diagnostics.Trace.WriteLine(e);
         return(false);
     }
 }
        public static List <FoodPlace> CreateFoodPlaces()
        {
            WpfWebClient.ServiceReferenceEHEC.ServiceClient client = new WpfWebClient.ServiceReferenceEHEC.ServiceClient();
            List <WpfWebClient.ServiceReferenceEHEC.City>   cities = new List <ServiceReferenceEHEC.City>(client.GetCities());

            int FirstPartLength  = FoodPlaceNameFirstPart.Count();
            int SecondPartLength = FoodPlaceNameSecondPart.Count();
            int Counter          = FirstPartLength * SecondPartLength;

            int i = 1;

            while (i < 20)
            {
                int    FirstPart      = random.Next(1, FirstPartLength);
                int    SecondPart     = random.Next(1, SecondPartLength);
                int    Description    = random.Next(FoodPlaceDescription.Count);
                string FoodPlaceDescr = FoodPlaceDescription[Description];
                int    StreetName     = random.Next(FoodPlaceStreetName.Count);
                string FoodPlacesn    = FoodPlaceStreetName[StreetName];

                string    FoodPlaceName = FoodPlaceNameFirstPart[FirstPart] + FoodPlaceNameSecondPart[SecondPart];
                string    streetname    = FoodPlacesn;
                string    fpdescr       = FoodPlaceDescr;
                int       StreetNumber  = random.Next(1, 100);
                int       CityID        = random.Next(1, cities.Count());
                City      city          = cities[CityID];
                FoodPlace NewFoodPlace  = new FoodPlace();

                NewFoodPlace.Name         = FoodPlaceName;
                NewFoodPlace.Streetname   = streetname;
                NewFoodPlace.Streetnumber = StreetNumber.ToString();
                NewFoodPlace.Description  = fpdescr;
                NewFoodPlace.City         = city;



                Foodplaces.Add(NewFoodPlace);
                i++;
            }

            client.Close();

            return(Foodplaces);
        }
        public void WriteFoodPlace(FoodPlace foodplace)
        {
            FoodPlaceDB dataaccess = new FoodPlaceDB();

            dataaccess.CreateFoodPlace(foodplace);
        }