2015 is lining up to be the year of React. Lately, it has garnered a lot of attention, for front-end, mobile and server side JavaScript development.
اشتراکها
دوره 8 ساعته طراحی بانکهای اطلاعاتی
اشتراکها
سری بررسی PWA در 30 روز
اشتراکها
سری آموزشی SQL Server 2019
اشتراکها
کار با Vim در Visual Studio Code
نظرات مطالب
رسم نمودار توسط Kendo Chart
کاملاً مشخصه، با افزودن یک کاما خطوط فوق را اضافه کنید، مثلاً بعد از series و یا tooltip
اشتراکها
کتابخانه angular-overlay-menu
This directive is designed to provide a general purpose overlay menu. Floating menu can be used for both flat and nested navigation structures. Desgined to be as simple as possible in order to afford intuitive interactions. Demo
اشتراکها
نمایش تاریخ و زمان به صورت منطقه ای
نظرات مطالب
ASP.NET MVC #18
- نیازی نیست تمام متدهای RoleProvider دات نت پیاده سازی شوند. برای یک برنامه پیاده سازی دو متد IsUserInRole، GetRolesForUser کافی است.
- سپس دو کلاس Role و User را باید تعریف کنید. این دو رابطه many-to-many با هم دارند؛ یعنی هر کدام با یک ICollection به دیگری ارتباط پیدا میکنند. سپس این دو کلاس را در کلاس Context برنامه مطابق معمول توسط DbSetها در معرض دید EF قرار میدهید. مابقی آن کارکردن معمولی با این دو جدول اضافه شده به برنامه است:
و در این حالت CustomRoleProvider به صورت زیر خواهد بود. در این روش فرض شده حین لاگین، user.Id در FormsAuthentication.SetAuthCookie تنظیم میشود؛ یعنی userName در این RoleProvider به id آن تنظیم شده:
- سپس دو کلاس Role و User را باید تعریف کنید. این دو رابطه many-to-many با هم دارند؛ یعنی هر کدام با یک ICollection به دیگری ارتباط پیدا میکنند. سپس این دو کلاس را در کلاس Context برنامه مطابق معمول توسط DbSetها در معرض دید EF قرار میدهید. مابقی آن کارکردن معمولی با این دو جدول اضافه شده به برنامه است:
public class EfRolesService : IRolesService { readonly IUnitOfWork _uow; readonly IDbSet<Role> _roles; public EfRolesService(IUnitOfWork uow) { _uow = uow; _roles = _uow.Set<Role>(); } public IList<Role> FindUserRoles(int userId) { var query = from role in _roles from user in role.Users where user.Id == userId select role; return query.OrderBy(x => x.Name).ToList(); } public string[] GetRolesForUser(int userId) { var roles = FindUserRoles(userId); if (roles == null || !roles.Any()) { return new string[] { }; } return roles.Select(x => x.Name).ToArray(); } public bool IsUserInRole(int userId, string roleName) { var query = from role in _roles where role.Name == roleName from user in role.Users where user.Id == userId select role; var userRole = query.FirstOrDefault(); return userRole != null; } }
public class CustomRoleProvider : RoleProvider { public override bool IsUserInRole(string username, string roleName) { // Since the role provider, in this case the CustomRoleProvider is instantiated by // the ASP.NET framework the best solution is to use the service locator pattern. // The service locator pattern is normally considered to be an anti-pattern but // sometimes you have to be pragmatic and accept the limitation on the framework // that is being used (in this case the ASP.NET framework). var rolesService = ObjectFactory.GetInstance<IRolesService>(); return rolesService.IsUserInRole(username.ToInt(), roleName); } public override string[] GetRolesForUser(string username) { var rolesService = ObjectFactory.GetInstance<IRolesService>(); return rolesService.GetRolesForUser(username.ToInt()); } // مابقی نیازی نیست پیاده سازی شوند