public ICollection<Group> getGroupTypesOfClient(int GroupTypeId)
        {
            List<Group> groupsCollection = new List<Group>();
            var context = new ubietydbEntities();
            context.Configuration.ProxyCreationEnabled = false;

            groupsCollection = context.Groups.Where(b => b.GroupTypeId == GroupTypeId).ToList();

            return groupsCollection;
        }
Esempio n. 2
0
        void b_Click(object sender, EventArgs e)
        {
            var userStore = new UserStore<IdentityUser>();

            TextBox tbUserName = (TextBox)form1.FindControl("username");
            TextBox tbPassword = (TextBox)form1.FindControl("password");

            string userName = tbUserName.Text;
            string password = tbPassword.Text;

            var userManager = new UserManager<IdentityUser>(userStore);

            IdentityUser user = null;

            Regex rgx = new Regex(@"^\d{10}$"); //10 digit mobile number

            if (rgx.IsMatch(userName))
            {
                using (ubietydbEntities db = new ubietydbEntities())
                {
                    string authUserId;
                    Employee emp = (from recordset in db.Employees where recordset.PrimaryMobile.ToString() == userName select recordset).FirstOrDefault();
                    if (emp != null) {
                        authUserId = emp.AuthUserId;
                        user = userManager.FindById(authUserId);
                    }
                }
            }
            else
            {
                user = userManager.Find(userName, password);
            }

            if (user != null)
            {
                var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
                var userIdentity = userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);

                authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, userIdentity);

                Response.Redirect("~/loggingin.aspx");
            }
            else
            {
                Response.Redirect("~/Login.aspx?credentials=wrong");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            String str = System.Web.HttpContext.Current.User.Identity.GetUserId();
            using (var context = new ubietydbEntities())
            {
                var employee = context.Employees
                   .Where(b => b.AuthUserId.Equals(str))
                   .FirstOrDefault();

                Session["EmpId"] = employee.EmpId;
                Session["loggedinuserName"] = employee.EmpName;
                Session["Designation"] = employee.Designation;
                Session["EmpNum"] = employee.EmpNum;

                if (System.Web.HttpContext.Current.User.IsInRole("OrgEmployee"))
                {
                    Response.Redirect("~/Org/showclients.aspx");
                }
                else if (System.Web.HttpContext.Current.User.IsInRole("ClientAdmin"))
                {
                    Session["EmpId"] = employee.EmpId;

                    Session["ClientId"] = employee.CompanyId;
                    Session["SelectClientId"] = employee.CompanyId;

                    Client client = context.Clients.Find(employee.CompanyId);
                    Session["ClientName"] = client.ClientName;

                    Response.Redirect("~/GroupManagement.aspx");
                }
                else if (System.Web.HttpContext.Current.User.IsInRole("ClientManager") || System.Web.HttpContext.Current.User.IsInRole("SecondLevelManager"))
                {
                    Session["ClientId"] = employee.CompanyId;
                    Session["SelectClientId"] = employee.CompanyId;

                    Client client = context.Clients.Find(employee.CompanyId);
                    Session["ClientName"] = client.ClientName;

                    //var emp = context.getEmpsofManager(employee.EmpId);

                    Response.Redirect("~/Client/main.aspx");
                }
                else if (System.Web.HttpContext.Current.User.IsInRole("ClientEmployee"))
                {
                    Session["ClientId"] = employee.CompanyId;
                    Session["SelectClientId"] = employee.CompanyId;

                    Client client = context.Clients.Find(employee.CompanyId);
                    Session["ClientName"] = client.ClientName;

                    Response.Redirect("~/Employees/home.aspx");
                }
                else if (System.Web.HttpContext.Current.User.IsInRole("SuperAdmin"))
                {
                    Response.Redirect("~/Dashboard.aspx");
                }
                else if (System.Web.HttpContext.Current.User.IsInRole("OrgManager"))
                {
                    Session["SelectClientId"] = employee.CompanyId;
                    Response.Redirect("~/org/JobDescription.aspx");
                }
                else if (System.Web.HttpContext.Current.User.IsInRole("OrgEmployee"))
                {
                    Session["SelectClientId"] = employee.CompanyId;
                    Response.Redirect("~/org/Home.aspx");
                }

                //
                //
            }
        }