public ActionResult ExceptionalOppertunity() { ExceptionOpportunityModel EOModel = new ExceptionOpportunityModel(); ExceptionOpportunityService _service = new ExceptionOpportunityService(); EOModel.Categories = _service.GetAllHomeSchoolCategories(); EOModel.ExceptionOpportunities = objContext.ExceptionOpportunities.Where(x => x.IsDeletedInd == false && x.StatusInd == true && x.ShowOnHomeInd == true).OrderByDescending(x => x.ExOpportunityCreateDate).ToList(); return(View(EOModel)); }
/// <summary> /// this method will show the Exceptional Opportunity listing. /// </summary> /// <param name="Page">this parameter is used to get page number to be shown.</param> /// <param name="PageSize">this parameter is used to get no of recorde to be shown.</param> /// <param name="gridSortOptions">this parameter is used to get grid sorting option.</param> /// <param name="formCollection">this parameter is used to get controls collection on the page.</param> /// <param name="ObjResult"></param> /// <returns>view to enter Exceptional Opportunity details.</returns> public ActionResult Index(int?Page, int?PageSize, GridSortOptions gridSortOptions, FormCollection formCollection, string ObjResult) { var db_obj = new db_KISDEntities(); TempData["CroppedImage"] = null; #region Check Tab is Accessible or Not db_KISDEntities objContext = new db_KISDEntities(); 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.NewToKISD), 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 //*******************Fill Values if Display order contains null values*************************** var displayOrderList = objContext.ExceptionOpportunities.Where(x => x.IsDeletedInd == false).ToList(); foreach (var item in displayOrderList) { if (string.IsNullOrEmpty(item.DisplayOrderNbr.ToString())) { var objExceptionOppData = objContext.ExceptionOpportunities.Where(x => x.ExOpportunityID == item.ExOpportunityID).FirstOrDefault(); var NewdisplayOrder = (displayOrderList.Max(x => x.DisplayOrderNbr)) == null ? 1 : displayOrderList.Max(x => x.DisplayOrderNbr).Value + 1; objExceptionOppData.DisplayOrderNbr = NewdisplayOrder; 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); } else if (objAjaxRequest.ajaxcall == "showonhome")//Ajax Call type = showonhome { Page = (Session["pageNo"] != null ? Convert.ToInt32(Session["pageNo"].ToString()) : Page); gridSortOptions = (Session["GridSortOption"] != null ? Session["GridSortOption"] as GridSortOptions : gridSortOptions); } else if (objAjaxRequest.ajaxcall == "displayorder")//Ajax Call type = Display Order i.e. drop down values { 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 Exceptional Opportunity if (objAjaxRequest.hfid != null && objAjaxRequest.hfvalue != null && !string.IsNullOrEmpty(objAjaxRequest.hfid) && !string.IsNullOrEmpty(objAjaxRequest.hfvalue) && ObjResult != null && !string.IsNullOrEmpty(ObjResult) && objAjaxRequest.qs_Type.ToString().Trim().ToLower() == "showonhome") { var ExcepOppID = System.Convert.ToInt64(objAjaxRequest.hfid); var objExcepOpp = objContext.ExceptionOpportunities.Find(ExcepOppID); if (objExcepOpp != null) { #region System Change Log var oldresult = (from a in objContext.ExceptionOpportunities where a.ExOpportunityID == ExcepOppID select a).ToList(); DataTable dtOld = KISD.Areas.Admin.Models.Common.LINQResultToDataTable(oldresult); #endregion if (objExcepOpp.StatusInd == false) { TempData["Message"] = "Inactive Exceptional Opportunity cannot be set to show on home."; } else { objExcepOpp.ShowOnHomeInd = objAjaxRequest.hfvalue == "1"; objContext.SaveChanges(); #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 = "Exceptional Opportunity"; objSCL.LogTypeTxt = objExcepOpp.ExOpportunityID > 0 ? "Update" : "Add"; objSCL.NotesTxt = " Details updated show on home for " + objExcepOpp.TitleTxt; objSCL.LogDateTime = DateTime.Now; objContext.SystemChangeLogs.Add(objSCL); objContext.SaveChanges(); objSCL = objContext.SystemChangeLogs.OrderByDescending(x => x.ChangeLogID).FirstOrDefault(); var newResult = (from x in objContext.ExceptionOpportunities where x.ExOpportunityID == objExcepOpp.ExOpportunityID select x); DataTable dtNew = KISD.Areas.Admin.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 TempData["AlertMessage"] = "Show on home updated successfully."; } } objAjaxRequest.hfid = null; //remove parameter value objAjaxRequest.hfvalue = null; //remove parameter value objAjaxRequest.qs_Type = null; //remove parameter value PageSize = ((Request.QueryString["pagesize"] != null && Request.QueryString["pagesize"].ToString() != "All") ? Convert.ToInt32(Request.QueryString["pagesize"].ToString()) : Models.Common._pageSize); Page = (Session["pageNo"] != null ? Convert.ToInt32(Session["pageNo"].ToString()) : Models.Common._currentPage); gridSortOptions = (Session["GridSortOption"] != null ? Session["GridSortOption"] as GridSortOptions : gridSortOptions); } else if (objAjaxRequest.hfid != null && objAjaxRequest.hfvalue != null && !string.IsNullOrEmpty(objAjaxRequest.hfid) && !string.IsNullOrEmpty(objAjaxRequest.hfvalue) && ObjResult != null && !string.IsNullOrEmpty(ObjResult)) { var ExOpportunityID = System.Convert.ToInt64(objAjaxRequest.hfid); var ExceptionOpportunity = objContext.ExceptionOpportunities.Find(ExOpportunityID); if (ExceptionOpportunity != null) { #region System Change Log var oldresult = (from a in objContext.ExceptionOpportunities where a.ExOpportunityID == ExOpportunityID select a).ToList(); DataTable dtOld = KISD.Areas.Admin.Models.Common.LINQResultToDataTable(oldresult); #endregion ExceptionOpportunity.StatusInd = objAjaxRequest.hfvalue == "1"; if (objAjaxRequest.qs_Type == "displayorder") { if (ExceptionOpportunityService.ChangeExceptionOpportunityDisplayOrder(ExceptionOpportunity.DisplayOrderNbr.Value, Convert.ToInt64(objAjaxRequest.qs_value))) { TempData["AlertMessage"] = "Display Order has been changed successfully."; } } else { if (ExceptionOpportunity.ShowOnHomeInd == true) { TempData["Message"] = "Show on Home Exceptional Opportunity cannot be set to Inactive."; } else { objContext.SaveChanges(); #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 = "Exceptional Opportunity"; objSCL.LogTypeTxt = ExceptionOpportunity.ExOpportunityID > 0 ? "Update" : "Add"; objSCL.NotesTxt = " Details updated status for " + ExceptionOpportunity.TitleTxt; objSCL.LogDateTime = DateTime.Now; objContext.SystemChangeLogs.Add(objSCL); objContext.SaveChanges(); objSCL = objContext.SystemChangeLogs.OrderByDescending(x => x.ChangeLogID).FirstOrDefault(); var newResult = (from x in objContext.ExceptionOpportunities where x.ExOpportunityID == ExceptionOpportunity.ExOpportunityID select x); DataTable dtNew = KISD.Areas.Admin.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 TempData["AlertMessage"] = "Status updated successfully."; } } 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()) : Models.Common._pageSize); Page = (Session["pageNo"] != null ? Convert.ToInt32(Session["pageNo"].ToString()) : Models.Common._currentPage); gridSortOptions = (Session["GridSortOption"] != null ? Session["GridSortOption"] as GridSortOptions : gridSortOptions); } } else { TempData["Message"] = string.Empty; } ObjResult = string.Empty; } #endregion Ajax Call ViewBag.Title = ViewBag.PageTitle = "Exceptional Opportunities Listing"; //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 = "ExOpportunityCreateDate"; Session["PageSize"] = null; Session["pageNo"] = null; Session["GridSortOption"] = null; } if (gridSortOptions.Column == "TitleTxt" || gridSortOptions.Column == "ExOpportunityCreateDate" || gridSortOptions.Column == "CategoryName") { } else { gridSortOptions.Column = "ExOpportunityCreateDate"; } //.. 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 <ExceptionOpportunityModel> { ViewData = ViewData, Query = _service.GetExceptionOpportunitys().AsQueryable(), GridSortOptions = gridSortOptions, DefaultSortColumn = "ExOpportunityCreateDate", Page = page, PageSize = pagesize, }.Setup(); if (Request.IsAjaxRequest()) // check if request comes from ajax, then return Partial view { return(View("ExceptionOpportunityPartial", pagedViewModel)); // ("partial view name ") } else { return(View(pagedViewModel)); } }
public JsonResult Delete(string iid, FormCollection fm) { //decrypt ExceptionOpportunity id(iid) iid = !string.IsNullOrEmpty(Convert.ToString(iid)) ? EncryptDecrypt.Decrypt(iid) : "0"; //.. Code for get the route value directory RouteValueDictionary rvd = new RouteValueDictionary(); ViewBag.Title = "Exceptional Opportunity"; var page = Request.QueryString["page"] != null ? Request.QueryString["page"].ToString() : Models.Common._currentPage.ToString(); var pagesize = Request.QueryString["pagesize"] != null ? Request.QueryString["pagesize"].ToString() : Models.Common._pageSize.ToString(); rvd.Add("pagesize", pagesize); rvd.Add("Column", Request.QueryString["Column"] != null ? Request.QueryString["Column"].ToString() : "ExOpportunityCreateDate"); rvd.Add("Direction", Request.QueryString["Direction"] != null ? Request.QueryString["Direction"].ToString() : "Descending"); TempData["pager"] = pagesize; Session["Edit/Delete"] = "Delete"; try { // TODO: Add delete logic here //.. Check for Exceptional Opportunity in use ExceptionOpportunity objExOpportunity = objContext.ExceptionOpportunities.Find(Convert.ToInt32(iid)); int OpportunityID = Convert.ToInt32(iid); #region System Change Log var oldresult = (from a in objContext.ExceptionOpportunities where a.ExOpportunityID == OpportunityID select a).ToList(); DataTable dtOld = KISD.Areas.Admin.Models.Common.LINQResultToDataTable(oldresult); #endregion if (objExOpportunity != null) { // objExOpportunity.IsDeletedInd = true; //****************Display Order ************************ try { var objExOpportunityService = new ExceptionOpportunityService(); objExOpportunityService.ChangeDeletedDisplayOrder(objExOpportunity.DisplayOrderNbr.Value, objExOpportunity.ExOpportunityID); } catch { } //*************************************************** // objContext.SaveChanges(); #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 = "Exceptional Opportunity"; objSCL.LogTypeTxt = "Delete"; objSCL.NotesTxt = " Details deleted for " + objExOpportunity.TitleTxt; objSCL.LogDateTime = DateTime.Now; objContext.SystemChangeLogs.Add(objSCL); objContext.SaveChanges(); objSCL = objContext.SystemChangeLogs.OrderByDescending(x => x.ChangeLogID).FirstOrDefault(); var objContextnew = new db_KISDEntities(); var newResult = (from x in objContextnew.ExceptionOpportunities where x.ExOpportunityID == OpportunityID select x); DataTable dtNew = KISD.Areas.Admin.Models.Common.LINQResultToDataTable(newResult); foreach (DataColumn col in dtNew.Columns) { 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(); } #endregion TempData["AlertMessage"] = "Exceptional Opportunity details deleted successfully."; } //.. Checks for no of records in current page if exists records then return same page number else decrease the page number int?CheckPage = 1; var count = objContext.ExceptionOpportunities.Where(x => x.IsDeletedInd == false).Count(); if (Convert.ToInt32(page) > 1) { CheckPage = count > ((Convert.ToInt32(page) - 1) * Convert.ToInt32(pagesize)) ? Convert.ToInt32(page) : (Convert.ToInt32(page)) - 1; } rvd.Add("page", CheckPage); return(Json(Url.Action("Index", "ExceptionOpportunity", rvd))); } catch { rvd.Add("page", page); return(Json(Url.Action("Index", "ExceptionOpportunity", rvd))); } }
/// <summary> /// Code to create instance Exceptional Opportunity Service class in constructor /// </summary> public ExceptionOpportunityController() { _service = new ExceptionOpportunityService(); }