public ActionResult Index(int?Page, int?PageSize, GridSortOptions gridSortOptions, FormCollection formCollection, string ObjResult) { var objContext = new db_KISDEntities(); var currentLoggedUserId = Convert.ToInt64(Membership.GetUser().ProviderUserKey); var CurrentUserRoleID = objContext.UserRoles.Where(x => x.UserID == currentLoggedUserId).FirstOrDefault().RoleID; #region Check Tab is Accessible or Not var userId = objContext.Users.Where(x => x.UserNameTxt == User.Identity.Name).Select(x => x.UserID).FirstOrDefault(); var RoleID = objContext.UserRoles.Where(x => x.UserID == userId).Select(x => x.RoleID).FirstOrDefault(); var HasTabAccess = GetAccessibleTabAccess(Convert.ToInt32(ModuleType.SchoolBoard), Convert.ToInt32(userId)); if (!(HasTabAccess || RoleID == Convert.ToInt32(UserType.SuperAdmin) || RoleID == Convert.ToInt32(UserType.Admin))) //if tab not accessible then redirect to home { return(RedirectToAction("Index", "Home")); } #endregion ViewBag.Title = ViewBag.PageTitle = "Board Members Listing"; //*******************Fill Values if Display order contains null values*************************** var displayOrderList = objContext.BoardOfMembers.Where(x => x.IsDeletedInd == false).ToList(); foreach (var item in displayOrderList) { if (string.IsNullOrEmpty(item.DisplayOrderNbr.ToString())) { var objContentData = objContext.BoardOfMembers.Where(x => x.BoardMemberID == item.BoardMemberID && x.IsDeletedInd == false).FirstOrDefault(); var displayOrder1 = (displayOrderList.Max(x => x.DisplayOrderNbr)) == null ? 1 : displayOrderList.Max(x => x.DisplayOrderNbr).Value + 1; objContentData.DisplayOrderNbr = displayOrder1; objContext.SaveChanges(); } } //*********************************************************** #region Ajax Call if (ObjResult != null) { AjaxRequest objAjaxRequest = JsonConvert.DeserializeObject <AjaxRequest>(ObjResult);//Convert json String to object Model if (objAjaxRequest.ajaxcall != null && !string.IsNullOrEmpty(objAjaxRequest.ajaxcall) && ObjResult != null && !string.IsNullOrEmpty(ObjResult)) { if (objAjaxRequest.ajaxcall == "paging") //Ajax Call type = paging i.e. Next|Previous|Back|Last { Session["pageNo"] = Page; // stores the page no for status } else if (objAjaxRequest.ajaxcall == "sorting") //Ajax Call type = sorting i.e. column sorting Asc or Desc { Page = (Session["pageNo"] != null ? Convert.ToInt32(Session["pageNo"].ToString()) : Page); Session["GridSortOption"] = gridSortOptions; PageSize = (Session["PageSize"] != null ? Convert.ToInt32(Session["PageSize"].ToString()) : PageSize); } else if (objAjaxRequest.ajaxcall == "ddlPaging")//Ajax Call type = drop down paging i.e. drop down value 10, 25, 50, 100, ALL { Session["PageSize"] = (Request.QueryString["pagesize"] != null ? Convert.ToInt32(Request.QueryString["pagesize"].ToString()) : PageSize); Session["GridSortOption"] = gridSortOptions; Session["pageNo"] = Page; } else if (objAjaxRequest.ajaxcall == "status")//Ajax Call type = status i.e. Active/Inactive { Page = (Session["pageNo"] != null ? Convert.ToInt32(Session["pageNo"].ToString()) : Page); gridSortOptions = (Session["GridSortOption"] != null ? Session["GridSortOption"] as GridSortOptions : gridSortOptions); } objAjaxRequest.ajaxcall = null;; //remove parameter value } //Ajax Call for update status for images if (objAjaxRequest.hfid != null && objAjaxRequest.hfvalue != null && !string.IsNullOrEmpty(objAjaxRequest.hfid) && !string.IsNullOrEmpty(objAjaxRequest.hfvalue) && ObjResult != null && !string.IsNullOrEmpty(ObjResult)) { var ListingID = Convert.ToInt64(objAjaxRequest.hfid); var Listing = objContext.BoardOfMembers.Find(ListingID); if (Listing != null) { #region System Change Log var oldresult = (from a in objContext.BoardOfMembers where a.BoardMemberID == ListingID select a).ToList(); DataTable dtOld = Models.Common.LINQResultToDataTable(oldresult); #endregion if (objAjaxRequest.qs_Type == "status") { Listing.StatusInd = objAjaxRequest.hfvalue == "1"; TempData["Message"] = "Status updated successfully."; } else if (objAjaxRequest.qs_Type == "displayorder") { try { if (BoardMembersModelService.ChangeDisplayOrder(Convert.ToInt64(Listing.DisplayOrderNbr), Convert.ToInt64(objAjaxRequest.qs_value))) { TempData["Message"] = "Display Order has been changed successfully."; } } catch { TempData["Message"] = "Some Error Occured while changing Display Order, Please try again later."; } } objContext.SaveChanges(); #region System Change Log SystemChangeLog objSCL = new SystemChangeLog(); User objuser = objContext.Users.Where(x => x.UserID == currentLoggedUserId).FirstOrDefault(); objSCL.NameTxt = objuser.FirstNameTxt + " " + objuser.LastNameTxt; objSCL.UsernameTxt = objuser.UserNameTxt; objSCL.UserRoleID = (short)objContext.UserRoles.Where(x => x.UserID == objuser.UserID).First().RoleID; objSCL.ModuleTxt = "Board Member Listing"; objSCL.LogTypeTxt = "Update"; objSCL.NotesTxt = (objAjaxRequest.qs_Type == "status" ? "Status " : "Display order ") + "updated for " + Listing.NameTxt; objSCL.LogDateTime = DateTime.Now; objContext.SystemChangeLogs.Add(objSCL); objContext.SaveChanges(); objSCL = objContext.SystemChangeLogs.OrderByDescending(x => x.ChangeLogID).FirstOrDefault(); var newResult = (from x in objContext.BoardOfMembers where x.BoardMemberID == Listing.BoardMemberID select x); DataTable dtNew = Models.Common.LINQResultToDataTable(newResult); foreach (DataColumn col in dtNew.Columns) { // if(objSCL) if (dtOld.Rows[0][col.ColumnName].ToString() != dtNew.Rows[0][col.ColumnName].ToString()) { SystemChangeLogDetail objSCLD = new SystemChangeLogDetail(); objSCLD.ChangeLogID = objSCL.ChangeLogID; objSCLD.FieldNameTxt = col.ColumnName.ToString(); objSCLD.OldValueTxt = dtOld.Rows[0][col.ColumnName].ToString(); objSCLD.NewValueTxt = dtNew.Rows[0][col.ColumnName].ToString(); objContext.SystemChangeLogDetails.Add(objSCLD); objContext.SaveChanges(); } } #endregion objAjaxRequest.hfid = null; //remove parameter value objAjaxRequest.hfvalue = null; //remove parameter value PageSize = ((Request.QueryString["pagesize"] != null && Request.QueryString["pagesize"].ToString() != "All") ? Convert.ToInt32(Request.QueryString["pagesize"].ToString()) : PageSize); Page = (Session["pageNo"] != null ? Convert.ToInt32(Session["pageNo"].ToString()) : Page); gridSortOptions = (Session["GridSortOption"] != null ? Session["GridSortOption"] as GridSortOptions : gridSortOptions); } } else { TempData["Message"] = string.Empty; } ObjResult = string.Empty; } #endregion Ajax Call //This section is used to retain the values of page , pagesize and gridsortoption on complete page post back(Edit, Dlete) if (!Request.IsAjaxRequest() && Session["Edit/Delete"] != null && !string.IsNullOrEmpty(Session["Edit/Delete"].ToString())) { PageSize = (Session["PageSize"] != null ? Convert.ToInt32(Session["PageSize"]) : Models.Common._pageSize); Page = (Session["pageNo"] != null ? Convert.ToInt32(Session["pageNo"]) : Models.Common._currentPage); gridSortOptions = (Session["GridSortOption"] != null ? Session["GridSortOption"] as GridSortOptions : gridSortOptions); Session["Edit/Delete"] = null; } else if (!Request.IsAjaxRequest() && Session["Edit/Delete"] == null) { gridSortOptions.Column = "BOMCreateDate"; Session["PageSize"] = null; Session["pageNo"] = null; Session["GridSortOption"] = null; } if (gridSortOptions.Column == "NameTxt" || gridSortOptions.Column == "TitleTxt" || gridSortOptions.Column == "DisplayOrderNbr" || gridSortOptions.Column == "TitleTxt" ) { } else { gridSortOptions.Column = "BOMCreateDate"; } //.. Code for get records as page view model var pagesize = PageSize.HasValue ? PageSize.Value : Models.Common._pageSize; var page = Page.HasValue ? Page.Value : Models.Common._currentPage; TempData["pager"] = pagesize; var pagedViewModel = new PagedViewModel <BoardMembersModel> { ViewData = ViewData, Query = _service.GetBoardMembers().AsQueryable(), GridSortOptions = gridSortOptions, DefaultSortColumn = "BOMCreateDate", Page = page, PageSize = pagesize, }.Setup(); if (Request.IsAjaxRequest()) // check if request comes from ajax, then return Partial view { return(View("BoardMembersListingPartial", pagedViewModel)); // ("partial view name ") } else { return(View(pagedViewModel)); } }
public JsonResult Delete(string bmid) { bmid = !string.IsNullOrEmpty(Convert.ToString(bmid)) ? EncryptDecrypt.Decrypt(bmid) : "0"; long BOMID = Convert.ToInt32(bmid); var rvd = new RouteValueDictionary(); rvd.Add("pagesize", Request.QueryString["pagesize"] ?? "10"); rvd.Add("Column", Request.QueryString["Column"] ?? "BOMCreateDate"); rvd.Add("Direction", Request.QueryString["Direction"] ?? "Descending"); Session["Edit/Delete"] = "Delete"; if (BOMID > 0) { try { using (var objContext = new db_KISDEntities()) { #region System Change Log var oldresult = (from a in objContext.BoardOfMembers where a.BoardMemberID == BOMID select a).ToList(); DataTable dtOld = Models.Common.LINQResultToDataTable(oldresult); #endregion //****************Display Order ************************ var objData = objContext.BoardOfMembers.Where(x => x.BoardMemberID == BOMID).FirstOrDefault(); if (objData != null) { try { var objModelService = new BoardMembersModelService(); var parentid = Request.QueryString["ParentId"] ?? "0"; objModelService.ChangeDeletedDisplayOrder(objData.DisplayOrderNbr.Value, objData.BoardMemberID); } catch { } } //*************************************************** #region System Change Log SystemChangeLog objSCL = new SystemChangeLog(); long userid = Convert.ToInt64(Membership.GetUser().ProviderUserKey); User objuser = objContext.Users.Where(x => x.UserID == userid).FirstOrDefault(); objSCL.NameTxt = objuser.FirstNameTxt + " " + objuser.LastNameTxt; objSCL.UsernameTxt = objuser.UserNameTxt; objSCL.UserRoleID = (short)objContext.UserRoles.Where(x => x.UserID == objuser.UserID).First().RoleID; objSCL.ModuleTxt = "Board Members"; objSCL.LogTypeTxt = "Delete"; objSCL.NotesTxt = "Board Members Details deleted for " + objData.NameTxt; objSCL.LogDateTime = DateTime.Now; objContext.SystemChangeLogs.Add(objSCL); objContext.SaveChanges(); objSCL = objContext.SystemChangeLogs.OrderByDescending(x => x.ChangeLogID).FirstOrDefault(); var newResult = (from x in objContext.RightSections where x.RightSectionID == BOMID select x); DataTable dtNew = Models.Common.LINQResultToDataTable(newResult); foreach (DataColumn col in dtNew.Columns) { try { SystemChangeLogDetail objSCLD = new SystemChangeLogDetail(); objSCLD.ChangeLogID = objSCL.ChangeLogID; objSCLD.FieldNameTxt = col.ColumnName.ToString(); objSCLD.OldValueTxt = dtOld.Rows[0][col.ColumnName].ToString(); objSCLD.NewValueTxt = col.ColumnName == "IsDeletedInd" ? dtNew.Rows[0][col.ColumnName].ToString() : ""; objContext.SystemChangeLogDetails.Add(objSCLD); objContext.SaveChanges(); } catch { } } #endregion try { Models.Common.DeleteImage(Server.MapPath(objData.ImageURLTxt)); } catch { } TempData["Message"] = " Board Member details deleted successfully."; } } catch (Exception e) { TempData["Message"] = "Some error occured while deleting the Member, Please try again later."; } } int?Page = 1; var count = 1; using (var objContext = new db_KISDEntities()) { count = objContext.Users.Where(x => x.IsDeletedInd == false).Count(); } var page = Request.QueryString["page"] ?? "1"; var pagesize = Request.QueryString["pagesize"] ?? "10"; if (Convert.ToInt32(page) > 1) { Page = count > ((Convert.ToInt32(page) - 1) * Convert.ToInt32(pagesize)) ? Convert.ToInt32(page) : (Convert.ToInt32(page)) - 1; } rvd.Add("page", Page); return(Json(Url.Action("Index", "BoardMembers", rvd))); }
/// <summary> /// Code to create instance Image Service class in constructor /// </summary> public BoardMembersController() { _service = new BoardMembersModelService(); }