public ActionResult PostAdvertisement()
        {
            User CurrentUser = (User)Session[WebUtil.CURRENT_USER];

            if (CurrentUser == null)
            {
                return(RedirectToAction("Login", "Users", new { returnurl = "Advertisement/PostAdvertisement" }));
            }
            ViewBag.Country  = new LocationHandler().GetCountries().ToSelectList();
            ViewBag.Catagory = new CatagoriesHandler().GetCatagories().ToSelectList();
            var temp = new AdvertisementTypeHandler().GetAdvertisementTypes().ToSelectList();

            temp.First().Selected = true;
            ViewBag.AdvType = temp;
            return(View());
        }
        public ActionResult PostAdvertisement()
        {
            //Query String Method
            User currentUser = (User)Session[WebUtil.CURRENT_USER];

            if (currentUser == null)
            {
                return(RedirectToAction("Login", "User", new { returnurl = "Advertisement/PostAdvertisement" }));
            }

            ViewBag.CountryList  = new LocationHandler().getAllCountries().ToSelectList();
            ViewBag.CatagoryList = new CatagoryHendler().getAllCatagories().ToSelectList();
            var type = new AdvertisementTypeHandler().GetAllAdvertisementTypes().ToSelectList();

            type.First().Selected = true;
            ViewBag.advType = type;
            return(View());
        }
        public ActionResult EditPost(int id)
        {
            DemoContext   _context = new DemoContext();
            Advertisement objAdv   = new AdvertisementHandler().GetDetailAdvertisement(id);
            var           type     = new AdvertisementTypeHandler().GetAllAdvertisementTypes().ToSelectList();

            // type.Find(x => Convert.ToInt32(x.Value)==objAdv.Type.ID).Selected = true;
            ViewBag.advType = type;

            //This code is  select the selected Country of the Post
            ViewBag.CountryList = new SelectList(_context.Countries, "ID", "Name", objAdv.City.Province.Country.ID);

            //This code is  select the selected Province of the Post
            List <SelectListItem> prv = ModelHelper.ToSelectList(new LocationHandler().getProvincesBtCountry(objAdv.City.Province.Country));

            prv.Find(x => Convert.ToInt32(x.Value) == objAdv.City.Province.ID).Selected = true;
            ViewBag.ProvinceList = prv;


            //This code is  select the selected Cities of the Post
            var citi = ModelHelper.ToSelectList(_context.Ciities.OrderBy(c => c.Name).Where(x => x.Province.ID.Equals(objAdv.City.Province.ID)).ToList());
            // ViewBag.ciList = citi;

            var s = new SelectList(_context.Ciities.OrderBy(x => x.Name).Where(x => x.Province.ID == objAdv.City.Province.ID).ToList(), "ID", "Name");

            ViewBag.ciList = s;
            //This code is also select the selected Catagory of the post
            ViewBag.CatagoryList = new SelectList(_context.Catagories.OrderBy(x => x.Name), "ID", "Name", objAdv.SubCatagory.Catagory.ID);

            //This code is  select the selected SubCatagory of the post
            List <SelectListItem> subcats = ModelHelper.ToSelectList(new CatagoryHendler().getSubCatagoriesByCatagoryId(objAdv.SubCatagory.Catagory));

            subcats.Find(x => Convert.ToInt32(x.Value) == objAdv.SubCatagory.ID).Selected = true;
            ViewBag.SubCatagoryList = subcats;
            // ViewBag.SubCatagoryList = new SelectList(_context.SubCatagories.OrderBy(x => x.Name), "ID", "Name", objAdv.SubCatagory.ID);

            return(View(objAdv));
        }