public ActionResult UpdateDomainNamesForControllers() { List <ControllerActionList> Controllers = new List <ControllerActionList>(); var controllers = Assembly.GetExecutingAssembly().GetExportedTypes().Where(t => typeof(ControllerBase).IsAssignableFrom(t)).Select(t => t); foreach (Type controller in controllers) { if (controller.Name != "AccountController") { Controllers.Add(new ControllerActionList { ControllerName = controller.Name.Replace("Controller", "") }); } } List <ControllerActionList> DBControllers = (from p in db.MvcController select new ControllerActionList { ControllerName = p.ControllerName, IsActive = p.IsActive } ).ToList(); var UpdatePubDomains = from p in Controllers join t in DBControllers on p.ControllerName equals t.ControllerName select p.ControllerName; foreach (var item in UpdatePubDomains) { if (!CommonControllers.Controllers.Contains(item)) { MvcController DomainNameUpdateRec = new MvcControllerService(_unitOfWork).Find(item); DomainNameUpdateRec.PubModuleName = ProjectConstants.Customize; DomainNameUpdateRec.ModifiedBy = User.Identity.Name; DomainNameUpdateRec.ModifiedDate = DateTime.Now; new MvcControllerService(_unitOfWork).Update(DomainNameUpdateRec); } } 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/")); } }
public void UpdateControllers() { string s = ""; List <ControllerActionList> List = new List <ControllerActionList>(); List <ControllerActionList> Controllers = new List <ControllerActionList>(); var controllers = Assembly.GetExecutingAssembly().GetExportedTypes().Where(t => typeof(ControllerBase).IsAssignableFrom(t)).Select(t => t); #region ☺ControllerUpdateCode☺ foreach (Type controller in controllers) { if (controller.Name != "AccountController") { Controllers.Add(new ControllerActionList { ControllerName = controller.Name.Replace("Controller", "") }); } } List <ControllerActionList> DBControllers = (from p in db.MvcController where p.PubModuleName == ProjectConstants.Customize select new ControllerActionList { ControllerName = p.ControllerName, IsActive = p.IsActive } ).ToList(); var PendingToUpdate = from p in Controllers join t in DBControllers on p.ControllerName equals t.ControllerName into table from left in table.DefaultIfEmpty() where left == null select p.ControllerName; var PendingToDeActivate = from p in DBControllers join t in Controllers on p.ControllerName equals t.ControllerName into table from right in table.DefaultIfEmpty() where right == null select p.ControllerName; var PendingToActivate = from p in Controllers join t in DBControllers.Where(m => m.IsActive == false) on p.ControllerName equals t.ControllerName select p.ControllerName; foreach (var item in PendingToUpdate) { if (!CommonControllers.Controllers.Contains(item)) { MvcController temp = new MvcController(); temp.ControllerName = item; temp.IsActive = true; 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 MvcControllerService(_unitOfWork).Create(temp); } } foreach (var item in PendingToDeActivate) { MvcController DeactivateRecord = new MvcControllerService(_unitOfWork).Find(item); DeactivateRecord.IsActive = false; DeactivateRecord.ModifiedBy = User.Identity.Name; DeactivateRecord.ModifiedDate = DateTime.Now; new MvcControllerService(_unitOfWork).Update(DeactivateRecord); } foreach (var item in PendingToActivate) { MvcController ActivateRecord = new MvcControllerService(_unitOfWork).Find(item); ActivateRecord.IsActive = true; ActivateRecord.ModifiedBy = User.Identity.Name; ActivateRecord.ModifiedDate = DateTime.Now; new MvcControllerService(_unitOfWork).Update(ActivateRecord); } try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ErrorMessage = message; } #endregion }