Example #1
0
        public ActionResult SearchByThana()
        {
            var thanas            = _Context.Thanas.ToList();
            CreateAddViewModel ca = new CreateAddViewModel()
            {
                Thanas = thanas
            };

            return(View(ca));
        }
Example #2
0
        public ActionResult SearchByDistrict()
        {
            var districts         = _Context.Districts.ToList();
            CreateAddViewModel ca = new CreateAddViewModel()
            {
                Districts = districts
            };

            return(View(ca));
        }
        public ActionResult StoreAdd(CreateAddViewModel cavm, IEnumerable <HttpPostedFileBase> files)
        {
            if (Session["user_id"] != null)
            {
                if (!ModelState.IsValid)
                {
                    cavm.Divisions = _Context.Divisions.ToList();
                    return(View("CreateAdd", cavm));
                }
                var           user_id = (int)Session["user_id"];
                Advertisement add     = new Advertisement();
                add.Description = cavm.Description;
                add.DivisionId  = cavm.DivisionId;
                add.DistrictId  = cavm.DistrictId;
                add.ThanaId     = cavm.ThanaId;
                add.PublishDate = DateTime.Now;
                add.EndDate     = cavm.EndDate;
                add.Price       = cavm.Price;
                add.UserId      = user_id;
                add.Address     = cavm.Address;
                add.IsPaid      = false;
                add.Key         = user_id.ToString() + "_" + DateTime.Now.ToString("MMddyyyyHHmmssfff");

                _Context.Advertisements.Add(add);
                _Context.SaveChanges();

                var lastAdd = _Context.Advertisements.Where(a => a.UserId == user_id).OrderByDescending(a => a.Id)
                              .ToList();
                var last_id = 0;
                foreach (var x in lastAdd)
                {
                    last_id = x.Id;
                    break;
                }
                foreach (var file in files)
                {
                    if (file != null && file.ContentLength > 0 && file.ContentType.Contains("image") &&
                        Path.GetExtension(file.FileName).ToLower() != ".gif")
                    {
                        using (var reader = new BinaryReader(file.InputStream))
                        {
                            var advertisemage = new AdvertiseImage();
                            advertisemage.AdvertisementId = last_id;
                            advertisemage.ContentType     = file.ContentType;
                            advertisemage.Contents        = reader.ReadBytes(file.ContentLength);

                            _Context.AdvertiseImages.Add(advertisemage);
                            _Context.SaveChanges();
                        }
                    }
                }
                return(RedirectToAction("Index", "Users"));
            }
            return(RedirectToAction("LogInUser", "Users"));
        }
        public ActionResult CreateAdd()
        {
            var division = _Context.Divisions.ToList();

            var creatingAdd = new CreateAddViewModel()
            {
                Divisions = division
            };

            return(View(creatingAdd));
        }
Example #5
0
        public ActionResult CreateAdd()
        {
            var allCategoris = this.categoriesService.GetAll().Select(x => x.CategorieName).ToList();
            var allCities    = this.citiesServices.GetAll().Select(x => x.Name).ToList();

            var searchModel = new CreateAddViewModel();

            searchModel.Categories = allCategoris;
            searchModel.Cities     = allCities;
            return(View(searchModel));
        }
Example #6
0
        public ActionResult SearchDistrict(CreateAddViewModel cavm)
        {
            var districtId = cavm.DistrictId;
            var districtWiseAdvertisement = _Context.Advertisements.Where(a => a.DistrictId == districtId && a.IsPaid == true);
            var allAdd = new AllAddViewModel()
            {
                Advertisements = districtWiseAdvertisement
            };

            return(View(allAdd));
        }
Example #7
0
        public ActionResult SearchThana(CreateAddViewModel cavm)
        {
            var thanaId = cavm.ThanaId;
            var thanaWiseAdvertisments = _Context.Advertisements.Where(a => a.ThanaId == thanaId && a.IsPaid == true).ToList();

            var allAdd = new AllAddViewModel()
            {
                Advertisements = thanaWiseAdvertisments
            };

            return(View(allAdd));
        }