Пример #1
0
        public ActionResult GetBuilding(int? buildingId)
        {
            if (!buildingId.HasValue)
            {
                return new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest);                
            }

            using (var db = new Models.OnLeaveContext())
            {
                var buildingDB = db.UtilityBuildings
                    .Include(b => b.UtilityBuildingPhotoDetails)
                    .Include(b => b.UtilityBuidingFacilityDetails)
                    .Include(b => b.Periods)
                    .Include(b => b.Periods.Select(p => p.RoomAmounts))
                    .Include(b => b.UtilityBuildingLocales)
                    .Include(b => b.Offers)
                    .FirstOrDefault(b => b.UtilityBuildingId == buildingId);
                if (buildingDB == null)
                {
                    return new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound);
                }

                var bg = buildingDB.UtilityBuildingLocales.FirstOrDefault(l => l.LocaleId == (int)LocaleTypes.BG);
                if (bg == null) bg = new UtilityBuildingLocale();
                var en = buildingDB.UtilityBuildingLocales.FirstOrDefault(l => l.LocaleId == (int)LocaleTypes.EN);
                if (en == null) en = new UtilityBuildingLocale();
                
                var model = new UtilityBuildingModel
                {
                    Id = buildingDB.UtilityBuildingId,
                    Name =  bg.Name,
                    NameEN = en.Name,
                    Description = bg.Description,
                    DescriptionEN = en.Description,
                    UtilityBuildingTypeId = buildingDB.UtilityBuildingTypeId,
                    Address = bg.Address,
                    AddressEN = en.Address,
                    ContactPerson = bg.ContactPerson,
                    ContactPersonEN = en.ContactPerson,
                    PhoneNumber = buildingDB.PhoneNumber,
                    CityId = buildingDB.CityId,
                    Rating = buildingDB.Rating ?? 0,
                    SearchRating = User.IsInRole("Root") ? buildingDB.SearchRating : null,
                    Latitude = buildingDB.lat ?? 0M,
                    Longitude = buildingDB.lon ?? 0M,                    
                    Size = buildingDB.Size,
                    PhotoIds = buildingDB.UtilityBuildingPhotoDetails.Select(ph => ph.PhotoId).ToList(),                    
                    Facilities = db.UtilityBuildingFacilityTypes.Select(ft =>
                        new FacilityTypeModel
                        {
                            FacilityTypeId = ft.UtilityBuildingFacilityTypeId,
                            FacilityTypeName = ft.Name
                        }).ToArray(),
                    Periods = buildingDB.Periods.Select(p => 
                    {
                        StaticDataProvider.RoomTypes.ToList().ForEach(rType =>
                        {
                            var roomAmount = p.RoomAmounts.FirstOrDefault(rAmountDB => rAmountDB.RoomTypeId == rType.RoomTypeId);
                            if (roomAmount == null)
                            {
                                // add default value for room type
                                p.RoomAmounts.Add(new RoomAmount
                                {
                                    PeriodId = p.PeriodId,
                                    RoomTypeId = rType.RoomTypeId,
                                    Amount = 0M,                                    
                                });
                            }
                        });

                        return p; 
                    }).ToList()
                };

                // get offers
                model.Offers = buildingDB.Offers.Select(o => new OnLeave.Models.BusinessEntities.Offer
                {
                    OfferId = o.OfferId,
                    Description = o.Description,
                    StartDate = o.StartDate,
                    EndDate = o.EndDate,
                    Discount = o.Discount
                }).ToList();

                // 5 periods for each hotel
                while (model.Periods.Count < 5)
                {
                    model.Periods.Add(new Period
                    {
                        UtilityBuildingId = model.Id,
                        FromDate = DateTime.Now.Date,
                        ToDate = DateTime.Now.Date,
                        RoomAmounts = StaticDataProvider.RoomTypes.Select(rType => new RoomAmount
                        {
                            RoomTypeId = rType.RoomTypeId,                            
                            Amount = 0M,
                        }).ToList()
                    });
                }

                foreach (var f in model.Facilities)
                {
                    f.Selected = buildingDB.UtilityBuidingFacilityDetails.Any(ft => ft.UtilityBuildingFacilityTypeId == f.FacilityTypeId);
                }

                ViewBag.Cities = StaticDataProvider.Cities.Select(c => new SelectListItem { Text = c.Name, Value = c.CityId.ToString() });
                ViewBag.RoomTypes = StaticDataProvider.RoomTypes;
                ViewBag.UtilityBuildingTypes = StaticDataProvider.UtilityBuildingTypes.Select(t => new SelectListItem
                {
                    Text = t.Description,
                    Value = t.UtilityBuildingTypeId.ToString()
                });

                return PartialView("EditBuilding", model);
            }            
        }
Пример #2
0
        public ActionResult GetUtilityBuildingExternal(int? buildingId, bool? edit)
        {
            UtilityBuildingExternalModel utilityBuilding = null;

            if (buildingId.HasValue)
            {
                using (var db = new OnLeaveContext())
                {
                    var buildingDB = db.UtilityBuildings
                        .Include(b => b.UtilityBuildingLocales)
                        .FirstOrDefault(b => b.UtilityBuildingId == buildingId);

                    if (buildingDB == null) new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound);
                    utilityBuilding = new UtilityBuildingExternalModel
                    {
                        Id = buildingDB.UtilityBuildingId,
                        PhoneNumber = buildingDB.PhoneNumber,
                        CityId = buildingDB.CityId,
                        UrlAddress = buildingDB.ExternalUrl,
                        PhotoIds = buildingDB.UtilityBuildingPhotoDetails.Select(ph => ph.PhotoId).ToList(),
                    };

                    var bg = buildingDB.UtilityBuildingLocales.FirstOrDefault(l => l.LocaleId == (int)LocaleTypes.BG);
                    if (bg == null) bg = new UtilityBuildingLocale();
                    var en = buildingDB.UtilityBuildingLocales.FirstOrDefault(l => l.LocaleId == (int)LocaleTypes.EN);
                    if (en == null) en = new UtilityBuildingLocale();
                    utilityBuilding.Name = bg.Name;
                    utilityBuilding.NameEN = en.Name;
                }
            }
            else
            {
                utilityBuilding = new UtilityBuildingExternalModel
                {
                    UtilityBuildingTypeId = (int)UtilityBuildingTypes.Hotel,
                    PhotoIds = new List<int>()
                };
            }

            ViewBag.Cities = StaticDataProvider.Cities.Select(c => new SelectListItem { Text = c.Name, Value = c.CityId.ToString() });
            ViewBag.UtilityBuildingTypes = StaticDataProvider.UtilityBuildingTypes.Select(t => new SelectListItem
            {
                Text = t.Description,
                Value = t.UtilityBuildingTypeId.ToString()
            });
            ViewBag.edit = edit ?? false;
            
            return PartialView("UtilityBuildingExternal", utilityBuilding);
        }