Esempio n. 1
0
 /// <summary>
 /// Create role
 /// </summary>
 /// <param name="myRole">the role to add</param>
 public void CreateRole(string myRole)
 {
     if (!MyRoleManager.RoleExists(myRole))
     {
         MyRoleManager.Create(new IdentityRole(myRole));
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Create roles
 /// </summary>
 /// <param name="roleName">a string represetning the name of the role to be created</param>
 public void createRole(string roleName)
 {
     //check if the role exists
     if (!MyRoleManager.RoleExists(roleName))
     {
         //create role
         CreateRole(roleName);
     }
 }
Esempio n. 3
0
        public ActionResult AdminReport(ReportDto search)
        {
            if (!MyRoleManager.hasRole(MyRoleManager.RoleType.SYSTEMADMIN) && !MyRoleManager.hasRole(MyRoleManager.RoleType.DCEADMIN))
            {
                return(RedirectToAction("Index"));
            }

            search = AdminSearch(search);

            ViewBag.CompaniesList = GetCompanyList.GetCompany();

            return(View(search));
        }
Esempio n. 4
0
 public KontaktController(
     UserManager <ApplicationUser> userManager,
     SignInManager <ApplicationUser> signInManager,
     ILogger <AccountController> logger,
     RoleManager <IdentityRole> roleMgr,
     UserManager <ApplicationUser> userMrg,
     MojDbContext context
     )
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _logger        = logger;
     _roleManager   = new MyRoleManager(roleMgr, userMrg);
     ctx            = context;
 }
Esempio n. 5
0
 /// <summary>
 /// Create roles
 /// </summary>
 /// <param name="roleName">a string represetning the name of the role to be created</param>
 public void removeRole(string roleName)
 {
     //check if the role exists
     if (MyRoleManager.RoleExists(roleName))
     {
         var role = m_idbctx.Roles.Where(r => r.Name == roleName).FirstOrDefault();
         m_idbctx.Roles.Remove(role);
         m_idbctx.SaveChanges();
     }
     else
     {
         HttpContext.Current.Session["Error"] = roleName + " does not exist";
         HttpContext.Current.Response.Redirect("~/UserPages/ErrorPage.aspx");
     }
 }
Esempio n. 6
0
        protected override void Seed(ExtJS_Store.DAL.ApplicationContext context)
        {
            var userManager = new MyUserManager(new UserStore <User>(context));
            var roleManager = new MyRoleManager(new RoleStore <MyRole>(context));

            // создаем две роли
            var role1 = new MyRole {
                Name = "admin"
            };
            var role2 = new MyRole {
                Name = "user"
            };

            // добавляем роли в бд
            roleManager.Create(role1);
            roleManager.Create(role2);

            // создаем пользователей
            var user = new User {
                Email = "*****@*****.**", UserName = "******"
            };
            string password = "******";
            var    result   = userManager.Create(user, password);

            // если создание пользователя прошло успешно
            if (result.Succeeded)
            {
                // добавляем для пользователя роли
                userManager.AddToRole(user.Id, role1.Name);
                userManager.AddToRole(user.Id, role2.Name);
            }

            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
        }
Esempio n. 7
0
        // GET: System
        public ActionResult Role()
        {
            AccessAuthoritiesDto dto = new AccessAuthoritiesDto();

            dto.AccessPaths = db.AccessPaths.ToList();
            dto.AccessRoles = db.AccessRoles.ToList();
            if (MyRoleManager.hasRole(MyRoleManager.RoleType.DCEADMIN))
            {
                dto.UserRole = db.UserRoles.OrderBy(ur => ur.username).Where(ur => ur.roletype != MyRoleManager.RoleType.SYSTEMADMIN).ToList();
            }
            else
            {
                dto.UserRole = db.UserRoles.OrderBy(ur => ur.username).ThenBy(ur => ur.roletype).ToList();
            }

            ViewBag.CompaniesList = GetCompanyList.GetCompany();

            return(View(dto));
        }
Esempio n. 8
0
        public static void InitWebConfig(System.Configuration.Configuration conf, bool useAcessProviders, string connectionStringName)
        {
            SystemWebSectionGroup websec = conf.GetSectionGroup("system.web") as SystemWebSectionGroup;

            websec.Authentication.Mode = AuthenticationMode.Forms;
            //if (useAcessProviders)
            //{
            //	AccessMembershipProvider.SetPrividerSettings(websec.Membership, connectionStringName);
            //	AccessRoleProvider.SetRoleSettings(websec.RoleManager, connectionStringName);
            //}
            //else
            //{
            UniMembershipProvider.SetPrividerSettings(websec.Membership, connectionStringName);
            MyRoleManager.SetRoleSettings(websec.RoleManager, connectionStringName);
            //}
            CreateHttpHandler(websec);
            InitConfigSections(ref conf);
            InitJcoSecuritySection(conf);
            conf.Save();
        }
Esempio n. 9
0
        protected override void Seed(Infrastructure.DbContext.MyIdentityDbContext context)
        {
            MyUserManager userManager = new MyUserManager(new UserStore <MyUser>(context));
            MyRoleManager roleManager = new MyRoleManager(new RoleStore <MyRole>(context));

            string roleName = "Administrator";
            string userName = "******";
            string password = "******";
            string email    = "*****@*****.**";

            if (!roleManager.RoleExists(roleName))
            {
                roleManager.Create(new MyRole(roleName));
            }

            MyUser user = userManager.FindByName(userName);

            if (user == null)
            {
                userManager.Create(new MyUser {
                    UserName = userName, Email = email
                },
                                   password);
                user = userManager.FindByName(userName);
            }

            if (!userManager.IsInRole(user.Id, roleName))
            {
                userManager.AddToRole(user.Id, roleName);
            }
            foreach (MyUser dbUser in userManager.Users)
            {
                if (dbUser.Country == Countries.None)
                {
                    dbUser.SetCountryFromCity(dbUser.City);
                }
            }
            context.SaveChanges();
        }
Esempio n. 10
0
        protected override void Seed(ExtStore2.DAL.ApplicationContext context)
        {
            var userManager = new MyUserManager(new UserStore <User>(context));
            var roleManager = new MyRoleManager(new RoleStore <MyRole>(context));

            // создаем две роли
            var role1 = new MyRole {
                Name = "admin"
            };
            var role2 = new MyRole {
                Name = "user"
            };

            // добавляем роли в бд
            roleManager.Create(role1);
            roleManager.Create(role2);

            // создаем пользователей
            var user = new User
            {
                Email    = "*****@*****.**",
                UserName = "******",
                Name     = "Admin",
                Address  = "My address",
                Code     = "My code",
                Discount = 50
            };
            string password = "******";
            var    result   = userManager.Create(user, password);

            // если создание пользователя прошло успешно
            if (result.Succeeded)
            {
                // добавляем для пользователя роли
                userManager.AddToRole(user.Id, role1.Name);
                userManager.AddToRole(user.Id, role2.Name);
            }

            var products = new List <Product>
            {
                new Product {
                    Name = "Продукт 1", Price = 100, Category = "Category", Code = "Code 1"
                },
                new Product {
                    Name = "Продукт 2", Price = 500, Category = "Category", Code = "Code 2"
                },
                new Product {
                    Name = "Новый продукт 3", Price = 8350, Category = "New category", Code = "New code 1"
                },
                new Product {
                    Name = "Новый продукт 4", Price = 15613, Category = "New category", Code = "New code 2"
                }
            };

            for (int i = 1; i <= 50; i++)
            {
                products.Add(new Product {
                    Name = "Product " + i, Price = i * 1000 + i * 3, Category = "Category " + i, Code = "Code " + i
                });
            }
            ;

            products.ForEach(s => context.Products.AddOrUpdate(p => p.Name, s));
            context.SaveChanges();
        }
Esempio n. 11
0
        protected override void Seed(Hotel.Data.HotelDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.
            if (!context.Roles.Any(r => r.Name == "Admin"))
            {
                var roleManager = new MyRoleManager(new MyRoleStore(context));
                var adminRole   = new IdentityRole("Admin");
                roleManager.Create(adminRole);
            }
            if (!context.Users.Any(u => u.Email == "*****@*****.**"))
            {
                var manager = new UserManager <Employee>(new UserStore <Employee>(context));
                var user    = new Employee()
                {
                    UserName  = "******",
                    Email     = "*****@*****.**",
                    FirstName = "Test",
                    LastName  = "Test"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, "Admin");
            }
            RoomType basic = new RoomType {
                Id          = 1, Title = "Basic", BasicRate = 10, LivingRoomsCount = 1, ImageUrl = "basic.jpg",
                Description = "Basic setup for comfortable living with all needed features."
            };
            RoomType normal = new RoomType {
                Id          = 2, Title = "Normal", BasicRate = 15, LivingRoomsCount = 2, ImageUrl = "normal.jpg",
                Description = "Extend format for comfortable living with one additional room."
            };
            RoomType business = new RoomType {
                Id          = 3, Title = "Business", BasicRate = 20, LivingRoomsCount = 3, ImageUrl = "business.jpg",
                Description = "Basic setup for comfortable living with all needed features."
            };
            RoomType luxury = new RoomType {
                Id          = 4, Title = "Luxury", BasicRate = 35, LivingRoomsCount = 5, ImageUrl = "luxury.jpg",
                Description = "The best apartments with perfecrt view of the city for our best guests."
            };

            context.RoomTypes.AddOrUpdate(basic);
            context.RoomTypes.AddOrUpdate(normal);
            context.RoomTypes.AddOrUpdate(business);
            context.RoomTypes.AddOrUpdate(luxury);

            RoomFeature condition = new RoomFeature {
                Id = 1, Title = "Air condition", Description = "High quility air condition", AdditionalCost = 2
            };
            RoomFeature miniBar = new RoomFeature {
                Id = 2, Title = "Minibar", Description = "Unlimited minibar", AdditionalCost = 3
            };

            context.RoomFeatures.AddOrUpdate(condition);
            context.RoomFeatures.AddOrUpdate(miniBar);

            Room basicRoom = new Room {
                Id = 1, Floor = 2, MaxVisitorsCount = 1, Type = basic, Title = "Basic room", ImageUrl = "basic.jpg"
            };
            Room normalRoom = new Room {
                Id       = 2, Floor = 2, MaxVisitorsCount = 2, Type = normal, Title = "Normal room", ImageUrl = "normal.jpg",
                Features = new System.Collections.Generic.List <RoomFeature> {
                    condition
                }
            };
            Room businessRoom = new Room {
                Id       = 3, Floor = 5, MaxVisitorsCount = 2, Type = business, Title = "Business room", ImageUrl = "business.jpg",
                Features = new System.Collections.Generic.List <RoomFeature> {
                    condition, miniBar
                }
            };

            context.Rooms.AddOrUpdate(basicRoom);
            context.Rooms.AddOrUpdate(normalRoom);
            context.Rooms.AddOrUpdate(businessRoom);
        }
Esempio n. 12
0
 public RoleController()
 {
     _userManager = HttpContext.Current.GetOwinContext().Get <MyUserManager>();
     _roleManager = HttpContext.Current.GetOwinContext().Get <MyRoleManager>();
 }
Esempio n. 13
0
        // GET: Approvals
        public ActionResult History(ApprovalSearch search)
        {
            string currentuser = !string.IsNullOrEmpty(User?.Identity?.Name) ? User.Identity.Name.ToUpper() : "Anonymous";

            currentuser = currentuser.Substring(currentuser.IndexOf('\\') + 1).Replace("\\", "").ToUpper();



            ApprovalIndexDto       dto  = new ApprovalIndexDto();
            IEnumerable <Approval> list = db.Approvals.Where(a => 1 == 1);

            if (search.sp != null)
            {
                list = list.Where(p => p.privacy.IND_SP.Contains(search.sp));
            }
            if (search.hospital != null)
            {
                list = list.Where(p => p.privacy.WKP_NAME.Contains(search.hospital));
            }

            if (!MyRoleManager.hasRole(MyRoleManager.RoleType.SYSTEMADMIN) && !MyRoleManager.hasRole(MyRoleManager.RoleType.DCEADMIN))
            {
                list = list.Where(p => p.creater.Equals(currentuser));
            }
            else if (search.owner != null)
            {
                list = list.Where(p => p.creater.Equals(search.owner));
            }

            if (search.status != null && !search.status.Equals("total"))
            {
                if (search.status.Equals("approved"))
                {
                    list = list.Where(p => p.status.Equals(ApprovalStatus.Approved));
                }
                else if (search.status.Equals("rejected"))
                {
                    list = list.Where(p => p.status.Equals(ApprovalStatus.Rejected));
                }
                else if (search.status.Equals("request"))
                {
                    list = list.Where(p => p.status.Equals(ApprovalStatus.Request));
                }
            }
            else
            {
                list = list.Where(p => p.status != ApprovalStatus.Request);
            }
            if (search.requestbegindt != null)
            {
                list = list.Where(a => a.createdate >= search.requestbegindt);
            }
            if (search.requestenddt != null)
            {
                list = list.Where(a => a.createdate <= search.requestenddt);
            }

            if (search.approvalbegindt != null)
            {
                list = list.Where(a => a.modifieddate >= search.approvalbegindt);
            }
            if (search.approvalenddt != null)
            {
                list = list.Where(a => a.modifieddate <= search.approvalenddt);
            }

            if (!string.IsNullOrEmpty(search.owner))
            {
                list = list.Where(a => a.creater.Contains(search.owner));
            }
            if (!string.IsNullOrEmpty(search.name))
            {
                list = list.Where(a => a.privacy.IND_FULL_NAME.Contains(search.name));
            }

            dto.Approvals = list.ToList();
            dto.Search    = search;

            ViewBag.CompaniesList = GetCompanyList.GetCompany();

            return(View(dto));
        }
Esempio n. 14
0
 public AccountController()
 {
     _userManager = HttpContext.Current.GetOwinContext().Get <MyUserManager>();
     _roleManager = HttpContext.Current.GetOwinContext().Get <MyRoleManager>();
     _db          = new OwinApiContext();
 }
        // GET: Dashboard
        public ActionResult Dashboard(string pcmsid = null)
        {
            string currentuser = !string.IsNullOrEmpty(User?.Identity?.Name) ? User.Identity.Name.ToUpper() : "Anonymous";

            currentuser = currentuser.Substring(currentuser.IndexOf('\\') + 1).Replace("\\", "").ToUpper();

            DashboardDto dto = new DashboardDto();

            if (!MyRoleManager.hasRole(MyRoleManager.RoleType.SYSTEMADMIN) && !MyRoleManager.hasRole(MyRoleManager.RoleType.MARKETING) && !MyRoleManager.hasRole(MyRoleManager.RoleType.DCEADMIN) && !MyRoleManager.hasRole(MyRoleManager.RoleType.BUMCM))
            {
                dto.approvalrequests = db.Approvals.Where(a => a.status == ApprovalStatus.Request && a.creater == currentuser).ToList().Count();
                dto.rejectedrequests = db.Approvals.Where(a => a.status == ApprovalStatus.Rejected && a.creater == currentuser).ToList().Count();

                if (pcmsid == null)
                {
                    dto.logs = db.Privacylogs.Where(p => p.creater == currentuser).OrderByDescending(p => p.createdate).Take(300).ToList();
                }
                else
                {
                    dto.logs = db.Privacylogs.Where(p => p.creater == currentuser && p.privacy.PCMSID.Contains(pcmsid)).OrderByDescending(p => p.createdate).Take(300).ToList();
                }
            }
            else if (MyRoleManager.hasRole(MyRoleManager.RoleType.DCEADMIN))
            {
                var query = from u in db.UserRoles
                            join c in db.Companies on u.COMP_CODE equals c.COMP_CODE
                            select c.DCE_TSA;

                foreach (var q in query)
                {
                    if (q == "Y")
                    {
                        dto.approvedrequests = db.Approvals.Where(a => a.status == ApprovalStatus.Approved).ToList().Count();
                        dto.rejectedrequests = db.Approvals.Where(a => a.status == ApprovalStatus.Rejected).ToList().Count();
                        dto.approvalrequests = db.Approvals.Where(a => a.status == ApprovalStatus.Request).ToList().Count();


                        dto.mmscount = db.Consents.Where(c => c.CONSENT_SOURCE == @"MMS").Count();
                        //dto.pforcerxcount = db.Privacylogs.Where(pl => pl.creater == @"PFORCERX").Count();
                        dto.pforcerxcount = db.Consents.Where(c => c.CONSENT_SOURCE == @"PFORCERX").Count();

                        dto.hardcount = db.Consents.Where(c => c.CONSENT_SOURCE != @"MMS" && c.CONSENT_SOURCE != @"GRV" && c.CONSENT_SOURCE != @"PFORCERX").Select(c => c.privacy).Distinct().Count();

                        dto.grvcount = db.Consents.Where(c => c.CONSENT_SOURCE == @"GRV").Count();

                        if (pcmsid == null)
                        {
                            dto.logs = db.Privacylogs.OrderByDescending(p => p.createdate).Take(300).ToList();
                        }
                        else
                        {
                            dto.logs = db.Privacylogs.Where(p => p.privacy.PCMSID.Contains(pcmsid)).OrderByDescending(p => p.createdate).Take(300).ToList();
                        }
                    }
                }
            }
            else
            {
                dto.approvedrequests = db.Approvals.Where(a => a.status == ApprovalStatus.Approved).ToList().Count();
                dto.rejectedrequests = db.Approvals.Where(a => a.status == ApprovalStatus.Rejected).ToList().Count();
                dto.approvalrequests = db.Approvals.Where(a => a.status == ApprovalStatus.Request).ToList().Count();

                // 만료 갯수

                /*
                 * Setting setting = db.Settings.Where(s => s.type == SettingType.ConsentTerm).First();
                 * DateTime expired = DateTime.UtcNow.AddYears(-1 * Int32.Parse(setting.value));
                 * IQueryable<Privacy> privacys = db.Consents.Where(cst => cst.CONSENT_DATE < expired).Select(cst => cst.privacy).Distinct();
                 * privacys = privacys.Where(p => p.status != PrivacyStatus.DELETED || p.status != PrivacyStatus.DELETED);
                 * var count = privacys.Count();
                 *
                 * // String sqlQuery = "select count(*) from Privacies where id in (select privacy_ID from Consents where CONSENT_DATE < DATEADD(year ," + -1 * Int32.Parse(setting.value) + ", CURRENT_TIMESTAMP));";
                 * // var count = db.Database.SqlQuery(sqlQuery);
                 *
                 * dto.expiredconsents = (int)count;
                 */
                // dto.mmscount = db.Privacylogs.Where(pl => pl.creater == @"MMS").Count();
                dto.mmscount = db.Consents.Where(c => c.CONSENT_SOURCE == @"MMS").Count();
                //dto.pforcerxcount = db.Privacylogs.Where(pl => pl.creater == @"PFORCERX").Count();
                dto.pforcerxcount = db.Consents.Where(c => c.CONSENT_SOURCE == @"PFORCERX").Count();

                dto.hardcount = db.Consents.Where(c => c.CONSENT_SOURCE != @"MMS" && c.CONSENT_SOURCE != @"GRV" && c.CONSENT_SOURCE != @"PFORCERX").Select(c => c.privacy).Distinct().Count();

                //dto.codemappingcount = db.Privacylogs.Where(pl => pl.creater == @"ODSM").Count();
                //dto.codemappingcount += db.Privacylogs.Where(pl => pl.creater == @"TASK" && (pl.changes.Contains(@"NucleusKey") || pl.changes.Contains(@"OneKey"))).Count();

                dto.grvcount = db.Consents.Where(c => c.CONSENT_SOURCE == @"GRV").Count();

                if (pcmsid == null)
                {
                    dto.logs = db.Privacylogs.OrderByDescending(p => p.createdate).Take(300).ToList();
                }
                else
                {
                    dto.logs = db.Privacylogs.Where(p => p.privacy.PCMSID.Contains(pcmsid)).OrderByDescending(p => p.createdate).Take(300).ToList();
                }
            }
            ViewBag.pcmsid = pcmsid;
            return(View(dto));
        }