protected override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); // Определяем сайт SiteId = GetCurrentSiteId(); var userId = Guid.Empty; if (User.Identity.IsAuthenticated) { var _userId = User.Identity.GetUserId(); var currentUser = UserManager.FindById(_userId); userId = currentUser.UserId; } _cmsRepository = new CmsRepository("dbConnection", SiteId, RequestUserInfo.IP, userId); //PageName = _Repository.GetPageName(ControllerName); //StartUrl = "/Admin/" + (String)RouteData.Values["controller"] + "/"; ////Проверка на права доступа к конкретному сайту //var siteAuth = User.IsInRole(SiteId.ToString()); //if(!siteAuth) // filterContext.Result = new RedirectResult("~/Account/AccessDenied"); }
//Не используется параметрический вызов //public BeCoreController(ApplicationUserManager userManager, ApplicationSignInManager signInManager) //{ // UserManager = userManager; // SignInManager = signInManager; //} protected override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); ControllerName = filterContext.RouteData.Values["Controller"].ToString().ToLower(); ActionName = filterContext.RouteData.Values["Action"].ToString().ToLower(); StartUrl = "/Admin/" + (String)RouteData.Values["controller"] + "/"; // Определяем сайт SiteId = GetCurrentSiteId(); // Данные об авторизованном пользователе var _userId = User.Identity.GetUserId(); var currentUser = UserManager.FindById(_userId); var userId = currentUser.UserId; //Проверка на права доступа к сайту var siteAuth = User.IsInRole(SiteId.ToString()); //Проверка на права доступа к контроллеру var controllerAuth = User.Identity.HasClaim(ControllerName, "view"); if (!siteAuth || !controllerAuth) { filterContext.Result = new RedirectResult("~/Account/AccessDenied"); } _cmsRepository = new CmsRepository("dbConnection", SiteId, RequestUserInfo.IP, userId); PageName = _cmsRepository.GetPageName(ControllerName); if (string.IsNullOrEmpty(PageName)) { PageName = _cmsRepository.GetModulePageName(ControllerName); } var core_site = _cmsRepository.GetCoreSites(SiteId); SiteDir = core_site.c_serial.ToString(); //Для построения меню в левой части админки //Для всех админов один список MenuCmsCore = _cmsRepository.GetCmsMenu(); //Модули для всех - разные MenuModulCore = _cmsRepository.GetModulesMenu(userId); ViewBag.SiteId = SiteId.ToString(); }
private static void Run() { var cmsRepository = new CmsRepository(); var fileRepository = new FileRepository(); var errorFiles = new List <SiteContent>(); var logFilePath = ConfigurationManager.AppSettings["LogFilePath"] ?? "."; var logFileName = string.Format(@"{0}\{1}-{2:yyyyMMdd-hhmmsstt}.txt", logFilePath, ApplicationName, DateTime.Now); var logFile = new StreamWriter(logFileName); try { logFile.WriteLine(SettingsMessage); logFile.LogInfo("Retrieving files to copy."); var directories = Directory.GetDirectories(CmsFilePath); foreach (var directory in directories) { var file = Directory.GetFiles(directory).FirstOrDefault(); if (string.IsNullOrEmpty(file)) { logFile.LogError(null, string.Format("Could not find file in directory: {0}", directory)); } var fileInfo = new System.IO.FileInfo(file); var contentId = int.Parse(fileInfo.Directory.Name); var content = cmsRepository.FindBy <SiteContent>(s => s.SiteContentID == contentId).FirstOrDefault(); logFile.LogInfo("Uploading File: {0} ({1:#,00.00} KB)", fileInfo.Name, fileInfo.Length / 1024); if (content == null) { logFile.LogError(null, string.Format("SiteContent Record not found: {0}", contentId)); continue; } var fileBytes = System.IO.File.ReadAllBytes(file); var newFile = new Portal.Model.File { Data = fileBytes, Info = new Portal.Model.FileInfo { Name = fileInfo.Name, Extension = Path.GetExtension(fileInfo.Name), SizeBytes = fileBytes.Length, CreateUserID = 0, CreateDate = DateTime.Now } }; // Save File fileRepository.Add(newFile); fileRepository.Save(); if (newFile.FileID > 0) { content.FileID = newFile.FileID; content.ModifyUserID = 0; content.ModifyDate = DateTime.Now; // Update SiteContent with FileID cmsRepository.Update(content); cmsRepository.Save(); } logFile.LogInfo("\tSaved file: {0}, FileID: {1}.", fileInfo.Name, newFile.FileID); } logFile.LogInfo("Import Completed.\r\n\r\nSummary:\r\nTotal Files: {0}\r\nErrored Files: {1}", directories.Length, errorFiles.Count); //if (errorFiles.Count > 0) //{ // logFile.Log(EventTypes.Warning, null, "Files that could not be imported:"); // errorFiles.ForEach(f => logFile.Log(EventTypes.Warning, null, "\tSiteContentID: {0}, File: {1}:{2}/{3}", f.SiteContentID, f.FileContentLocation, f.FileSubdirectory, f.FileName)); //} logFile.LogInfo("\r\n\r\nDone! Log file saved to: {0}.", Path.GetFullPath(logFileName)); } catch (Exception ex) { logFile.LogError(ex, "\t{0}", ex.FullMessage()); } finally { logFile.Dispose(); cmsRepository.Dispose(); fileRepository.Dispose(); } }