//Get Posts By Date
        public ActionResult GetPostsByDate(DateTime firstDate, DateTime secondDate, string type)
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Unauthorized());
            }

            if (!_workContext.CurrentCustomer.IsInCustomerRole(RolesType.Administrators, true) && !_workContext.CurrentCustomer.IsInCustomerRole(RolesType.ConsultationAdmin, true))
            {
                return(Forbid());
            }

            if (firstDate == null || secondDate == null)
            {
                return(NotFound());
            }

            //----------------------
            //var f = firstDate.ToString("dd/MM/yyyy");
            //CultureInfo arSA = new CultureInfo("ar-SA");
            //arSA.DateTimeFormat.Calendar = new HijriCalendar();
            //var dateValue = DateTime.ParseExact(f, "dd/MM/yyyy", arSA);
            //StringBuilder builder = new StringBuilder();
            //builder.Append(dateValue.Day);
            //builder.Append("/");
            //builder.Append(dateValue.Month);
            //builder.Append("/");
            //builder.Append(dateValue.Year);



            //----------------------

            var postsInDb = _postService.GetPostsByDate(firstDate, secondDate, type);
            var posts     = new PostOutputModel
            {
                Posts = postsInDb.Select(m => new PostModel
                {
                    Id                 = m.Id,
                    Text               = m.Text,
                    Title              = m.Title,
                    DateCreated        = m.DateCreated,
                    DateUpdated        = m.DateUpdated,
                    IsClosed           = m.IsClosed,
                    IsAnswered         = m.IsAnswered,
                    Rate               = m.Rate,
                    IsDispayed         = m.IsDispayed,
                    IsReserved         = m.IsReserved,
                    IsSetToSubCategory = m.IsSetToSubCategory,
                    SubCategoryId      = m.SubCategoryId,
                    CategoryId         = m.CategoryId,
                    PostOwner          = m.Customer.Username,
                    CategoryName       = m.Category.Name,
                    SubCategoryName    = m.SubCategory?.Name
                }).ToList()
            };

            return(Json(new { data = posts.Posts }));
        }
        //Not Replied With SubCategory Id In Json
        public ActionResult GetAllNotRepliedPostsWithSubCategoryIdInJson(int subCategoryId)
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Unauthorized());
            }


            if (!_workContext.CurrentCustomer.IsInCustomerRole(RolesType.Administrators, true) && !_workContext.CurrentCustomer.IsInCustomerRole(RolesType.ConsultationAdmin, true))
            {
                return(Forbid());
            }



            if (subCategoryId == null || subCategoryId == 0)
            {
                return(NotFound());
            }

            var posts = _postService.GetNotRepliedPostsWithSubCategoryId(subCategoryId);

            if (posts == null)
            {
                return(NotFound());
            }

            var outputModel = new PostOutputModel
            {
                Posts = posts.Select(m => new PostModel()
                {
                    Id                 = m.Id,
                    Text               = m.Text,
                    Title              = m.Title,
                    DateCreated        = m.DateCreated,
                    DateUpdated        = m.DateUpdated,
                    IsClosed           = m.IsClosed,
                    IsAnswered         = m.IsAnswered,
                    Rate               = m.Rate,
                    IsDispayed         = m.IsDispayed,
                    IsReserved         = m.IsReserved,
                    IsSetToSubCategory = m.IsSetToSubCategory,
                    SubCategoryId      = m.SubCategoryId,
                    CategoryId         = m.CategoryId,
                    PostOwner          = m.Customer.Username,
                    CategoryName       = m.Category.Name,
                    SubCategoryName    = m.SubCategory?.Name
                }).ToList()
            };

            return(Json(new { data = outputModel.Posts }));
        }
        public ActionResult GetAllClosedDisplayedPostsInJson()
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Unauthorized());
            }


            if (!_workContext.CurrentCustomer.IsInCustomerRole(RolesType.Administrators, true) && !_workContext.CurrentCustomer.IsInCustomerRole(RolesType.ConsultationAdmin, true))
            {
                return(Forbid());
            }

            //Server Side Parameters
            var start = Convert.ToInt32(Request.Form["start"].FirstOrDefault());
            //int startRec = Request.Form.GetValues("start").First;
            //int start = Convert.ToInt32(Request.Form.GetValues("start")[0]);
            int    length         = Convert.ToInt32(Request.Form["length"]);
            string searchValue    = Request.Form["search[value]"];
            string sortColumnName = Request.Form["columns[" + Request.Form["order[0][column]"] + "][name]"];
            string sortDirection  = Request.Form["order[0][dir]"];


            var posts = _postService.GetClosedDisplayedPosts(start, length, searchValue, sortColumnName, sortDirection);


            var outputModel = new PostOutputModel
            {
                Posts = posts.Select(m => new PostModel()
                {
                    Id                 = m.Id,
                    Text               = m.Text,
                    Title              = m.Title,
                    DateCreated        = m.DateCreated,
                    DateUpdated        = m.DateUpdated,
                    IsClosed           = m.IsClosed,
                    IsAnswered         = m.IsAnswered,
                    IsCommon           = m.IsCommon,
                    Rate               = m.Rate,
                    IsDispayed         = m.IsDispayed,
                    IsReserved         = m.IsReserved,
                    IsSetToSubCategory = m.IsSetToSubCategory,
                    SubCategoryId      = m.SubCategoryId,
                    CategoryId         = m.CategoryId,
                    PostOwner          = m.Customer.Username,
                    CategoryName       = m.Category.Name,
                    SubCategoryName    = m.SubCategory?.Name
                }).ToList()
            };

            return(Json(new { data = outputModel.Posts }));
        }
Esempio n. 4
0
        public IActionResult GetPostsByCategoryAjax(int categoryId)
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Unauthorized());
            }


            if (!_workContext.CurrentCustomer.IsInCustomerRole(RolesType.Administrators, true) && !_workContext.CurrentCustomer.IsInCustomerRole(RolesType.HaragAdmin, true))
            {
                return(Forbid());
            }

            //Server Side Parameters
            var start = Convert.ToInt32(Request.Form["start"].FirstOrDefault());
            //int startRec = Request.Form.GetValues("start").First;
            //int start = Convert.ToInt32(Request.Form.GetValues("start")[0]);
            int    length         = Convert.ToInt32(Request.Form["length"]);
            string searchValue    = Request.Form["search[value]"];
            string sortColumnName = Request.Form["columns[" + Request.Form["order[0][column]"] + "][name]"];
            string sortDirection  = Request.Form["order[0][dir]"];
            var    posts          = _postService.GetPostsByCategory(categoryId, start, length, searchValue, sortColumnName, sortDirection);


            var outputModel = new PostOutputModel
            {
                Items = posts.Select(m => new PostModel()
                {
                    Id          = m.Id,
                    Text        = m.Text,
                    Title       = m.Title,
                    DateCreated = m.DateCreated,
                    DateUpdated = m.DateUpdated,
                    IsClosed    = m.IsCommentingClosed,
                    IsAnswered  = m.IsAnswered,
                    City        = m.City?.ArName,

                    IsDispayed = m.IsDispayed,
                    IsFeatured = (m.IsFeatured == null ? false : (bool)m.IsFeatured),


                    Customer = m.Customer.Username,
                    Category = m.Category.Name,
                }).ToList()
            };

            return(Json(new { data = outputModel.Items }));
        }
        //Get  Post By Id
        public ActionResult GetPostById(int postId, string type)
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Unauthorized());
            }


            if (!_workContext.CurrentCustomer.IsInCustomerRole(RolesType.Administrators, true) && !_workContext.CurrentCustomer.IsInCustomerRole(RolesType.ConsultationAdmin, true))
            {
                return(Forbid());
            }
            if (postId == 0 || postId == null)
            {
                return(NotFound());
            }

            var postInDb = _postService.GetPostById(postId, type);
            var post     = new PostOutputModel
            {
                Posts = postInDb.Select(m => new PostModel
                {
                    Id                 = m.Id,
                    Text               = m.Text,
                    Title              = m.Title,
                    DateCreated        = m.DateCreated,
                    DateUpdated        = m.DateUpdated,
                    IsClosed           = m.IsClosed,
                    IsAnswered         = m.IsAnswered,
                    Rate               = m.Rate,
                    IsDispayed         = m.IsDispayed,
                    IsReserved         = m.IsReserved,
                    IsSetToSubCategory = m.IsSetToSubCategory,
                    SubCategoryId      = m.SubCategoryId,
                    CategoryId         = m.CategoryId,
                    PostOwner          = m.Customer.Username,
                    CategoryName       = m.Category.Name,
                    SubCategoryName    = m.SubCategory?.Name
                }).ToList()
            };

            return(Json(new { data = post.Posts }));
        }
Esempio n. 6
0
        //Get Post By Id
        public ActionResult GetPostById(int postId)
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Unauthorized());
            }

            if (!_workContext.CurrentCustomer.IsInCustomerRole(RolesType.Administrators, true) && !_workContext.CurrentCustomer.IsInCustomerRole(RolesType.HaragAdmin, true))
            {
                return(Forbid());
            }

            if (postId == 0)
            {
                return(NotFound());
            }

            var postInDb    = _postService.GetPostById(postId);
            var outputModel = new PostOutputModel
            {
                Items = postInDb.Select(m => new PostModel()
                {
                    Id          = m.Id,
                    Text        = m.Text,
                    Title       = m.Title,
                    DateCreated = m.DateCreated,
                    DateUpdated = m.DateUpdated,
                    IsClosed    = m.IsCommentingClosed,
                    IsAnswered  = m.IsAnswered,
                    City        = m.City?.ArName,

                    IsDispayed = m.IsDispayed,
                    IsFeatured = (m.IsFeatured == null ? false : (bool)m.IsFeatured),


                    Customer = m.Customer.Username,
                    Category = m.Category.Name,
                }).ToList()
            };

            return(Json(new { data = outputModel.Items }));
        }