예제 #1
0
        public ActionResult ManageEmployees()
        {
            List <FullEmployeeDetail> employeeList = new List <FullEmployeeDetail>();

            using (EmployeeDetailsDBService db = new EmployeeDetailsDBService(empCode))
            {
                ViewBag.employeeList = db.AllEmployeeDetails();
            }
            return(View());
        }
예제 #2
0
 public ActionResult CreateUser()
 {
     using (BTCEntities db = new BTCEntities())
     {
         List <Roles> allRoles = db.Roles.ToList();
         List <FullEmployeeDetail> allEmployees = new List <FullEmployeeDetail>();
         using (EmployeeDetailsDBService employeeDetailsDBService = new EmployeeDetailsDBService(empCode))
         {
             allEmployees = employeeDetailsDBService.AllEmployeeDetails();
         }
         ViewBag.allRoles     = allRoles;
         ViewBag.allEmployees = allEmployees;
         CheckErrorMessages();
         return(View());
     }
 }
예제 #3
0
        public ActionResult AdminDashboard()
        {
            List <Users> usersList = new List <Users>();

            using (BTCEntities db = new BTCEntities())
            {
                ViewBag.usersList = db.Users.Include(a => a.Roles).Include(a => a.HRW_Employee).ToList();
            }
            List <FullEmployeeDetail> employeeList = new List <FullEmployeeDetail>();

            using (EmployeeDetailsDBService db = new EmployeeDetailsDBService(empCode))
            {
                ViewBag.employeeList = db.AllEmployeeDetails(50);
            }
            return(View());
        }
예제 #4
0
        public ActionResult CreateUser([Bind(Include = "ID,Username,FirstName,LastName,Email,Password,IsActive,ActivationCode")] Users userObj, FormCollection form)
        {
            try
            {
                bool   statusRegistration  = false;
                string messageRegistration = string.Empty;
                int    empValue            = Convert.ToInt32(form["EmployeeID"].ToString());
                userObj.HREmployeeID = empValue;

                int DDLValue = Convert.ToInt32(form["RoleID"].ToString());

                string userName = Membership.GetUserNameByEmail(userObj.Email);
                if (!string.IsNullOrEmpty(userName))
                {
                    ModelState.AddModelError("Warning Email", "Sorry: Email already Exists");
                    var           errlist = ModelState.Values.Where(e => e.Errors.Count > 0).Select(a => a.Errors);
                    List <string> sberr   = new List <string>();
                    foreach (var item in errlist)
                    {
                        sberr.Add(item[0].ErrorMessage);
                    }
                    TempData["ErrorMessage"] = sberr.ToList();
                    CheckErrorMessages();
                    return(RedirectToAction("CreateUser", userObj));
                }

                using (BTCEntities db = new BTCEntities())
                {
                    List <Roles> allRoles = db.Roles.ToList();
                    List <FullEmployeeDetail> allEmployees = new List <FullEmployeeDetail>();
                    using (EmployeeDetailsDBService employeeDetailsDBService = new EmployeeDetailsDBService(empCode))
                    {
                        allEmployees = employeeDetailsDBService.AllEmployeeDetails();
                    }
                    ViewBag.allRoles     = allRoles;
                    ViewBag.allEmployees = allEmployees;

                    var role = db.Roles.Where(a => a.ID == DDLValue).FirstOrDefault();
                    var user = new Users()
                    {
                        Username       = userObj.Username,
                        FirstName      = userObj.FirstName,
                        LastName       = userObj.LastName,
                        Email          = userObj.Email,
                        Password       = userObj.Password,
                        HREmployeeID   = userObj.HREmployeeID,
                        ActivationCode = Guid.NewGuid(),
                    };

                    user.Roles.Add(role);
                    db.Users.Add(user);

                    db.SaveChanges();
                }

                //VerificationEmail(userObj.Email, userObj.ActivationCode.ToString());
                messageRegistration = "Your account has been created successfully. ^_^";
                statusRegistration  = true;

                ViewBag.Message = messageRegistration;
                ViewBag.Status  = statusRegistration;

                return(RedirectToAction("ManageUsers"));
            }
            catch (Exception)
            {
                return(View("CreateUser", userObj));
            }
        }