示例#1
0
        public ActionResult City(CityModel city)
        {
            if (!ModelState.IsValid)
            {
                return PartialView(city);
            }
            
            using (var db = new OnLeaveContext())
            {
                if (city.CityId == 0)
                {
                    if (db.Cities.Any(c => c.Name.ToLower() == city.Name.ToLower()))
                    {
                        ModelState.AddModelError(city.GetPropertyName(() => city.Name), "Дублиран град");
                        return PartialView(city);
                    }

                    // add city
                    db.Cities.Add(new City
                        {
                            Name = city.Name,
                            KeyWords = city.Name,
                            lat = city.latitude,
                            lon = city.longitude
                        });
                }
                else if (city.CityId > 0)
                {
                    var c = db.Cities.FirstOrDefault(cityDB => cityDB.CityId == city.CityId);
                    if (c == null)
                    {
                        ModelState.AddModelError(string.Empty, "Град липсва");                        
                    }

                    if (db.Cities.Any(cityDB => cityDB.CityId != city.CityId && cityDB.Name.ToLower() == city.Name.ToLower()))
                    {
                        ModelState.AddModelError(city.GetPropertyName(() => city.Name), "Дублиран град");
                    }

                    if (!ModelState.IsValid)
                    {
                        return PartialView(city);
                    }

                    c.Name = city.Name;
                    c.KeyWords = city.Name;
                    c.lon = city.longitude;
                    c.lat = city.latitude;
                }

                db.SaveChanges();
                StaticDataProvider.updateCity = true;
            }

            return RedirectToAction("Cities");
        }
示例#2
0
        public ActionResult GetCity(int cityId)
        {
            if (cityId == -1)
            {
                ModelState.Clear();
                return PartialView("City", new CityModel());
            }
            
            using (var db = new OnLeaveContext())
            {
                var city = db.Cities.FirstOrDefault(c => c.CityId == cityId);
                if (city == null)
                {
                    ModelState.AddModelError(string.Empty, "Крад липсва");
                    return RedirectToAction("Cities");                    
                }

                return PartialView("City",
                    new CityModel
                    {
                        Name = city.Name,
                        longitude = city.lon,
                        latitude = city.lat
                    });
            }
        }
示例#3
0
        public ActionResult DeleteCity(int cityId)
        {
            if (cityId < 0)
            {
                return new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest);
            }

            using (var db = new OnLeaveContext())
            {
                var city = db.Cities.FirstOrDefault(c => c.CityId == cityId);
                if (city == null) return new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound);

                if (db.UtilityBuildings.Any(b => b.CityId == city.CityId))
                {
                    return new HttpStatusCodeResult(System.Net.HttpStatusCode.Forbidden, "Съществуващ хотел от града");
                }

                db.Cities.Remove(city);
                db.SaveChanges();
                StaticDataProvider.updateCity = true;
            }

            return new HttpStatusCodeResult(System.Net.HttpStatusCode.OK);
        }
示例#4
0
 public ActionResult Cities()
 {
     using (var db = new OnLeaveContext())
     {
         var cities = db.Cities.ToArray();
         return PartialView(cities);
     }
 }
示例#5
0
        public ActionResult SaveBuildingLocation(int buildingId, decimal latitude, decimal longitude)
        {
            using (var db = new OnLeaveContext())
            {
                var buildingDB = db.UtilityBuildings.FirstOrDefault(b => b.UtilityBuildingId == buildingId);
                if (buildingDB == null)
                {
                    return new HttpStatusCodeResult(System.Net.HttpStatusCode.Forbidden);
                }

                if (buildingDB.UserId != User.Identity.GetUserId())
                {
                    return new HttpStatusCodeResult(System.Net.HttpStatusCode.Forbidden);
                }

                buildingDB.lat = latitude;
                buildingDB.lon = longitude;

                db.SaveChanges();
            }
            
            return new HttpStatusCodeResult(System.Net.HttpStatusCode.OK);
        }
示例#6
0
        public ActionResult SaveUtilityBuildingExternal(UtilityBuildingExternalModel model)
        {
            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 = ViewBag.edit ?? false;

            if (!ModelState.IsValid) return PartialView("UtilityBuildingExternal", model);

            if (model.UrlAddress != null && !model.UrlAddress.ToLowerInvariant().Contains("http"))
            {
                // make it absolute
                model.UrlAddress = string.Format("http://{0}", model.UrlAddress);
            }
            
            using (var db = new OnLeaveContext())
            {
                UtilityBuilding building = new UtilityBuilding();
                if (model.Id > 0)
                {
                    building = db.UtilityBuildings
                        .Include(b => b.UtilityBuildingPhotoDetails)
                        .FirstOrDefault(b => b.UtilityBuildingId == model.Id);
                    if (building == null || building.UserId != User.Identity.GetUserId())
                    {
                        new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound);
                    }

                    building.KeyWords = model.Name;
                    building.PhoneNumber = model.PhoneNumber;
                    building.CityId = model.CityId;
                    building.ExternalUrl = model.UrlAddress;

                    var buildingLocaleBG = building.UtilityBuildingLocales.FirstOrDefault(l => l.LocaleId == (int)LocaleTypes.BG);
                    if (buildingLocaleBG != null)
                    {
                        buildingLocaleBG.Name = model.Name;                        
                    }
                    else
                    {
                        building.UtilityBuildingLocales.Add(new UtilityBuildingLocale
                        {
                            LocaleId = (int)LocaleTypes.BG,
                            Name = model.Name                            
                        });
                    }

                    var buildingLocaleEN = building.UtilityBuildingLocales.FirstOrDefault(l => l.LocaleId == (int)LocaleTypes.EN);
                    if (buildingLocaleEN != null)
                    {
                        if (string.IsNullOrWhiteSpace(model.NameEN))
                        {
                            // remove if no data                             
                            db.UtilityBuildingLocales.Remove(buildingLocaleEN);
                        }
                        else
                        {
                            buildingLocaleEN.Name = model.NameEN;                            
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrWhiteSpace(model.NameEN))
                        {
                            building.UtilityBuildingLocales.Add(new UtilityBuildingLocale
                            {
                                LocaleId = (int)LocaleTypes.EN,
                                Name = model.NameEN                                
                            });
                        }
                    }
                }
                else
                {
                    building = new UtilityBuilding
                    {
                        KeyWords = model.Name,
                        UtilityBuildingTypeId = model.UtilityBuildingTypeId,
                        UserId = User.Identity.GetUserId(),
                        PhoneNumber = model.PhoneNumber,
                        CityId = model.CityId,
                        SystemTypeId = (int)Common.Constant.SystemType.Booking,
                        ExternalUrl = model.UrlAddress
                    };

                    building.UtilityBuildingLocales.Add(new UtilityBuildingLocale
                    {
                        LocaleId = (int)LocaleTypes.BG,
                        Name = model.Name,
                    });

                    if (!string.IsNullOrWhiteSpace(model.NameEN))
                    {
                        building.UtilityBuildingLocales.Add(new UtilityBuildingLocale
                        {
                            LocaleId = (int)LocaleTypes.EN,
                            Name = model.NameEN,
                        });
                    }

                    db.UtilityBuildings.Add(building);
                }                
                
                db.SaveChanges();
                
                model.Id = building.UtilityBuildingId;
                model.PhotoIds = building.UtilityBuildingPhotoDetails.Select(ph => ph.PhotoId).ToList();
            }

            ViewBag.edit = true;            

            ModelState.Clear();
            return PartialView("UtilityBuildingExternal", model);
        }
示例#7
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);
        }
示例#8
0
        public ActionResult SendReservation(SendReservationModel model)
        {
            if (!ModelState.IsValid)
            {
                return PartialView("_SendReservation",  model);
            }

            UtilityBuilding building = null;
            using (var db = new OnLeaveContext())
            {
                building = db.UtilityBuildings
                    .Include(b => b.UtilityBuildingLocales)
                    .FirstOrDefault(b => b.UtilityBuildingId == model.UtilityBuildingId);
            }

            if (building == null) return new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound, "building not found");

            User user = null;
            using (var db = new UserDbContext())
            {
                user = db.Users.FirstOrDefault(u => u.Id == building.UserId);
            }

            if (user == null) return new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound, "user not found");

            dynamic email = new Email("_Reservation");

            email.To = ConfigurationManager.AppSettings["email"];
            email.From = ConfigurationManager.AppSettings["email"];
            email.Subject = "Резервация от Отпускарче";
            email.ClientName = model.ClientName;
            email.Email = model.Email;
            email.BuildingEmail = user.Email;
            email.StartDate = model.StartDate;
            email.EndDate = model.EndDate;
            email.ReservationDescription = model.ReservationDescription;
            email.BuildingId = building.UtilityBuildingId;
            email.Name = string.Join(" / ", building.UtilityBuildingLocales.Select(l => l.Name).ToArray());
            email.Send();

            ModelState.Clear();
            return PartialView("_SendReservation", new SendReservationModel());
        }