public ActionResult DocumentMenu(int DocTypeId, int DocId) { if (DocTypeId == 0 || DocId == 0) { return(View("Error")); } int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; int SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; var DocumentType = new DocumentTypeService(_unitOfWork).Find(DocTypeId); if (DocumentType.ControllerActionId.HasValue && DocumentType.ControllerActionId.Value > 0) { ControllerAction CA = new ControllerActionService(_unitOfWork).Find(DocumentType.ControllerActionId.Value); if (CA == null) { return(View("~/Views/Shared/UnderImplementation.cshtml")); } else if (!string.IsNullOrEmpty(DocumentType.DomainName)) { return(Redirect(System.Configuration.ConfigurationManager.AppSettings[DocumentType.DomainName] + "/" + CA.ControllerName + "/" + CA.ActionName + "/" + DocId)); } else { return(RedirectToAction(CA.ActionName, CA.ControllerName, new { id = DocId })); } } ViewBag.RetUrl = System.Web.HttpContext.Current.Request.UrlReferrer; HandleErrorInfo Excp = new HandleErrorInfo(new Exception("Document Settings not Configured"), "StockInHand", "DocumentMenu"); return(View("Error", Excp)); }
public void UpdateActions() { List <ControllerActionList> Actions = new List <ControllerActionList>(); #region ☻ActionUpdateCode☻ var controllers = Assembly.GetExecutingAssembly().GetExportedTypes().Where(t => typeof(ControllerBase).IsAssignableFrom(t)).Select(t => t); foreach (Type controller in controllers) { var actions = controller.GetMethods().Where(t => t.Name != "Dispose" && !t.IsSpecialName && t.DeclaringType.IsSubclassOf(typeof(ControllerBase)) && t.IsPublic && !t.IsStatic).ToList(); foreach (var action in actions) { var myAttributes = action.GetCustomAttributes(false); for (int j = 0; j < myAttributes.Length; j++) { if (myAttributes.All(m => (m is HttpGetAttribute))) { Actions.Add(new ControllerActionList { ActionName = action.Name, ControllerName = controller.Name.Replace("Controller", "") }); break; } } } } List <ControllerActionList> DbControllers = new List <ControllerActionList>(); DbControllers = (from p in db.MvcController where p.IsActive == true select new ControllerActionList { ControllerName = p.ControllerName, ControllerId = p.ControllerId, }).ToList(); var MapControllerActions = (from p in Actions join t in DbControllers on p.ControllerName equals t.ControllerName select new ControllerActionList { ActionName = p.ActionName, ControllerId = t.ControllerId, } ); List <ControllerActionList> DBActions = new List <ControllerActionList>(); DBActions = (from p in db.ControllerAction where p.PubModuleName == ProjectConstants.Customize select new ControllerActionList { ActionId = p.ControllerActionId, ActionName = p.ActionName, ControllerId = p.ControllerId, IsActive = p.IsActive }).ToList(); var PendingToUpdate = (from p in MapControllerActions join t in DBActions on new { ActName = p.ActionName, ContId = p.ControllerId } equals new { ActName = t.ActionName, ContId = t.ControllerId } into table from DBA in table.DefaultIfEmpty() where DBA == null select new ControllerActionList { ActionName = p.ActionName, ControllerId = p.ControllerId }).ToList(); var PendingToDeActivate = (from p in DBActions join t in MapControllerActions on new { ActName = p.ActionName, ContId = p.ControllerId } equals new { ActName = t.ActionName, ContId = t.ControllerId } into table from MCA in table.DefaultIfEmpty() where MCA == null select new ControllerActionList { ActionName = p.ActionName, ControllerId = p.ControllerId, }).ToList(); var PendingToActivate = (from p in MapControllerActions join t in DBActions.Where(m => m.IsActive == false) on new { ActName = p.ActionName, ContId = p.ControllerId } equals new { ActName = t.ActionName, ContId = t.ControllerId } select new ControllerActionList { ActionName = p.ActionName, ControllerId = p.ControllerId }).ToList(); foreach (var item in PendingToUpdate) { ControllerAction temp = new ControllerAction(); temp.ActionName = item.ActionName; temp.IsActive = true; temp.ControllerId = item.ControllerId; temp.PubModuleName = ProjectConstants.Customize; temp.ObjectState = Model.ObjectState.Added; temp.CreatedBy = User.Identity.Name; temp.CreatedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ModifiedDate = DateTime.Now; new ControllerActionService(_unitOfWork).Create(temp); } foreach (var item in PendingToDeActivate) { ControllerAction DeactivateRecord = new ControllerActionService(_unitOfWork).Find(item.ActionName, item.ControllerId); DeactivateRecord.IsActive = false; DeactivateRecord.ModifiedBy = User.Identity.Name; DeactivateRecord.ModifiedDate = DateTime.Now; new ControllerActionService(_unitOfWork).Update(DeactivateRecord); } foreach (var item in PendingToActivate) { ControllerAction ActivateRecord = new ControllerActionService(_unitOfWork).Find(item.ActionName, item.ControllerId); ActivateRecord.IsActive = true; ActivateRecord.ModifiedBy = User.Identity.Name; ActivateRecord.ModifiedDate = DateTime.Now; new ControllerActionService(_unitOfWork).Update(ActivateRecord); } try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ErrorMessage = message; } #endregion }
public ActionResult UpdateDomainNamesForActions() { List <ControllerActionList> Actions = new List <ControllerActionList>(); var controllers = Assembly.GetExecutingAssembly().GetExportedTypes().Where(t => typeof(ControllerBase).IsAssignableFrom(t)).Select(t => t); foreach (Type controller in controllers) { var actions = controller.GetMethods().Where(t => t.Name != "Dispose" && !t.IsSpecialName && t.DeclaringType.IsSubclassOf(typeof(ControllerBase)) && t.IsPublic && !t.IsStatic).ToList(); foreach (var action in actions) { var myAttributes = action.GetCustomAttributes(false); for (int j = 0; j < myAttributes.Length; j++) { if (myAttributes.All(m => (m is HttpGetAttribute))) { Actions.Add(new ControllerActionList { ActionName = action.Name, ControllerName = controller.Name.Replace("Controller", "") }); break; } } } } List <ControllerActionList> DbControllers = new List <ControllerActionList>(); DbControllers = (from p in db.MvcController where p.IsActive == true select new ControllerActionList { ControllerName = p.ControllerName, ControllerId = p.ControllerId, }).ToList(); var MapControllerActions = (from p in Actions join t in DbControllers on p.ControllerName equals t.ControllerName select new ControllerActionList { ActionName = p.ActionName, ControllerId = t.ControllerId, } ); List <ControllerActionList> DBActions = new List <ControllerActionList>(); DBActions = (from p in db.ControllerAction select new ControllerActionList { ActionId = p.ControllerActionId, ActionName = p.ActionName, ControllerId = p.ControllerId, IsActive = p.IsActive }).ToList(); var PendingToUpdate = from p in MapControllerActions join t in DBActions on new { ActName = p.ActionName, ContId = p.ControllerId } equals new { ActName = t.ActionName, ContId = t.ControllerId } select p; foreach (var item in PendingToUpdate) { ControllerAction ActivateRecord = new ControllerActionService(_unitOfWork).Find(item.ActionName, item.ControllerId); ActivateRecord.PubModuleName = ProjectConstants.Customize; new ControllerActionService(_unitOfWork).Update(ActivateRecord); } try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ErrorMessage = message; } if (!string.IsNullOrEmpty(ErrorMessage)) { ViewBag.ErrorMessage = ErrorMessage; return(View("Error")); } else { return(Redirect(System.Configuration.ConfigurationManager.AppSettings["MenuDomain"] + "/Menu/Module/")); } }