Exemple #1
0
        public ActionResult Index(int?categoryID, int?pageNumber)
        {
            ViewBag.CategoryId = categoryID;
            int     pageSize       = 3;
            var     lstClassifieds = new List <MyAccountClassifieds>();
            int     pagecount      = 0;
            ViewAds viewAdsModel   = new ViewAds();

            viewAdsModel.nextButton = 2;
            viewAdsModel.prevButton = 1;
            if (pageNumber == null || pageNumber == 1)
            {
                pageNumber = 1;
                viewAdsModel.nextButton = 2; viewAdsModel.prevButton = 1;
            }

            if (categoryID == null)
            {
                lstClassifieds = GetMyAccountClassifiedFromPosts(ClassifiedApi.GetAllPosts()).OrderBy(x => x.PostedDate).Skip(((int)pageNumber - 1) * pageSize).Take((int)pageSize).ToList();
                pagecount      = (int)Math.Ceiling((decimal)ClassifiedApi.GetAllPosts().ToList().Count / (decimal)pageSize);
                //  var pager = new Pager(ClassifiedApi.GetAllPosts().ToList().Count, pageNumber);
            }
            else
            {
                lstClassifieds = GetMyAccountClassifiedFromPosts(ClassifiedApi.GetAllPosts()).Where(x => x.CategoryId == categoryID).OrderBy(x => x.PostedDate).Skip(((int)pageNumber - 1) * pageSize).Take((int)pageSize).ToList();
                pagecount      = (int)Math.Ceiling((decimal)ClassifiedApi.GetAllPosts().Where(x => x.CategoryId == categoryID).ToList().Count / (decimal)pageSize);
            }
            if (pageNumber == pagecount)
            {
                viewAdsModel.nextButton = pagecount;
                if (pagecount == 1)
                {
                    viewAdsModel.prevButton = 1;
                }
                else
                {
                    viewAdsModel.prevButton = Convert.ToInt32(pageNumber) - 1;
                }
            }
            else
            {
                viewAdsModel.nextButton = Convert.ToInt32(pageNumber) + 1;
                if (pageNumber == 1)
                {
                    viewAdsModel.prevButton = Convert.ToInt32(pageNumber);
                }
                else
                {
                    viewAdsModel.prevButton = Convert.ToInt32(pageNumber) - 1;
                }
            }

            viewAdsModel.pageCount   = pagecount;
            viewAdsModel.lst         = lstClassifieds;
            viewAdsModel.lstCategory = ClassifiedApi.GetAllCategory();

            return(View(viewAdsModel));
        }
        public ActionResult ViewDetail(int?classifiedId)
        {
            int id;
            MyAccountClassifieds classified = ClassifiedApi.GetClassifiedById((int.Parse(classifiedId.ToString()) != 0) ? int.Parse(classifiedId.ToString()) : 1);

            if (classified != null)
            {
                return(View(classified));
            }
            else
            {
                return(View("MyAccount"));
            }
        }
Exemple #3
0
        public List <MyAccountClassifieds> GetMyAccountClassifiedFromPosts(List <TAC_Classified> lstTAcClassified)
        {
            List <MyAccountClassifieds> lstClassifieds = new List <MyAccountClassifieds>();

            foreach (var item in lstTAcClassified)
            {
                lstClassifieds.Add(new MyAccountClassifieds()
                {
                    CategoryId      = item.CategoryId,
                    ClassifiedId    = item.ClassifiedId,
                    ClassifiedImage = item.ClassifiedImage,
                    ClassifiedPrice = item.ClassifiedPrice,
                    ClassifiedTitle = item.ClassifiedTitle,
                    CreatedBy       = item.CreatedBy,
                    Description     = item.Description,
                    PostedDate      = item.PostedDate,
                    Summary         = item.Summary,
                    Location        = ((ClassifiedApi.GetContactByClassified(item.ClassifiedId) == null) ? string.Empty : ClassifiedApi.GetContactByClassified(item.ClassifiedId).ContactCity)
                });
            }
            return(lstClassifieds);
        }
        public ActionResult MyAccount(int?categoryID, int?pageNumber)
        {
            Logs();
            MyAccountModel myAccountModel = new MyAccountModel();
            TAC_User       model          = new TAC_User();

            if (Session["User"] != null)
            {
                model = (TAC_User)Session["User"];
            }
            else
            {
                ModelState.AddModelError("User", "Please Login to continue");
                return(View());
            }

            int totalPageCount = 0;

            myAccountModel.nextButton = 2;
            myAccountModel.prevButton = 1;

            ViewBag.CategoryId = categoryID;
            int pageSize       = 3;
            var lstClassifieds = new List <MyAccountClassifieds>();
            int pagecount      = 0;

            if (pageNumber == null || pageNumber == 1)
            {
                pageNumber = 1;
                myAccountModel.nextButton = 2; myAccountModel.prevButton = 1;
            }
            if (categoryID == null)
            {
                lstClassifieds = GetMyAccountClassifiedFromPosts(ClassifiedApi.GetAllPosts().Where(x => x.CreatedBy.ToString().ToLower() == model.UserId.ToString().ToLower()).ToList()).OrderBy(x => x.PostedDate).Skip(((int)pageNumber - 1) * pageSize).Take((int)pageSize).ToList();
                pagecount      = (int)Math.Ceiling((decimal)ClassifiedApi.GetAllPosts().Where(x => x.CreatedBy.ToString().ToLower() == model.UserId.ToString().ToLower()).ToList().Count / (decimal)pageSize);
            }
            else
            {
                lstClassifieds = GetMyAccountClassifiedFromPosts(ClassifiedApi.GetAllPosts().Where(x => x.CreatedBy.ToString().ToLower() == model.UserId.ToString().ToLower()).ToList()).Where(x => x.CategoryId == categoryID).OrderBy(x => x.PostedDate).Skip(((int)pageNumber - 1) * pageSize).Take((int)pageSize).ToList();
                pagecount      = (int)Math.Ceiling((decimal)ClassifiedApi.GetAllPosts().Where(x => x.CreatedBy.ToString().ToLower() == model.UserId.ToString().ToLower()).ToList().Where(x => x.CategoryId == categoryID).ToList().Count / (decimal)pageSize);
            }
            //if (lstClassifieds.Count % 3 == 0)
            //{
            //    totalPageCount = lstClassifieds.Count / 3;
            //}
            //else
            //{
            //    totalPageCount = (lstClassifieds.Count / 3) + 1;
            //}

            if (pageNumber == pagecount)
            {
                myAccountModel.nextButton = pagecount;
                if (pagecount == 1)
                {
                    myAccountModel.prevButton = 1;
                }
                else
                {
                    myAccountModel.prevButton = Convert.ToInt32(pageNumber) - 1;
                }
            }
            else
            {
                myAccountModel.nextButton = Convert.ToInt32(pageNumber) + 1;
                if (pageNumber == 1)
                {
                    myAccountModel.prevButton = Convert.ToInt32(pageNumber);
                }
                else
                {
                    myAccountModel.prevButton = Convert.ToInt32(pageNumber) - 1;
                }
            }


            myAccountModel.myAccountClassifieds = lstClassifieds;
            myAccountModel.pageCount            = pagecount;
            myAccountModel.lstCategory          = ClassifiedApi.GetAllCategory();
            return(View(myAccountModel));
        }