示例#1
0
        public async Task <IHttpActionResult> PutRestaurant(int id, Containers.Models.EasyInputs.EasyRestaurant restaurant)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            DB.Restaurant restaurantDB = restaurant.ToDBRestaurant();
            restaurantDB.Id = id;

            db.Entry(restaurantDB).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RestaurantExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#2
0
        public async Task <IHttpActionResult> PostRestaurant(Containers.Models.EasyInputs.EasyRestaurant restaurant)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            db.Restaurant.Add(restaurant.ToDBRestaurant());
            await db.SaveChangesAsync();

            DB.Restaurant restaurantDb = db.Restaurant
                                         .Where(a => a.Adress == restaurant.Adress)
                                         .Where(i => i.Id_City == restaurant.Id_City)
                                         .Where(i => i.Img.Length == restaurant.Img.Length)
                                         .Where(n => n.Name == restaurant.Name)
                                         .Where(p => p.Popularity == restaurant.Popularity)
                                         .Where(t => t.TypeOfFood == restaurant.TypeOfFood)
                                         .FirstOrDefault();

            return(CreatedAtRoute("DefaultApi", new { Name = restaurantDb.Id }, restaurantDb));
        }