Пример #1
0
        public IActionResult Post([FromBody] Restaurant r)
        {
            DataLayerService.DataLayerService ds = DataLayer.GetService();

            List <Restaurant> restaurantExists = ds.RestaurantRepository.GetByNC(r.Name, r.City);
            Restaurant        restaurant;

            if (restaurantExists.Count == 0)
            {
                restaurant = ds.RestaurantRepository.Create(r);
            }

            restaurant = ds.RestaurantRepository.Get(r.Name, r.City);


            if (restaurant == null)
            {
                return(NotFound());
            }
            var json = JsonConvert.SerializeObject(restaurant, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Ok(json));
        }
Пример #2
0
        public IActionResult LogIn([FromBody] LogIn logIn)
        {
            DataLayerService.DataLayerService ds = DataLayer.GetService();

            if (ds.UserRepository.UserExist(logIn))
            {
                return(Ok(true));
            }

            return(NotFound());
        }
Пример #3
0
        public IActionResult Post([FromBody] User u)
        {
            DataLayerService.DataLayerService ds = DataLayer.GetService();

            User user = ds.UserRepository.Create(u);

            if (user == null)
            {
                return(NotFound());
            }

            return(Ok(true));
        }
Пример #4
0
        public IActionResult UsernameExist(string username)
        {
            DataLayerService.DataLayerService ds = DataLayer.GetService();

            bool exist = ds.UserRepository.UsernameExist(username);

            var json = JsonConvert.SerializeObject(exist, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Ok(json));
        }
Пример #5
0
        public static DataLayerService.DataLayerService GetService()
        {
            if (_factory == null)
            {
                lock (objLock)
                {
                    if (_factory == null)
                    {
                        _factory = ObjectFactory.GetDataLayerService();
                    }
                }
            }

            return(_factory);
        }
Пример #6
0
        public object Get(string username)
        {
            DataLayerService.DataLayerService ds = DataLayer.GetService();

            List <User> user = ds.UserRepository.Get(username);

            if (user == null)
            {
                return(null);
            }

            return(user);
            //  var res = new { result = user };
            //  return new ObjectResult(user);
        }
Пример #7
0
        public IActionResult Get()
        {
            DataLayerService.DataLayerService ds = DataLayer.GetService();

            IEnumerable <Restaurant> restaurant = ds.RestaurantRepository.GetAll();

            if (restaurant == null)
            {
                return(NotFound());
            }
            var json = JsonConvert.SerializeObject(restaurant, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Ok(json));
        }
Пример #8
0
        // [Route("edit")]
        public IActionResult Put([FromBody] Restaurant r)
        {
            DataLayerService.DataLayerService ds = DataLayer.GetService();

            Restaurant restaurant = ds.RestaurantRepository.Update(r);

            if (restaurant == null)
            {
                return(NotFound());
            }
            var json = JsonConvert.SerializeObject(restaurant, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Ok(json));
        }
Пример #9
0
        public IActionResult GetByCriteria(string name, string description)
        {
            DataLayerService.DataLayerService ds = DataLayer.GetService();

            IEnumerable <Food> food = ds.FoodRepository.SearchFood(name, description);

            if (food == null)
            {
                return(NotFound());
            }
            var json = JsonConvert.SerializeObject(food, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Ok(json));
        }
Пример #10
0
        public IActionResult GetSimilarlyFood([FromBody] Food f)
        {
            DataLayerService.DataLayerService ds = DataLayer.GetService();

            List <Food> food = ds.FoodRepository.GetSimilarlyFood(f);

            if (food == null)
            {
                return(NotFound());
            }
            var json = JsonConvert.SerializeObject(food, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Ok(json));
        }
        public IActionResult Post([FromBody] Picture p)
        {
            DataLayerService.DataLayerService ds = DataLayer.GetService();

            Picture picture = ds.PictureRepository.Create(p);

            if (picture == null)
            {
                return(NotFound());
            }
            var json = JsonConvert.SerializeObject(picture, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Ok(json));
        }
Пример #12
0
        public IActionResult GetPictures([FromRoute] string foodId)
        {
            DataLayerService.DataLayerService ds = DataLayer.GetService();

            IEnumerable <Picture> pics = ds.FoodRepository.GetPictures(foodId);

            if (pics == null)
            {
                return(NotFound());
            }
            var json = JsonConvert.SerializeObject(pics, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Ok(json));
        }
Пример #13
0
        public IActionResult GetByCity(string city)
        {
            DataLayerService.DataLayerService ds = DataLayer.GetService();

            List <Restaurant> restaurants = ds.RestaurantRepository.GetByCity(city);

            if (restaurants == null)
            {
                return(NotFound());
            }
            var json = JsonConvert.SerializeObject(restaurants, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Ok(json));
        }
Пример #14
0
        public IActionResult GetRecomendedFood(string usernameS, string usernameD)
        {
            DataLayerService.DataLayerService ds = DataLayer.GetService();

            IEnumerable <Food> food = ds.UserRepository.GetRecomendedFood(usernameS, usernameD);

            if (food == null)
            {
                return(NotFound());
            }
            var json = JsonConvert.SerializeObject(food, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Ok(json));
        }
Пример #15
0
        // [Route("edit")]
        public IActionResult Put([FromBody] User u)
        {
            DataLayerService.DataLayerService ds = DataLayer.GetService();

            User user = ds.UserRepository.Update(u);

            if (user == null)
            {
                return(NotFound());
            }
            var json = JsonConvert.SerializeObject(user, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Ok(json));
        }
Пример #16
0
        public IActionResult GetMenu(string restaurantName, string restaurantCity)
        {
            DataLayerService.DataLayerService ds = DataLayer.GetService();

            List <Food> menu = ds.RestaurantRepository.GetMenu(restaurantName, restaurantCity);

            if (menu == null)
            {
                return(NotFound());
            }
            var json = JsonConvert.SerializeObject(menu, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Ok(json));
        }
Пример #17
0
        public IActionResult RateFood([FromBody] Rate rated)
        {
            DataLayerService.DataLayerService ds = DataLayer.GetService();
            string id, username;
            float  rate;

            id       = rated.Id;
            username = rated.Username;
            rate     = rated.Rating;

            Food food = ds.FoodRepository.RateFood(id, rate, username);

            if (food == null)
            {
                return(NotFound());
            }
            var json = JsonConvert.SerializeObject(food, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });
            var tip = new { tip = food.AverageRating };

            return(Ok(tip));
        }
Пример #18
0
        public IActionResult AddFood([FromBody] LinkUserFood l)
        {
            DataLayerService.DataLayerService ds = DataLayer.GetService();

            List <Food> foodExist = ds.FoodRepository.GetSame(l.Name, l.Description, l.Type);

            if (foodExist.Count != 0)
            {
                foreach (Food fe in foodExist)
                {
                    if (ds.RestaurantRepository.RelationshipServeExist(fe, l.RestaurantName, l.RestaurantCity))
                    {
                        var json = JsonConvert.SerializeObject(fe, new JsonSerializerSettings()
                        {
                            ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                        });
                        return(Ok(json));
                    }
                }
            }

            string username = l.Username;

            Food food;

            if (foodExist.Count == 0)
            {
                Food f = new Food();
                f.Name          = l.Name;
                f.Type          = l.Type;
                f.Description   = l.Description;
                f.AverageRating = 0;
                f.NumberOfVotes = 0;

                food = ds.FoodRepository.Create(f);
            }
            else
            {
                food = ds.FoodRepository.Get(foodExist[0].Id);
            }

            Picture picture = new Picture();

            picture.PictureURL = l.PictureURL;
            picture.FoodId     = food.Id;

            ds.PictureRepository.StoreImageUrl(picture);

            if (!ds.FoodRepository.RelationshipTastedExist(username, food))
            {
                ds.FoodRepository.LinkFromUserToFood(username, food);
            }

            ds.RestaurantRepository.AddFoodToMenu(food, l.RestaurantName, l.RestaurantCity);
            Restaurant rest = ds.RestaurantRepository.Get(l.RestaurantName, l.RestaurantCity);

            rest.Menu.Add(food);

            if (food == null)
            {
                return(NotFound());
            }
            return(Ok(true));
        }
        public void Delete(string id)
        {
            DataLayerService.DataLayerService ds = DataLayer.GetService();

            ds.PictureRepository.Delete(id);
        }
Пример #20
0
        public void Delete(string id)
        {
            DataLayerService.DataLayerService ds = DataLayer.GetService();

            ds.RestaurantRepository.Delete(id);
        }