Beispiel #1
0
        // GET api/restaurants
        public HttpResponseMessage GetAll()
        {
            try
            {
                using (var db = new EventeamContext())
                {
                    var restaurants = db.Restaurants.ToList();
                    var content     = new List <RestaurantViewModel>();

                    foreach (var restaurant in restaurants)
                    {
                        var photos    = _imagesService.GetPlatformPhotos(restaurant.FolderName, restaurant.Name);
                        var mainPhoto = _imagesService.FilterPlatformMainPhoto(photos);

                        content.Add(new RestaurantViewModel
                        {
                            RestaurantId       = restaurant.RestaurantID,
                            Name               = restaurant.Name,
                            Type               = restaurant.RestaurantType.Name,
                            ClassificationName = restaurant.Classification.Name,
                            KitchenName        = restaurant.Kitchen.Name,
                            Banquet            = restaurant.Banquet,
                            Buffet             = restaurant.Buffet,
                            TotalSquare        = restaurant.TotalSquare,
                            Seating            = restaurant.Seating,
                            MainPhoto          = mainPhoto,
                            PlatformPhotos     = photos
                        });
                    }

                    return(Request.CreateResponse(HttpStatusCode.OK, content, JsonMediaTypeFormatter.DefaultMediaType));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);

                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message,
                                              JsonMediaTypeFormatter.DefaultMediaType));
            }
        }
        // GET api/platforms
        public HttpResponseMessage GetAll()
        {
            try
            {
                using (var db = new EventeamContext())
                {
                    var platforms = db.Platforms.ToList();
                    var content   = new List <PlatformInfoViewModel>();

                    foreach (var platform in platforms)
                    {
                        var photos    = _imagesService.GetPlatformPhotos(platform.FolderName, platform.Name);
                        var mainPhoto = _imagesService.FilterPlatformMainPhoto(photos);

                        content.Add(new PlatformInfoViewModel
                        {
                            PlatformId = platform.PlatformID,
                            Name       = platform.Name,
                            CityName   = platform.City.Name,
                            Address    = platform.Address,
                            MainPhoto  = mainPhoto
                        });
                    }

                    return(Request.CreateResponse(HttpStatusCode.OK, content.ToList(),
                                                  JsonMediaTypeFormatter.DefaultMediaType));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);

                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message,
                                              JsonMediaTypeFormatter.DefaultMediaType));
            }
        }
        public ActionResult Platform(int id)
        {
            using (var db = new EventeamContext())
            {
                var platform = db.Platforms.FirstOrDefault(p => p.PlatformID == id);

                if (platform != null)
                {
                    var photos         = _imagesService.GetPlatformPhotos(platform.FolderName, platform.Name);
                    var mainPhoto      = _imagesService.FilterPlatformMainPhoto(photos);
                    var platformPhotos = _imagesService.FilterPlatformPhotos(photos);

                    var content = new PlatformViewModel
                    {
                        PlatformId              = platform.PlatformID,
                        Name                    = platform.Name,
                        CityName                = platform.City.Name,
                        LevelName               = platform.Level.Name,
                        LocationName            = platform.Location.Name,
                        Geography               = platform.Geography,
                        Address                 = platform.Address,
                        Subway                  = platform.Subway,
                        DistanceRailwayStation  = platform.DistanceRailwayStation,
                        DistanceAirportBorispil = platform.DistanceAirportBorispil,
                        DistanceAirportZhulyany = platform.DistanceAirportZhulyany,
                        Site                    = platform.Site,
                        HallsCount              = platform.HallsCount,
                        HallCapacity            = platform.HallCapacity,
                        RestaurantsCount        = platform.RestaurantsCount,
                        BanquetCapacity         = platform.BanquetCapacity,
                        BuffetCapacity          = platform.BuffetCapacity,
                        MainPhoto               = mainPhoto,
                        PlatformPhotos          = platformPhotos,
                    };

                    var hotel = db.Hotels.FirstOrDefault(h => h.PlatformID == id);
                    if (hotel != null)
                    {
                        content.Hotel = new HotelViewModel
                        {
                            HotelId        = hotel.HotelID,
                            CategoryName   = hotel.HotelCategory.Name,
                            Name           = hotel.Name,
                            Site           = hotel.Site,
                            RoomCount      = hotel.RoomCount,
                            Capacity       = hotel.Capacity,
                            Entertainment  = hotel.Entertainment,
                            Rehabilitation = hotel.Rehabilitation,
                            Parking        = hotel.Parking,
                            Internet       = hotel.Internet,
                            Other          = hotel.Other
                        };

                        if (hotel.Rooms.Any())
                        {
                            content.Hotel.Rooms = new List <RoomViewModel>();

                            foreach (var r in hotel.Rooms)
                            {
                                var c = new RoomViewModel
                                {
                                    RoomId           = r.RoomID,
                                    Name             = r.Name,
                                    RoomCategoryName = r.RoomCategory.Name,
                                    RoomTypeName     = r.RoomType.Name,
                                    Quantity         = r.Quantity
                                };

                                content.Hotel.Rooms.Add(c);
                            }
                        }
                    }

                    var restaurants = db.Restaurants.Where(p => p.PlatformID == id);
                    if (restaurants.Any())
                    {
                        content.Restaurants = new List <RestaurantViewModel>();

                        foreach (var r in restaurants)
                        {
                            var c = new RestaurantViewModel
                            {
                                RestaurantId       = r.RestaurantID,
                                Name               = r.Name,
                                Type               = r.RestaurantType.Name,
                                ClassificationName = r.Classification.Name,
                                KitchenName        = r.Kitchen.Name,
                                Banquet            = r.Banquet,
                                Buffet             = r.Buffet,
                                TotalSquare        = r.TotalSquare,
                                Seating            = r.Seating
                            };

                            content.Restaurants.Add(c);
                        }
                    }

                    var halls = db.Halls.Where(p => p.PlatformID == id);
                    if (halls.Any())
                    {
                        content.Halls = new List <HallViewModel>();

                        foreach (var h in halls)
                        {
                            var c = new HallViewModel
                            {
                                HallId      = h.HallID,
                                Name        = h.Name,
                                TotalSquare = h.TotalSquare,
                                Theater     = h.Theater,
                                Class       = h.Class,
                                PPlanting   = h.PPlanting,
                                MeetingRoom = h.MeetingRoom,
                                Banquet     = h.Banquet,
                                Buffet      = h.Buffet,
                                Equipment   = h.Equipment
                            };

                            content.Halls.Add(c);
                        }
                    }

                    return(View(content));
                }

                return(HttpNotFound());
            }
        }