public ActionResult GetConsultantPostsInJson(int consultantId, string type, DateTime?from, DateTime?to) { if (!_workContext.CurrentCustomer.IsRegistered()) { return(Unauthorized()); } if (!_workContext.CurrentCustomer.IsInCustomerRole(RolesType.Administrators, true) && !_workContext.CurrentCustomer.IsInCustomerRole(RolesType.ConsultationAdmin, true)) { return(Forbid()); } if (consultantId == null || consultantId == 0) { return(NotFound()); } //Server Side Parameters int start = Convert.ToInt32(Request.Form["start"].FirstOrDefault()); 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 customerPostsInDb = _postService.GetConsultantPosts(consultantId, type, start, length, searchValue, sortColumnName, sortDirection, from, to); var customerPosts = new CustomerPostsOutputModel { CustomerPosts = customerPostsInDb.Select(m => new CustomerPostsModel { Username = m.Consultant?.Username, Email = m.Consultant?.Email, Mobile = m.Consultant?.Mobile, SystemName = m.Consultant?.SystemName, PostId = 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.Consultant?.Username, CategoryName = m.Category.Name, SubCategoryName = m.SubCategory?.Name }).ToList() }; return(Json(new { data = customerPosts.CustomerPosts })); }
//Get Consultant Post By PostId and ConsultantId public ActionResult GetConsultantPostById(int consultantId, 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 (consultantId == null || consultantId == 0 || postId == null || postId == 0) { return(NotFound()); } var postInDb = _postService.GetConsultantPostById(consultantId, postId, type); var customerPost = new CustomerPostsOutputModel { CustomerPosts = postInDb.Select(m => new CustomerPostsModel { Username = m.Consultant.Username, Email = m.Consultant.Email, Mobile = m.Consultant.Mobile, SystemName = m.Consultant.SystemName, PostId = 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 = customerPost.CustomerPosts })); }