public override void OnAuthorization(AuthorizationContext filterContext) { base.OnAuthorization(filterContext); EnumHelper.Roles role = EnumHelper.Roles.Viewer; if (HttpContext.Current.User.IsInRole(EnumHelper.Roles.Author.ToString())) { role = EnumHelper.Roles.Author; } else if (HttpContext.Current.User.IsInRole(EnumHelper.Roles.Admin.ToString())) { role = EnumHelper.Roles.Admin; } string action = filterContext.Controller.ControllerContext.RouteData.Values["action"].ToString(); string controller = filterContext.Controller.ControllerContext.RouteData.Values["controller"].ToString(); CustomApplicationDbContext context = new CustomApplicationDbContext(); IQueryable <RolePermission> rolePermissions = context.RolePermissions; PermissionHelper permissionHelper = new PermissionHelper(rolePermissions); if (!permissionHelper.HasPermission(role, controller, action)) { HandleUnauthorizedRequest(filterContext); } }
public IHttpActionResult Get(int id) { CustomApplicationDbContext db = new CustomApplicationDbContext(); IQueryable<Lookup> itemTypes = db.Lookups.Where(l => l.Type.Description == EnumHelper.LookupTypes.Category.ToString()); IQueryable<Lookup> quoteRequestStatusTypes = db.Lookups.Where(l => l.Type.Description == EnumHelper.LookupTypes.QuoteRequestStatus.ToString()); IQueryable<Tenant> tenants = db.Tenants.Where(t => t.Users.Where(u => u.UserName == User.Identity.Name).Any()); Mapper.CreateMap<Tenant, TenantViewModel>(); var listOfTenantViewModel = Mapper.Map<IEnumerable<Tenant>, IEnumerable<TenantViewModel>>(tenants.ToList()); if (id == -1) { QuoteRequestViewModel quoteRequestTemplate = new QuoteRequestViewModel(); quoteRequestTemplate.ItemTypes = itemTypes; quoteRequestTemplate.Tenants = listOfTenantViewModel; quoteRequestTemplate.QuoteRequestStatuses = quoteRequestStatusTypes; quoteRequestTemplate.SelectedQuoteRequestStatus = quoteRequestStatusTypes.FirstOrDefault(x => x.Description == "Pending"); return Ok(quoteRequestTemplate); } QuoteRequest quoteRequest = QuoteRequestService.GetSingleQuote(id); Mapper.CreateMap<QuoteRequest, QuoteRequestViewModel>(); QuoteRequestViewModel quoteRequestViewModel = Mapper.Map<QuoteRequestViewModel>(quoteRequest); quoteRequestViewModel.ItemTypes = itemTypes.ToList(); quoteRequestViewModel.QuoteRequestStatuses = quoteRequestStatusTypes.ToList(); quoteRequestViewModel.SelectedItemType = quoteRequest.Category; quoteRequestViewModel.SelectedQuoteRequestStatus = quoteRequest.QuoteRequestStatus; quoteRequestViewModel.Tenants = listOfTenantViewModel; quoteRequestViewModel.CanChangeStatus = User.IsInRole("Admin") ? true : false; return Ok(quoteRequestViewModel); //return Json<QuoteRequestViewModel>(quoteRequestViewModel); }
public IHttpActionResult Get(int id) { CustomApplicationDbContext db = new CustomApplicationDbContext(); IQueryable <Lookup> itemTypes = db.Lookups.Where(l => l.Type.Description == EnumHelper.LookupTypes.Category.ToString()); IQueryable <Lookup> quoteRequestStatusTypes = db.Lookups.Where(l => l.Type.Description == EnumHelper.LookupTypes.QuoteRequestStatus.ToString()); IQueryable <Tenant> tenants = db.Tenants.Where(t => t.Users.Where(u => u.UserName == User.Identity.Name).Any()); Mapper.CreateMap <Tenant, TenantViewModel>(); var listOfTenantViewModel = Mapper.Map <IEnumerable <Tenant>, IEnumerable <TenantViewModel> >(tenants.ToList()); if (id == -1) { QuoteRequestViewModel quoteRequestTemplate = new QuoteRequestViewModel(); quoteRequestTemplate.ItemTypes = itemTypes; quoteRequestTemplate.Tenants = listOfTenantViewModel; quoteRequestTemplate.QuoteRequestStatuses = quoteRequestStatusTypes; quoteRequestTemplate.SelectedQuoteRequestStatus = quoteRequestStatusTypes.FirstOrDefault(x => x.Description == "Pending"); return(Ok(quoteRequestTemplate)); } QuoteRequest quoteRequest = QuoteRequestService.GetSingleQuote(id); Mapper.CreateMap <QuoteRequest, QuoteRequestViewModel>(); QuoteRequestViewModel quoteRequestViewModel = Mapper.Map <QuoteRequestViewModel>(quoteRequest); quoteRequestViewModel.ItemTypes = itemTypes.ToList(); quoteRequestViewModel.QuoteRequestStatuses = quoteRequestStatusTypes.ToList(); quoteRequestViewModel.SelectedItemType = quoteRequest.Category; quoteRequestViewModel.SelectedQuoteRequestStatus = quoteRequest.QuoteRequestStatus; quoteRequestViewModel.Tenants = listOfTenantViewModel; quoteRequestViewModel.CanChangeStatus = User.IsInRole("Admin") ? true : false; return(Ok(quoteRequestViewModel)); //return Json<QuoteRequestViewModel>(quoteRequestViewModel); }
// GET: api/Alive/5 public IHttpActionResult Get(int id) { CustomApplicationDbContext context = new CustomApplicationDbContext(); var setting = context.ApplicationSettings.FirstOrDefault(); return(Ok(setting.SettingId)); }
public override void OnAuthorization(AuthorizationContext filterContext) { base.OnAuthorization(filterContext); EnumHelper.Roles role = EnumHelper.Roles.Viewer; if(HttpContext.Current.User.IsInRole(EnumHelper.Roles.Author.ToString())) { role = EnumHelper.Roles.Author; } else if(HttpContext.Current.User.IsInRole(EnumHelper.Roles.Admin.ToString())) { role = EnumHelper.Roles.Admin; } string action = filterContext.Controller.ControllerContext.RouteData.Values["action"].ToString(); string controller = filterContext.Controller.ControllerContext.RouteData.Values["controller"].ToString(); CustomApplicationDbContext context = new CustomApplicationDbContext(); IQueryable<RolePermission> rolePermissions = context.RolePermissions; PermissionHelper permissionHelper = new PermissionHelper(rolePermissions); if (!permissionHelper.HasPermission(role, controller, action)) { HandleUnauthorizedRequest(filterContext); } }
protected override void Seed(HardwareInventoryManager.Models.ApplicationDbContext context) { //if (System.Diagnostics.Debugger.IsAttached == false) // System.Diagnostics.Debugger.Launch(); // This method will be called after migrating to the latest version. CustomApplicationDbContext customContext = new CustomApplicationDbContext(); SeedService initialSeed = new SeedService(customContext); }
private IEnumerable <TenantViewModel> GetTenants() { CustomApplicationDbContext context = new CustomApplicationDbContext(); IQueryable <Tenant> tenants = context.Tenants.Where(t => t.Users.Where(u => u.UserName == User.Identity.Name).Any()); Mapper.CreateMap <Tenant, TenantViewModel>(); var listOfTenantViewModel = Mapper.Map <IEnumerable <Tenant>, IEnumerable <TenantViewModel> >(tenants.ToList()); return(listOfTenantViewModel); }
public SeedService(CustomApplicationDbContext context) { _context = context; SeedLookups(); SeedTenants(); SeedInitialUserAndRole(); SeedRoles(); SeedDefaultRolePermissions(); SeedApplicationSettings(); SeedUserSettings(); // Must come last SeedBasicApplicationSettings(); }
/// <summary> /// Returns the table row Edit | Details | Delete links which the user in scope has permission to. /// </summary> /// <param name="html"></param> /// <param name="linkId"></param> /// <returns></returns> public static MvcHtmlString IndexLinks(this HtmlHelper html, object linkId) { // Get the users role EnumHelper.Roles role = EnumHelper.Roles.Viewer; if (HttpContext.Current.User.IsInRole(EnumHelper.Roles.Author.ToString())) { role = EnumHelper.Roles.Author; } else if (HttpContext.Current.User.IsInRole(EnumHelper.Roles.Admin.ToString())) { role = EnumHelper.Roles.Admin; } // Get the current route Controller name var currentRouteData = html.ViewContext.RouteData; string controller = currentRouteData.GetRequiredString("controller"); // Check user permissions CustomApplicationDbContext context = new CustomApplicationDbContext(); IQueryable <RolePermission> rolePermissions = context.RolePermissions; PermissionHelper permissionHelper = new PermissionHelper(rolePermissions); // Build the MvcHtmlString StringBuilder linkStringBuilder = new StringBuilder(); if (permissionHelper.HasPermission(role, controller, "Edit")) { linkStringBuilder.Append(string.Format("{0} |", LinkExtensions.ActionLink(html, "Edit", "Edit", linkId))); } linkStringBuilder.Append(LinkExtensions.ActionLink(html, "Details", "Details", linkId)); if (permissionHelper.HasPermission(role, controller, "Delete")) { linkStringBuilder.Append(string.Format("| {0}", LinkExtensions.ActionLink(html, "Delete", "Delete", linkId))); } return(new MvcHtmlString(linkStringBuilder.ToString())); }
/// <summary> /// Returns the table row Edit | Details | Delete links which the user in scope has permission to. /// </summary> /// <param name="html"></param> /// <param name="linkId"></param> /// <returns></returns> public static MvcHtmlString IndexLinks(this HtmlHelper html, object linkId) { // Get the users role EnumHelper.Roles role = EnumHelper.Roles.Viewer; if (HttpContext.Current.User.IsInRole(EnumHelper.Roles.Author.ToString())) { role = EnumHelper.Roles.Author; } else if (HttpContext.Current.User.IsInRole(EnumHelper.Roles.Admin.ToString())) { role = EnumHelper.Roles.Admin; } // Get the current route Controller name var currentRouteData = html.ViewContext.RouteData; string controller = currentRouteData.GetRequiredString("controller"); // Check user permissions CustomApplicationDbContext context = new CustomApplicationDbContext(); IQueryable<RolePermission> rolePermissions = context.RolePermissions; PermissionHelper permissionHelper = new PermissionHelper(rolePermissions); // Build the MvcHtmlString StringBuilder linkStringBuilder = new StringBuilder(); if (permissionHelper.HasPermission(role, controller, "Edit")) { linkStringBuilder.Append(string.Format("{0} |", LinkExtensions.ActionLink(html, "Edit", "Edit", linkId))); } linkStringBuilder.Append(LinkExtensions.ActionLink(html, "Details", "Details", linkId)); if (permissionHelper.HasPermission(role, controller, "Delete")) { linkStringBuilder.Append(string.Format("| {0}", LinkExtensions.ActionLink(html, "Delete", "Delete", linkId))); } return new MvcHtmlString(linkStringBuilder.ToString()); }
public AdminUserService(CustomApplicationDbContext context, int tenantId) { _context = context; TenantId = tenantId; }
public UserRepository(CustomApplicationDbContext context, string userId, IAccountProvider accountProvider) { _db = context; _userId = userId; _accountProvider = accountProvider; }
public TenantUtility() { _context = new CustomApplicationDbContext(); }
public UserServiceUoW(string userId, IAccountProvider accountProvider) { DbContext = new CustomApplicationDbContext(); UserRole = GetUserRole(userId); UserRepository = new UserRepository(DbContext, userId, accountProvider); }
public UserService(CustomApplicationDbContext context, IRepository <ApplicationUser> userRepository) { _context = context; _userRepository = userRepository; }
public Repository(CustomApplicationDbContext context, string userName) { dbContext = context; SetCurrentUserByUsername(userName); }
public RepositoryWithoutTenant(CustomApplicationDbContext context) { _db = context; }
public AssetRepository(CustomApplicationDbContext context, string userName) : base(context, userName) { }
protected override void Initialize(RequestContext requestContext) { base.Initialize(requestContext); _context = new CustomApplicationDbContext(); _userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(_context)); }
public SeedUserSettings(string userId) { _userId = userId; _context = new CustomApplicationDbContext(); SeedBasicApplicationSettings(); }
protected override void Initialize(RequestContext requestContext) { base.Initialize(requestContext); _context = new CustomApplicationDbContext(); _userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(_context)); }
private IEnumerable<TenantViewModel> GetTenants() { CustomApplicationDbContext context = new CustomApplicationDbContext(); IQueryable<Tenant> tenants = context.Tenants.Where(t => t.Users.Where(u => u.UserName == User.Identity.Name).Any()); Mapper.CreateMap<Tenant, TenantViewModel>(); var listOfTenantViewModel = Mapper.Map<IEnumerable<Tenant>, IEnumerable<TenantViewModel>>(tenants.ToList()); return listOfTenantViewModel; }
public GenericRepository(CustomApplicationDbContext context) { _context = context; _dbSet = context.Set <T>(); }
// GET: api/Alive/5 public IHttpActionResult Get(int id) { CustomApplicationDbContext context = new CustomApplicationDbContext(); var setting = context.ApplicationSettings.FirstOrDefault(); return Ok(setting.SettingId); }