public ActionResult Add(UserRole userRole)
        {
            StudentManagementDbContext context = new StudentManagementDbContext();

            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));

            try
            {
                var    allRoles  = context.Roles.ToList();
                string rolesName = null;
                if (allRoles != null && allRoles.Count > 0)
                {
                    var item = allRoles.Where(s => s.Id == userRole.RoleId).FirstOrDefault();
                    rolesName = item.Name;
                }

                var result = UserManager.AddToRole(userRole.UserId, rolesName);
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            // Lam sao lu DB
            return(RedirectToAction("Index"));
        }
Example #2
0
 public IActionResult Get(int id)
 {
     using (var context = new StudentManagementDbContext())
     {
         var obj = context.Students.Single(t => t.StudentId == id);
         return(Ok(obj));
     }
 }
Example #3
0
        public void addFees(FeesPaid fee)
        {
            using (var context = new StudentManagementDbContext())
            {
                var s = context.Database.ExecuteSqlCommand("sp_addFees @feeamount,@id",
                                                           new SqlParameter("@feeamount", fee.FeeAmount),
                                                           new SqlParameter("@id", fee.StudentId)

                                                           );
            }
        }
Example #4
0
        public void deleteStudent(int studentid)
        {
            using (var context = new StudentManagementDbContext())
            {
                var s = context.Database.ExecuteSqlCommand("sp_deleteStudent @id",
                                                           new SqlParameter("@id", studentid)



                                                           );
            }
        }
Example #5
0
 public void addStudents(Students student)
 {
     using (var context = new StudentManagementDbContext())
     {
         var s = context.Database.ExecuteSqlCommand("sp_addStudent @name,@email,@mobileno,@courseid,@password",
                                                    new SqlParameter("@name", student.StudentName),
                                                    new SqlParameter("@mobileno", student.MobileNo),
                                                    new SqlParameter("@email", student.Email),
                                                    new SqlParameter("@password", student.Password),
                                                    new SqlParameter("@courseid", student.CourseId)
                                                    );
     }
 }
 public IActionResult Post(Students student)
 {
     using (var context = new StudentManagementDbContext())
     {
         var obj = context.Students.Single(t => t.Email == student.Email && t.Password == student.Password);
         if (obj != null)
         {
             return(Ok(obj.StudentId));
         }
         else
         {
             return(Ok("login failed"));
         }
     }
 }
        // In this method we will create default User roles and Admin user for login
        private void createRolesandUsers()
        {
            StudentManagementDbContext context = new StudentManagementDbContext();

            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));

            // In Startup iam creating first Admin Role and creating a default Admin User
            if (!roleManager.RoleExists("Admin"))
            {
                // first we create Admin rool
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);

                //Here we create a Admin super user who will maintain the website
                var user = new ApplicationUser();
                user.UserName = "******";
                user.Email    = "*****@*****.**";

                string userPWD = "Pass@word1";
                var    chkUser = UserManager.Create(user, userPWD);

                //Add default User to Role Admin
                if (chkUser.Succeeded)
                {
                    var result1 = UserManager.AddToRole(user.Id, "Admin");
                }
            }

            // creating Creating Teacher role
            if (!roleManager.RoleExists("Teacher"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Teacher";
                roleManager.Create(role);
            }

            // creating Creating Employee role
            if (!roleManager.RoleExists("Student"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Student";
                roleManager.Create(role);
            }
        }
        public ActionResult Add()
        {
            // viet hai service call DB
            //1: lay het tat ca user trong he thong

            List <usp_AspNetUser_GetList> userList = new List <usp_AspNetUser_GetList>();
            //using (var service = new AspNetUserService())
            //{
            //    userList = service.GetListUser();
            //}
            //SelectList selectLists = new SelectList(userList, "Id", "UserName");

            var context = new StudentManagementDbContext();

            var allUsers = context.Users.ToList();

            var viewModels = new List <usp_AspNetUser_GetList>();

            foreach (var user in allUsers)
            {
                viewModels.Add(new usp_AspNetUser_GetList {
                    Id = user.Id, UserName = user.UserName
                });
            }
            SelectList selectLists = new SelectList(viewModels, "Id", "UserName");

            ViewBag.userListDb = selectLists;

            //2: lay het tat ca role trong he thong
            var allRoles  = context.Roles.ToList();
            var viewRoles = new List <usp_AspNetUser_GetList>();

            foreach (var role in allRoles)
            {
                viewRoles.Add(new usp_AspNetUser_GetList {
                    Id = role.Id, UserName = role.Name
                });
            }
            SelectList selectRoles = new SelectList(viewRoles, "Id", "UserName");

            ViewBag.listRoles = selectRoles;
            //cuoi cung dung ViewBag.ListUser,ViewBag.ListRole de truyen len view
            return(RedirectToAction("Indexs"));
        }
Example #9
0
 public bool isAdminUser()
 {
     if (User.Identity.IsAuthenticated)
     {
         var user = User.Identity;
         StudentManagementDbContext context = new StudentManagementDbContext();
         var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));
         var s           = UserManager.GetRoles(user.GetUserId());
         if (s[0].ToString() == "Admin")
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
Example #10
0
 public bool isRoleUser(string role)
 {
     if (User.Identity.IsAuthenticated)
     {
         var user = User.Identity;
         StudentManagementDbContext context = new StudentManagementDbContext();
         var  UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));
         var  s           = UserManager.GetRoles(user.GetUserId());
         bool result      = false;
         foreach (var item in s)
         {
             if (item == role)
             {
                 result = true;
             }
         }
         return(result);
     }
     return(false);
 }
 public StudentController(StudentManagementDbContext context)
 {
     _context = context;
 }
Example #12
0
 public GenericService(StudentManagementDbContext db)
 {
     _db    = db;
     _table = _db.Set <T>();
 }
Example #13
0
 public GenericService()
 {
     _db    = new StudentManagementDbContext();
     _table = _db.Set <T>();
 }