public ActionResult Edit(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Land land = db.Lands.Find(id); if (land == null) { return(HttpNotFound()); } LandsViewModel shopModel = new LandsViewModel { AdDescribtion = land.Ad.AdDescribtion, AdPrice = land.Ad.AdPrice, NumberOfLand = land.NumberOfLand, PlateNumber = land.PlateNumber, StreetsArea = land.StreetsArea, AdTitle = land.Ad.AdTitle, Id = land.AdId, CityId = land.Ad.City.Id }; ViewBag.CityId = new SelectList(db.Cities, "Id", "Name", land.Ad.City.Name); return(View(shopModel)); }
public ActionResult Lands(LandFilterCriteria filter, AnnouncementType type = AnnouncementType.Buy, AnnouncementOrder order = AnnouncementOrder.Address, NavigationViewType viewtype = NavigationViewType.List, int page = 1, bool considerEmpty = true) { IEnumerable <LandAnnouncement> lands = _announcementRepository.GetListOfLands().ToList().Where(an => an.Type == type && an.Address.HasValue); switch (order) { case AnnouncementOrder.Address: lands = lands.OrderBy(a => a.Address.ToString()); break; case AnnouncementOrder.AddressDescending: lands = lands.OrderByDescending(a => a.Address.ToString()); break; case AnnouncementOrder.Date: lands = lands.OrderBy(a => a.Created); break; case AnnouncementOrder.DateDescending: lands = lands.OrderByDescending(a => a.Created); break; default: lands = lands.OrderBy(a => a.Address.ToString()); break; } if (ModelState.IsValid) { if (filter != null) { if (filter.IsEmpty() && considerEmpty) { LandFilterCriteria newFilter = ObjectToCookie.GetObjectFromCookies <LandFilterCriteria>(Request.Cookies, COOKIE_KEY_LANDFILTER); if (newFilter != null) { filter = newFilter; } } lands = filter.Filter(lands); ObjectToCookie.SetCookieAsObject <LandFilterCriteria>(filter, Response.Cookies, COOKIE_KEY_LANDFILTER); } } else { filter = new LandFilterCriteria(); } ViewBag.ViewType = viewtype; ViewBag.Type = type; ViewBag.OrderType = order; if (viewtype == NavigationViewType.List) { LandsListViewModel viewModel = new LandsListViewModel(); viewModel.Page = createPageInfo(page, lands.Count()); setViewModel(viewModel, announcementsForPage(lands, page)); viewModel.FilterCriteria = filter; return(View("Lands", viewModel)); } else { LandsViewModel viewModel = new LandsViewModel(); setViewModel(viewModel, lands); viewModel.FilterCriteria = filter; return(View("LandsMap", viewModel)); } }
public ActionResult Edit(LandsViewModel landsVM, IEnumerable <HttpPostedFileBase> files) { var city = db.Cities.Find(landsVM.CityId); if (ModelState.IsValid) { var land = db.Lands.Find(landsVM.Id); var pics = land.Ad.Pictures; var pictures = new List <Picture>(); if (files != null && files.Count() > 0 && files.FirstOrDefault() != null) { foreach (var file in files) { string filName = Guid.NewGuid() + Path.GetFileName(file.FileName); pictures.Add(new Picture { PictureURL = filName, AdId = land.AdId }); file.SaveAs(Path.Combine(Server.MapPath("/Uploads/"), filName)); } } land.Ad.AdDescribtion = landsVM.AdDescribtion; land.Ad.AdPrice = landsVM.AdPrice; land.Ad.City = city; land.Ad.AdTitle = landsVM.AdTitle; land.NumberOfLand = landsVM.NumberOfLand; land.PlateNumber = landsVM.PlateNumber; if (pictures.Count() > 0) { land.Ad.Pictures.AddRange(pictures); } db.Entry(land).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("MyAds", "Ads")); } ViewBag.CityId = new SelectList(db.Cities, "Id", "Name", landsVM.CityId); return(View(landsVM)); }
public ViewLocator() { Login = new LoginViewModel(); Login.SetCoupledView(new LoginPage()); Lands = new LandsViewModel(); Lands.SetCoupledView(new LandsPage()); Land = new LandViewModel(); Land.SetCoupledView(new LandPage()); LandTabbed = new LandTabbedViewModel(); LandTabbed.SetCoupledView(new LandTabbedPage()); Currency = new CurrencyViewModel(); Currency.SetCoupledView(new CurrencyPage()); Master = new MasterViewModel(); Master.SetCoupledView(new MasterPage()); MasterMenu = new MasterMenuViewModel(); MasterMenu.SetCoupledView(new MasterMenuPage()); }
public MainViewModel() { instance = this; this.Lands = new LandsViewModel(); }
public ActionResult Create(LandsViewModel landsVM, IEnumerable <HttpPostedFileBase> files) { var uid = User.Identity.GetUserId(); var user = db.Users.Find(uid); if (!user.Confirmed) { ViewBag.NotConfirmed = "Sory! wait until the confirmation, thanks!."; ViewBag.CityId = new SelectList(db.Cities, "Id", "Name", landsVM.CityId); return(View(landsVM)); } if (ModelState.IsValid) { if (!User.IsInRole("Admin")) { //find user's listings and check if he advertised more than allowed size int uLiveAdsCount = db.Ads.Where(ap => ap.UserId.Equals(uid)).Count(); ////find user's subscription size int usubsId = db.Users.Where(u => u.Id.Equals(uid)).Select(usub => usub.SubscriptionId).FirstOrDefault(); int subsSize = db.Subscriptions.Where(s => s.SubscriptionId == usubsId).Select(sz => sz.SubscripsionSize).FirstOrDefault(); if (uLiveAdsCount >= subsSize) { ViewBag.LimitReached = "Sory! you have reached the limit of this subscription please remove some ads or upgrade your subscription, thanks!."; ViewBag.CityId = new SelectList(db.Cities, "Id", "Name", landsVM.CityId); return(View(landsVM)); } } //if user chooses no image show him error if (files == null || files.Count() <= 0 || files.FirstOrDefault() == null) { ViewBag.chooseImage = "Please choose image"; ViewBag.CityId = new SelectList(db.Cities, "Id", "Name", landsVM.CityId); return(View(landsVM)); } //end var pictures = new List <Picture>(); foreach (var file in files) { if (file != null && file.ContentLength > 0) { string filName = Guid.NewGuid() + Path.GetFileName(file.FileName); pictures.Add(new Picture { PictureURL = filName }); file.SaveAs(Path.Combine(Server.MapPath("/Uploads/"), filName)); } } var City = db.Cities.Find(landsVM.CityId); Ad Ad = new Ad() { AdDescribtion = landsVM.AdDescribtion, AdPrice = landsVM.AdPrice, City = City, AdTitle = landsVM.AdTitle, Date = DateTime.Now.Date, Discriminator = DiscriminatorOptions.Land, Pictures = pictures, UserId = User.Identity.GetUserId() }; Land land = new Land() { NumberOfLand = landsVM.NumberOfLand, PlateNumber = landsVM.PlateNumber, StreetsArea = landsVM.StreetsArea, Ad = Ad }; db.Lands.Add(land); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(db.Cities, "Id", "Name", landsVM.CityId); return(View(landsVM)); }
public LandsPage() { InitializeComponent(); BindingContext = _viewModel = new LandsViewModel(); }