Beispiel #1
0
        private void ExceptionLog(int httpCode)
        {
            Log Log = new Log();

            Log.DateTime = DateTime.UtcNow;
            string controllerName = (string)RouteData.Values["controller"];
            string actionName     = (string)RouteData.Values["action"];
            string StringLogMessage;

            if (httpCode != 0)
            {
                HandleErrorInfo HandleErrorInfo = new System.Web.Mvc.HandleErrorInfo(new HttpException(httpCode, ""), controllerName, actionName);
                StringLogMessage = "Controler:" + HandleErrorInfo.ControllerName +
                                   "---Action:" + HandleErrorInfo.ActionName +
                                   "---Exception.Message" + HandleErrorInfo.Exception.Message;
            }
            else
            {
                StringLogMessage = "Controler:" + controllerName +
                                   "---Action:" + actionName +
                                   "---Exception.Message" + "Error.";
            }
            Log.Message = StringLogMessage;

            PseezEntContext db = new PseezEntContext();

            db.Logs.Add(Log);
            db.SaveChanges();
        }
Beispiel #2
0
 //private void InitializePortalDatabase()
 //{
 //    Database.SetInitializer(new MigrateDatabaseToLatestVersion<PseezEntContext,Configuration>());
 //    var a = new PseezEntContext();
 //    a.Database.Initialize(true);
 //}
 //private void CreateAdminUserAndRole()
 //{
 //    //Initialzie Admin user and Password
 //    IdentityDbContext IdentityDbContext1 = new IdentityDbContext();
 //    UserManager<ApplicationUser> UserManager1 = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
 //    //Create User "Admin" if it is not existed.
 //    if (UserManager1.FindByName("Admin") == null)
 //    {
 //        var user = new ApplicationUser() { UserName = "******" };
 //        UserManager1.Create(user, "Pass#1");
 //    }
 //    //Create Role "Admin" if it is not existed.
 //    RoleManager<IdentityRole> RoleManager1 = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));
 //    if (RoleManager1.FindByName("Admin") == null)
 //    {
 //        IdentityRole IdentityRole1 = new IdentityRole("Admin");
 //        RoleManager1.Create(IdentityRole1);
 //    }
 //    //Add Admin user to Admin Role
 //    string IdentityUserId = IdentityDbContext1.Users.First(x => x.UserName == "Admin").Id;
 //    UserManager1.AddToRole(IdentityUserId, "Admin");
 //}
 private void SaveVisitorsInformation()
 {
     using (PseezEntContext db = new PseezEntContext())
     {
         WebsiteVisitor WebsiteVisitor1 = new WebsiteVisitor();
         WebsiteVisitor1.Date        = DateTime.Now;
         WebsiteVisitor1.HostAddress = Request.UserHostAddress;
         WebsiteVisitor1.HostName    = Request.UserHostName;
         WebsiteVisitor1.Browser     = Request.Browser.Browser;
         WebsiteVisitor1.Url         = Request.Url.AbsoluteUri;
         if (Request.UrlReferrer != null)
         {
             WebsiteVisitor1.UrlReferrer = Request.UrlReferrer.AbsoluteUri;
         }
         else
         {
             WebsiteVisitor1.UrlReferrer = "";
         }
         db.WebsiteVisitors.Add(WebsiteVisitor1);
         db.SaveChanges();
     }
 }