コード例 #1
0
        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);
            }
        }
コード例 #2
0
 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);
        }
コード例 #4
0
        // GET: api/Alive/5
        public IHttpActionResult Get(int id)
        {
            CustomApplicationDbContext context = new CustomApplicationDbContext();
            var setting = context.ApplicationSettings.FirstOrDefault();

            return(Ok(setting.SettingId));
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        public SeedService(CustomApplicationDbContext context)
        {
            _context = context;
            SeedLookups();
            SeedTenants();
            SeedInitialUserAndRole();
            SeedRoles();
            SeedDefaultRolePermissions();
            SeedApplicationSettings();
            SeedUserSettings();

            // Must come last
            SeedBasicApplicationSettings();
        }
コード例 #9
0
        public SeedService(CustomApplicationDbContext context)
        {
            _context = context;
            SeedLookups();
            SeedTenants();
            SeedInitialUserAndRole();
            SeedRoles();
            SeedDefaultRolePermissions();
            SeedApplicationSettings();
            SeedUserSettings();

            // Must come last
            SeedBasicApplicationSettings();
        }
コード例 #10
0
        /// <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()));
        }
コード例 #11
0
        /// <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());
        }
コード例 #12
0
 public AdminUserService(CustomApplicationDbContext context, int tenantId)
 {
     _context = context;
     TenantId = tenantId;
 }
コード例 #13
0
 public UserRepository(CustomApplicationDbContext context, string userId, IAccountProvider accountProvider)
 {
     _db              = context;
     _userId          = userId;
     _accountProvider = accountProvider;
 }
コード例 #14
0
 public TenantUtility()
 {
     _context = new CustomApplicationDbContext();
 }
コード例 #15
0
 public UserServiceUoW(string userId, IAccountProvider accountProvider)
 {
     DbContext      = new CustomApplicationDbContext();
     UserRole       = GetUserRole(userId);
     UserRepository = new UserRepository(DbContext, userId, accountProvider);
 }
コード例 #16
0
 public UserService(CustomApplicationDbContext context, IRepository <ApplicationUser> userRepository)
 {
     _context        = context;
     _userRepository = userRepository;
 }
コード例 #17
0
 public AdminUserService(CustomApplicationDbContext context, int tenantId)
 {
     _context = context;
     TenantId = tenantId;
 }
コード例 #18
0
 public UserServiceUoW(string userId, IAccountProvider accountProvider)
 {
     DbContext = new CustomApplicationDbContext();
     UserRole = GetUserRole(userId);
     UserRepository = new UserRepository(DbContext, userId, accountProvider);
 }
コード例 #19
0
 public TenantUtility()
 {
     _context = new CustomApplicationDbContext();
 }
コード例 #20
0
 public Repository(CustomApplicationDbContext context, string userName)
 {
     dbContext = context;
     SetCurrentUserByUsername(userName);
 }
 public RepositoryWithoutTenant(CustomApplicationDbContext context)
 {
     _db = context;
 }
コード例 #22
0
 public AssetRepository(CustomApplicationDbContext context, string userName) : base(context, userName)
 {
 }
コード例 #23
0
 protected override void Initialize(RequestContext requestContext)
 {
     base.Initialize(requestContext);
     _context     = new CustomApplicationDbContext();
     _userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(_context));
 }
コード例 #24
0
 public SeedUserSettings(string userId)
 {
     _userId = userId;
     _context = new CustomApplicationDbContext();
     SeedBasicApplicationSettings();
 }
コード例 #25
0
 protected override void Initialize(RequestContext requestContext)
 {
     base.Initialize(requestContext);
     _context = new CustomApplicationDbContext();
     _userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(_context));
 }
コード例 #26
0
 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;
 }
コード例 #27
0
 public GenericRepository(CustomApplicationDbContext context)
 {
     _context = context;
     _dbSet   = context.Set <T>();
 }
コード例 #28
0
 public SeedUserSettings(string userId)
 {
     _userId  = userId;
     _context = new CustomApplicationDbContext();
     SeedBasicApplicationSettings();
 }
コード例 #29
0
 // GET: api/Alive/5
 public IHttpActionResult Get(int id)
 {
     CustomApplicationDbContext context = new CustomApplicationDbContext();
     var setting = context.ApplicationSettings.FirstOrDefault();
     return Ok(setting.SettingId);
 }