Пример #1
0
        public string GetUserEmailByID(string id)
        {
            var appDbContext = new LeaveManagementDbContext();
            var user         = appDbContext.ApplicationUser.Where(t => t.Id == id).FirstOrDefault();

            return(user.Email);
        }
Пример #2
0
        public List <ApplicationUser> GetUsersByRole(string RoleName)
        {
            var appDbContext            = new LeaveManagementDbContext();
            List <ApplicationUser> user = appDbContext.ApplicationUser.Where(t => t.RoleName == RoleName).ToList();

            return(user);
        }
Пример #3
0
        public ApplicationUser GetUsersByName(string UserName)
        {
            var             appDbContext = new LeaveManagementDbContext();
            ApplicationUser user         = appDbContext.ApplicationUser.Where(t => t.UserName == UserName).FirstOrDefault();

            return(user);
        }
Пример #4
0
        public List <ApplicationUser> ListAllEmployeeProfile()
        {
            var appDbContext             = new LeaveManagementDbContext();
            var userStore                = new ApplicationUserStore(appDbContext);
            var userManager              = new ApplicationUserManager(userStore);
            List <ApplicationUser> Users = appDbContext.ApplicationUser.ToList();

            return(Users);
        }
Пример #5
0
        public ActionResult EditInfo()
        {
            var    appDbContext       = new LeaveManagementDbContext();
            var    userStore          = new ApplicationUserStore(appDbContext);
            var    userManager        = new ApplicationUserManager(userStore);
            string uid                = _employeeService.GetUserID();
            EmployeeInfoViewModel ivm = _employeeService.ViewEmployeeInfo(uid);

            return(View(ivm));
        }
Пример #6
0
        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var appDbContext = new LeaveManagementDbContext();
            var userStore    = new ApplicationUserStore(appDbContext);
            var userManager  = new ApplicationUserManager(userStore);
            var user         = userManager.FindById(filterContext.HttpContext.User.Identity.GetUserId());

            if (filterContext.HttpContext.User.IsInRole("ProjectManager") == false && user.IsSpecialPermission == false)
            {
                filterContext.Result = new RedirectToRouteResult(new
                                                                 RouteValueDictionary(new { controller = "Home", action = "Index" }));
            }
        }
Пример #7
0
        public IdentityResult DeleteEmployeeProfile(string Id)
        {
            var          appDbContext = new LeaveManagementDbContext();
            var          userStore    = new ApplicationUserStore(appDbContext);
            var          userManager  = new ApplicationUserManager(userStore);
            var          user         = userManager.FindById(Id);
            EmployeeInfo ei           = appDbContext.EmployeeInfo.Where(t => t.ApplicationUser.Id == Id).FirstOrDefault();

            appDbContext.EmployeeInfo.Remove(ei);
            //var roleId = userManager.GetRoles(Id).FirstOrDefault();
            //userManager.RemoveFromRole(user.Id,roleId);
            var result = userManager.Delete(user);

            return(result);
        }
Пример #8
0
        public void EmployeeLogin(LoginViewModel lvm)
        {
            var appDbContext = new LeaveManagementDbContext();
            var userStore    = new ApplicationUserStore(appDbContext);
            var userManager  = new ApplicationUserManager(userStore);
            var user         = userManager.Find(userManager.FindByEmail(lvm.Email).UserName, lvm.Password);

            if (user != null)
            {
                //login
                var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
                var userIdentity          = userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
                authenticationManager.SignIn(new AuthenticationProperties(), userIdentity);
            }
        }
Пример #9
0
        public void CreateRolesAndUsers()
        {
            var roleManager  = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new LeaveManagementDbContext()));
            var appDbContext = new LeaveManagementDbContext();
            var appUserStore = new ApplicationUserStore(appDbContext);
            var userManager  = new ApplicationUserManager(appUserStore);


            //Create Admin Role
            if (!roleManager.RoleExists("Employee"))
            {
                var role = new IdentityRole();
                role.Name = "Employee";
                roleManager.Create(role);
            }
        }
Пример #10
0
        public IdentityResult RegisterEmployeeProfile(RegisterViewModel rvm)
        {
            var appDbContext = new LeaveManagementDbContext();
            var userStore    = new ApplicationUserStore(appDbContext);
            var userManager  = new ApplicationUserManager(userStore);
            var passwordHash = Crypto.HashPassword(rvm.Password);
            var user         = new ApplicationUser()
            {
                Email = rvm.Email, UserName = rvm.Name, PasswordHash = passwordHash, PhoneNumber = rvm.Contact, RoleName = rvm.RoleName, IsSpecialPermission = rvm.IsSpecialPermission, EmployeeInfo = new EmployeeInfo()
            };
            var result = userManager.Create(user);

            if (result.Succeeded)
            {
                userManager.AddToRole(user.Id, rvm.RoleName);
            }
            return(result);
        }
Пример #11
0
        public void CreateLeaveType()

        {
            var       appDbContext = new LeaveManagementDbContext();
            LeaveType l            = new LeaveType();

            l = appDbContext.LeaveTypes.Where(t => t.LeaveTypeName == "Loss of Pay").FirstOrDefault();
            if (l == null)
            {
                LeaveType l1 = new LeaveType();
                l1.LeaveTypeName = "Loss of Pay";
                appDbContext.LeaveTypes.Add(l1);
                appDbContext.SaveChanges();
            }
            l = appDbContext.LeaveTypes.Where(t => t.LeaveTypeName == "Compensatory").FirstOrDefault();
            if (l == null)
            {
                LeaveType l1 = new LeaveType();
                l1.LeaveTypeName = "Compensatory";
                appDbContext.LeaveTypes.Add(l1);
                appDbContext.SaveChanges();
            }
        }
Пример #12
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, LeaveManagementDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseCors(MyAllowSpecificOrigins);

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            app.UseOpenApi();
            app.UseSwaggerUi3();

            //Update database on project startup
            context.Database.Migrate();
        }
Пример #13
0
        public void CreateRolesAndUsers()
        {
            var roleManager  = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new LeaveManagementDbContext()));
            var appDbContext = new LeaveManagementDbContext();
            var appUserStore = new ApplicationUserStore(appDbContext);
            var userManager  = new ApplicationUserManager(appUserStore);

            //Create Admin Role
            if (!roleManager.RoleExists("HumanResources"))
            {
                var role = new IdentityRole();
                role.Name = "HumanResources";
                var rolecreate = roleManager.Create(role);
            }

            //Create Admin User
            if (userManager.FindByName("HumanResources") == null)
            {
                var passwordHash = Crypto.HashPassword("humanresources123");
                var user         = new ApplicationUser()
                {
                    Email = "*****@*****.**", UserName = "******", PasswordHash = passwordHash, PhoneNumber = "0000", RoleName = "HumanResources", EmployeeInfo = new EmployeeInfo()
                };
                var chkUser = userManager.Create(user);
                if (chkUser.Succeeded)
                {
                    userManager.AddToRole(user.Id, "HumanResources");
                }
            }

            //Create Manager Role
            if (!roleManager.RoleExists("ProjectManager"))
            {
                var role = new IdentityRole();
                role.Name = "ProjectManager";
                roleManager.Create(role);
            }

            //Create Manager User
            if (userManager.FindByName("ProjectManager") == null)
            {
                var passwordHash = Crypto.HashPassword("projectmanager123");
                var user         = new ApplicationUser()
                {
                    Email = "*****@*****.**", UserName = "******", PasswordHash = passwordHash, PhoneNumber = "0000", RoleName = "ProjectManager", EmployeeInfo = new EmployeeInfo()
                };
                var chkUser = userManager.Create(user);
                if (chkUser.Succeeded)
                {
                    userManager.AddToRole(user.Id, "ProjectManager");
                }
            }

            //Create Customer Role
            if (!roleManager.RoleExists("Employee"))
            {
                var role = new IdentityRole();
                role.Name = "Employee";
                roleManager.Create(role);
            }
        }
 public EmployeeController(LeaveManagementDbContext leaveManagementDbContext)
 {
     _dbContext = leaveManagementDbContext;
     _empRepo   = new EmployeeRepository(_dbContext);
 }
 public LeaveInfoRepository(LeaveManagementDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Пример #16
0
 public ReportingController(LeaveManagementDbContext leaveManagementDbContext)
 {
     _dbContext = leaveManagementDbContext;
     _repRepo   = new ReportingRepository(_dbContext);
 }
 public RemainingHourController(LeaveManagementDbContext leaveManagementDbContext)
 {
     _dbContext = leaveManagementDbContext;
     _remRepo   = new RemainingHourRepository(_dbContext);
 }
Пример #18
0
 public RemainingHourRepository(LeaveManagementDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Пример #19
0
 public HRService(IEmployeeService employeeService, LeaveManagementDbContext db)
 {
     _employeeService = employeeService;
     _db = db;
 }
Пример #20
0
 public Repository(LeaveManagementDbContext context)
 {
     this._context = context;
 }
 public EmployeeRepository()
 {
     db          = new LeaveManagementDbContext();
     userStore   = new ApplicationUserStore(db);
     userManager = new ApplicationUserManager(userStore);
 }
Пример #22
0
 public LeavesController(LeaveManagementDbContext leaveInfo)
 {
     _dbContext = leaveInfo;
     _leaveRepo = new LeaveInfoRepository(_dbContext);
 }
 public EmployeeRepository(LeaveManagementDbContext dbContext)
 {
     _dbContext = dbContext;
 }