コード例 #1
0
        public IEnumerable<Restaurants> GetAllRestaurant()
        {
            using (var model = new RestoBookEntities())
            {
                var result = from restaurant in model.Restaurants
                             from cuisine in restaurant.TypeCuisine
                             join addr in model.Adresse on restaurant.Id_Restaurant equals addr.RestaurantsId
                             join ville in model.Ville on addr.VilleId equals ville.Id_Ville
                             select new
                             {
                                 Id = restaurant.Id_Restaurant,
                                 Nom = restaurant.lb_nom.Trim(),
                                 Active = restaurant.isActive,
                                 Rue = addr.lb_rue.Trim(),
                                 CP = addr.lb_codepostal.Trim(),
                                 Ville = ville.lb_ville.Trim(),
                                 Cuisine = cuisine.lb_cuisne.Trim()
                             };

                var gpResult = from gpRestaurant in result.AsEnumerable()
                               group gpRestaurant by gpRestaurant.Nom into gp
                               select new Restaurants()
                               {
                                   Id = gp.Select(s=>s.Id).FirstOrDefault(),
                                   Nom = gp.Select(s => s.Nom).FirstOrDefault(),
                                   Active = gp.Select(s => s.Active).FirstOrDefault(),
                                   Rue = gp.Select(s => s.Rue).FirstOrDefault(),
                                   CP = gp.Select(s => s.CP).FirstOrDefault(),
                                   Ville = gp.Select(s => s.Ville).FirstOrDefault(),
                                   Cuisine = String.Join(",", gp.Select(s => s.Cuisine))
                               };

                return gpResult.ToList();
            }
        }
コード例 #2
0
 public static void Update(InfoRestaurant lstInfoRestaurant,byte[] img,string name)
 {
     using (var model = new RestoBookEntities())
     {
         var image = new Picture();
         var restaurants = model.Restaurants.Find(lstInfoRestaurant.Id);
         var addresse = model.Adresse.Find(restaurants.Id_Restaurant);
         addresse.lb_codepostal = lstInfoRestaurant.Cp;
         addresse.lb_rue = lstInfoRestaurant.Rue;
         restaurants.lb_nom = lstInfoRestaurant.Nom;
         restaurants.isActive = lstInfoRestaurant.Active;
         image.lb_Name = name;
         image.lb_Picure = img;
         restaurants.Picture.Add(image);
         restaurants.Adresse.Add(addresse);
         model.Entry(restaurants).State = System.Data.Entity.EntityState.Modified;
         model.SaveChanges();
     }
 }