예제 #1
0
        public static bool Restore(Backup backup)
        {
            lock (thisLock)
            {
                using (context = new BaxterContext())
                {
                    try
                    {
                        context.Database.ExecuteSqlCommand(TransactionalBehavior.DoNotEnsureTransaction,
                            string.Format("USE master; ALTER DATABASE {0} SET SINGLE_USER WITH ROLLBACK IMMEDIATE; RESTORE DATABASE {0} FROM DISK = '{1}' WITH REPLACE"
                            , AppSettings.Name, backup.Path));

                        context.Database.ExecuteSqlCommand(TransactionalBehavior.DoNotEnsureTransaction,
                            string.Format("ALTER DATABASE {0} SET MULTI_USER;", AppSettings.Name));

                        return true;
                    }
                    catch (Exception e)
                    {
                        context.AppLogs.Add(new AppLogError()
                        {
                            MessageID = AppLogMessage.RestoreFailed,
                            Module = Module.Backup,
                            ExtraInfo = e.Message.ToString()
                        });
                        context.SaveChanges();

                        return false;
                    }
                }
            }
        }
예제 #2
0
        private int GetLevel(string functionName)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                var cookie = System.Web.HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
                if (cookie != null)
                {
                    try
                    {
                        using (var db = new BaxterContext())
                        {
                            var userID = int.Parse(FormsAuthentication.Decrypt(cookie.Value).UserData);
                            var role = db.Users.AsNoTracking().Where(u => u.ID == userID).Select(u => u.Role).FirstOrDefault();

                            if (role != null)
                            {
                                var property = typeof(Baxter.Models.Role).GetProperty(functionName + "Access");
                                if (property == null) return 0;

                                return (int)property.GetValue(role, null);
                            }
                            return 0;
                        }
                    }
                    catch (Exception)
                    {
                        return 0;
                    }
                }
            }
            return 0;
        }
예제 #3
0
 private static void GetSettings()
 {
     using (context = new BaxterContext())
     {
         settings = context.BackupSettings.FirstOrDefault();
     }
 }