Ejemplo n.º 1
0
        public async Task <IHttpActionResult> Create(RestaurantModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var entity = await _repository.Create(model);

            return(Json(entity));
        }
Ejemplo n.º 2
0
        public ActionResult Create(RestaurantCreateVM model)
        {
            Restaurant restaurant = new Restaurant
            {
                Name       = model.Name,
                CategoryID = model.CategoryID,
                CityID     = model.CityID
            };

            _restaurantRepository.Create(restaurant);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
 public void Create(RestaurantEntity restaurant)
 {
     _restaurant.Create(restaurant);
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            // get all cities
            CategoryRepository categoryRepository = new CategoryRepository();
            CityRepository     cityRepository     = new CityRepository();
            List <City>        cities             = cityRepository.GetAll();

            System.Console.WriteLine("The cities are: ");
            foreach (City item in cities)
            {
                System.Console.WriteLine(item.Name);
            }

            System.Console.WriteLine();

            // search city by ID
            City city = cityRepository.GetByID(1);

            System.Console.Write("The city with id=1 is: ");
            if (city != null)
            {
                System.Console.WriteLine(city.Name);
            }
            else
            {
                System.Console.WriteLine("not found");
            }

            System.Console.WriteLine();

            // get all restaurants
            RestaurantRepository restaurantRepository = new RestaurantRepository();
            List <Restaurant>    restaurants          = restaurantRepository.GetAll();

            System.Console.WriteLine("The restaurants are: ");
            foreach (Restaurant item in restaurants)
            {
                string line = string.Format($"{item.Name} - {item.CityName} - {item.CategoryName}");
                System.Console.WriteLine(line);
            }

            System.Console.WriteLine();

            // get all restaurants from the city with id = 1
            string cityName = cityRepository.GetByID(1).Name;

            restaurants = restaurantRepository.GetByCityID(1);
            System.Console.WriteLine($"The restaurants from {cityName} are: ");
            foreach (Restaurant item in restaurants)
            {
                string line = string.Format("{0} - {1} - {2}", item.Name, item.CityName, item.CategoryName);
                System.Console.WriteLine(line);
            }

            System.Console.WriteLine();

            // insert new restaurant
            Restaurant newRestaurant = new Restaurant();

            newRestaurant.Name       = "new restaurant";
            newRestaurant.CategoryID = 1;
            newRestaurant.CityID     = 2;
            restaurantRepository.Create(newRestaurant);

            System.Console.WriteLine();

            restaurantRepository.DeleteByID(newRestaurant.ID);

            System.Console.WriteLine($"The category with ID = 1 is : {categoryRepository.GetByID(1).Name}");

            System.Console.Read();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            // get all cities
            CityRepository cityRepository = new CityRepository();
            List <City>    cities         = cityRepository.GetAll();

            System.Console.WriteLine("The cities are: ");
            foreach (City item in cities)
            {
                System.Console.WriteLine(item.Name);
            }

            System.Console.WriteLine();

            // search city by ID
            City city = cityRepository.GetByID(1);

            System.Console.Write("The city with id=1 is: ");
            if (city != null)
            {
                System.Console.WriteLine(city.Name);
            }
            else
            {
                System.Console.WriteLine("not found");
            }

            System.Console.WriteLine();

            // get all restaurants
            RestaurantRepository restaurantRepository = new RestaurantRepository();
            List <Restaurant>    restaurants          = restaurantRepository.GetAll();

            System.Console.WriteLine("The restaurants are: ");
            foreach (Restaurant item in restaurants)
            {
                string line = string.Format("{0} - {1} - {2} - {3} - {4}", item.Name, item.CityName, item.CategoryName, item.Description, item.DateCreated.ToShortDateString());
                System.Console.WriteLine(line);
            }

            System.Console.WriteLine();

            // get all restaurants from Veliko Tarnovo
            restaurants = restaurantRepository.GetByCityID(1);
            System.Console.WriteLine("The restaurants from Valiko Tarnovo are: ");
            foreach (Restaurant item in restaurants)
            {
                string line = string.Format("{0} - {1} - {2} - {3} - {4}", item.Name, item.CityName, item.CategoryName, item.Description, item.DateCreated.ToShortDateString());
                System.Console.WriteLine(line);
            }

            System.Console.WriteLine();

            // insert new restaurant
            Restaurant newRestaurant = new Restaurant();

            newRestaurant.Name        = "new restaurant";
            newRestaurant.Description = "description";
            newRestaurant.CategoryID  = 1;
            newRestaurant.CityID      = 2;
            newRestaurant.ImageName   = "";
            restaurantRepository.Create(newRestaurant);
            System.Console.WriteLine("added new restaurant. The iD is: " + newRestaurant.ID);

            System.Console.WriteLine();

            //restaurantRepository.DeleteByID(newRestaurant.ID);
            //System.Console.WriteLine("deleting restaurant with ID = " + newRestaurant.ID);

            System.Console.Read();
        }