public static string GetCompanyImage(SASContext db) { int?companyId = db.Users.Find(WebSecurity.CurrentUserId).companyID; var company = db.Companies.Find(companyId); return(company.logo); }
public override void OnAuthorization(AuthorizationContext filterContext) { base.OnAuthorization(filterContext); db = new SASContext(); if (WebSecurity.IsAuthenticated) { var a = db.Actions .FirstOrDefault(ac => ac.name == filterContext.ActionDescriptor.ActionName); if (new MenuAuthorize().HasPermission(filterContext.ActionDescriptor.ActionName, filterContext.ActionDescriptor.ControllerDescriptor.ControllerName)) { return; } filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary { { "controller", "Unauthorize" }, { "action", "ErrorUnauthorized" } }); } else { filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary { { "controller", "Account" }, { "action", "Login" } }); } }
public void getValues(int ID) { Plan thisPlan = new SASContext().Plans.Find(ID); if (thisPlan == null) { return; } this.ID = thisPlan.ID; this.code = thisPlan.code; this.companyID = thisPlan.companyID; this.createUser = thisPlan.createUser; this.name = thisPlan.name; this.responsible = thisPlan.responsible; this.processID = thisPlan.processID; this.PlanObjectives = thisPlan.PlanObjectives; }
public static string getDataJson(HttpRequestBase Request, int?companyID, SASContext db) { EISDataTables TableParams = new EISDataTables(); TableParams.BindModel(Request); QueryBuilder query = new QueryBuilder(TableParams); query.FilterPagingSortingSearch(companyID); ButtonTemplates buttonTemplates = new ButtonTemplates(); buttonTemplates.fillTemplates(TableParams.buttonsOptions); jsonBuilder json = new jsonBuilder(TableParams); return(json.getDataJson(db, query, buttonTemplates)); }
public static List <SelectListItem> GetRulesSelect(SASContext db) { List <SelectListItem> rls = new List <SelectListItem>(); int?cID = db.Users.Find(WebSecurity.CurrentUserId).companyID; var company = db.Companies.Include(c => c.Rules).FirstOrDefault(c => c.ID == cID); int[] rules = company.Rules.Select(rl => rl.ID).ToArray(); db.Rules.Where(r => r.status == true && rules.Contains(r.ID)).ToList() .ForEach(item => rls.Add( new SelectListItem { Value = item.ID.ToString(), Text = item.code + " - " + item.name }) ); return(rls); }
public string getDataJson(SASContext db, QueryBuilder query, ButtonTemplates buttons) { IEnumerable <object[]> result; using (var cmd = db.Database.Connection.CreateCommand()) { db.Database.Connection.Open(); cmd.CommandText = query.fullQuery; using (var reader = cmd.ExecuteReader()) result = ReadDataReader(reader).ToList(); db.Database.Connection.Close(); } var filteredResult = result.Skip(datatables.iDisplayStart).Take(datatables.iDisplayLength).ToList(); int iTotalRecords = result.Count(); int iTotalDisplayRecords = result.ToList().Skip(0).Count(); string json = string.Format("{2}\"iTotalRecords\": {0},\"iTotalDisplayRecords\": {1}, " + "\"sEcho\":{3}," + "\"aaData\":[" , iTotalRecords, iTotalDisplayRecords, "{", datatables.sEcho, datatables.iDisplayStart); for (int h = 0; h < filteredResult.Count(); h++) { json += "["; for (int i = 0; i < datatables.colums.Count() - 1; i++) { json += "\"" + filteredResult[h][i] + "\","; } json += "\""; foreach (string template in buttons.ButtonMasks) { json += template.Replace("#id", filteredResult[h][datatables.colums.Count() - 1].ToString()); } json += "\",],**"; json = json.Replace(",],**", "],"); } json += "]}**"; json = json.Replace(",]}**", "]}"); json = json.Replace("}**", "}"); return(json); }
/// <summary> /// Constructor para sacar los permisos que tiene un usuario y almacenarlos en la variable $Menu /// </summary> public MenuAuthorize() { try { Tag = "<li>"; if (WebSecurity.IsAuthenticated) { db = new SGC_MVC.Models.SASContext(); var user = db.Users.FirstOrDefault(usr => usr.activeKey == "NOT FOUND"); user = db.Users.FirstOrDefault(usr => usr.ID == WebSecurity.CurrentUserId); foreach (SGC_MVC.Models.Webpages_Roles role in user.Webpages_Roles) { foreach (SGC_MVC.Models.Action action in role.Actions) { if (!Menu.ContainsKey( string.Format("{0}-{1}", action.Controller.name.Replace("Controller", ""), action.name) )) { Menu.Add( string.Format("{0}-{1}", action.Controller.name.Replace("Controller", ""), action.name), action.name ); } } } } } catch { new AuthorizationContext().Result = new RedirectToRouteResult( new RouteValueDictionary { { "controller", "Account" }, { "action", "Login" } }); } }
/// <summary> /// Metodo utilizado para almacenar los nombres de los controladores /// y sus acciones asociadas en la base de datos. /// </summary> public static void InsertControllerAndActions() { ControllerActionProvider cp = new ControllerActionProvider(); bool insertNew = false; using (SASContext db = new SASContext()) { foreach (string controllerName in cp.GetControllerNames()) { SGC_MVC.Models.Controller c = db.Controllers.FirstOrDefault( t => t.name == controllerName); if (c == null) { insertNew = true; c = new SGC_MVC.Models.Controller(); c.name = controllerName; } List <SGC_MVC.Models.Action> actions = new List <SGC_MVC.Models.Action>(); string[] lstActions = cp.GetActionNames(controllerName).Distinct().ToArray(); foreach (string action in lstActions) { SGC_MVC.Models.Action a = new SGC_MVC.Models.Action(); a.name = action; a.isView = true; actions.Add(a); } if (insertNew) { c.Actions = actions; } else { foreach (SGC_MVC.Models.Action a in actions) { if (!c.Actions.Contains(a, new Compare <SGC_MVC.Models.Action>((r, l) => r.name == l.name))) { c.Actions.Add(a); } } } if (db.Controllers.FirstOrDefault(con => con.name == controllerName) == null) { db.Controllers.Add(c); } if (insertNew) { db.SaveChanges(); } else { db.Entry(c).State = System.Data.EntityState.Modified; db.SaveChanges(); } insertNew = false; } } }
public static int?GetCompanyID(SASContext db) { return(db.Users.Find(WebSecurity.CurrentUserId).companyID); }
public static void InsertDefaultData() { using (SASContext db = new SASContext()) { int create_user = db.Users .FirstOrDefault(u => u.username == "*****@*****.**").ID; Status s = new Status(); s.name = "Creacion"; s.description = "Estatus de creacion"; s.createUser = create_user; Department d = new Department(); d.name = "Recursos Humanos"; d.description = "Departamento de recursos humanos"; d.status = true; d.createUser = create_user; Company c = new Company(); c.name = "EIS"; c.description = "Excellent Integrity Solutions"; c.companyText = ":D"; c.status = true; c.email = "*****@*****.**"; c.logo = "(-_-)"; if (db.Status.Count() == 0) { db.Status.Add(s); } if (db.Departments.Count() == 0) { db.Departments.Add(d); } if (db.Companies.Count() == 0) { db.Companies.Add(c); } var actions = db.Actions.Include(con => con.Controller); foreach (SGC_MVC.Models.Action a in actions) { SGC_MVC.Models.View v = new View(); v.description = string.Format("{0}-{1}", a.name, a.Controller.name); v.name = string.Format ( "{0}-{1}", (string.IsNullOrEmpty(a.displayName)) ? a.name : a.displayName, (string.IsNullOrEmpty(a.Controller.displayName)) ? a.Controller.name : a.Controller.displayName ); v.actionID = a.ID; var views = db.Views.ToList(); if (!views.Contains(v, new Compare <SGC_MVC.Models.View>((r, l) => r.description == l.description))) { db.Views.Add(v); } } db.SaveChanges(); } }
public SimpleMembershipInitializer() { Database.SetInitializer <SASContext>(null); try { using (var context = new SASContext()) { if (!context.Database.Exists()) { // Create the SimpleMembership database without Entity Framework migration schema ((IObjectContextAdapter)context).ObjectContext.CreateDatabase(); } } //WebSecurity.InitializeDatabaseConnection("SASContext", "user", "userID", "username", autoCreateTables: true); // Create admin user. if (!WebSecurity.UserExists("*****@*****.**")) { WebSecurity.CreateUserAndAccount( "*****@*****.**", "123456", propertyValues: new { username = "******", password = "******", name = "EISDR", createDate = DateTime.Now, updateDate = DateTime.Now, //email = "*****@*****.**", status = 1, activeKey = "", lastVisitAt = DateTime.Now, superUser = 1, }); } var roles = (SimpleRoleProvider)Roles.Provider; if (!roles.RoleExists("Administrators")) { roles.CreateRole("Administrators"); } if (!roles.GetRolesForUser("*****@*****.**").Contains("Administrators")) { roles.AddUsersToRoles(new[] { "*****@*****.**" }, new[] { "Administrators" }); } Helper.InsertControllerAndActions(); Helper.InsertDefaultData(); using (var db = new SASContext()) { var adminRole = db.Webpages_Roles.FirstOrDefault(r => r.RoleName == "Administrators"); foreach (SGC_MVC.Models.Action a in db.Actions) { if (!adminRole.Actions.Contains(a)) { adminRole.Actions.Add(a); } } db.Entry(adminRole).State = System.Data.EntityState.Modified; db.SaveChanges(); } } catch (Exception ex) { throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex); } }