コード例 #1
0
ファイル: Util.cs プロジェクト: EagleLizard/WackyWidget
 public static bool CanHire(EmpRole bossRole, EmpRole hireRole)
 {
     //presidents can never be hired
       if(hireRole == EmpRole.President){
     return false;
       }
       switch(bossRole){
     case EmpRole.President:
       return true;
     case EmpRole.VicePresident:
       if(hireRole == EmpRole.Supervisor || hireRole == EmpRole.Worker){
     return true;
       }
       break;
     case EmpRole.Supervisor:
       if(hireRole == EmpRole.Worker){
     return true;
       }
       break;
     case EmpRole.Worker:
     default:
       break;
       }
       return false;
 }
コード例 #2
0
 public void InitData()
 {
     ReBuildDatabase();
     u1 = new EmpUser()
     {
         Name = "User1"
     };
     u2 = new EmpUser()
     {
         Name = "User2"
     };
     r1 = new EmpRole()
     {
         Name = "Select"
     };
     r2 = new EmpRole()
     {
         Name = "Edit"
     };
     u1.Roles = new List <EmpRole>()
     {
         r1, r2
     };
     u2.Roles = new List <EmpRole>()
     {
         r1
     };
     Session.Save(u1);
     Session.Save(u2);
     Session.Save(r1);
     Session.Save(r2);
     Session.Flush();
 }
コード例 #3
0
        public ActionResult Delete(int?id)
        {
            EmpRole empRole = db.EmpRoles.Find(id);

            db.EmpRoles.Remove(empRole);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #4
0
        public EmpRole GetEmployeeRoleByRoleCode(string roleCode)
        {
            var empRole       = _da.GetRoleByRoleCode(roleCode);
            var empRoleEntity = new EmpRole();

            empRoleEntity.RoleCode = empRole.RoleCode;
            empRoleEntity.RoleName = empRole.RoleName;
            return(empRoleEntity);
        }
コード例 #5
0
        public void TestAddOneSide()
        {
            var r3 = new EmpRole()
            {
                Name = "Delete"
            };

            u1.Roles.Add(r3);
            Session.SaveOrUpdate(u1);
            Session.Flush();
        }
コード例 #6
0
ファイル: Util.cs プロジェクト: EagleLizard/WackyWidget
 //gets the value of the most direct subordinate.
 // Returns null if emprole is worker
 public static EmpRole DirectSubordinate(EmpRole bossRole)
 {
     switch(bossRole){
     case EmpRole.President:
       return EmpRole.VicePresident;
     case EmpRole.VicePresident:
       return EmpRole.Supervisor;
     case EmpRole.Supervisor:
       return EmpRole.Worker;
     case EmpRole.Worker:
     default:
       break;
       }
       return EmpRole.Invalid;
 }
コード例 #7
0
 public ActionResult Create(EmpRoleViewModel empRoleViewModel)
 {
     if (ModelState.IsValid)
     {
         EmpRole empRole = new EmpRole();
         empRole.RoleID      = empRoleViewModel.RoleID;
         empRole.EmpID       = empRoleViewModel.EmpID;
         empRole.IsActive    = empRoleViewModel.IsActive;
         empRole.CreatedDate = DateTime.Now;
         db.EmpRoles.Add(empRole);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(empRoleViewModel));
 }
コード例 #8
0
 public ActionResult Edit(EmpRoleViewModel empRoleViewModel)
 {
     if (ModelState.IsValid)
     {
         EmpRole empRole = db.EmpRoles.Find(empRoleViewModel.EmpRolesID);
         empRole.RoleID          = empRoleViewModel.RoleID;
         empRole.EmpID           = empRoleViewModel.EmpID;
         empRole.IsActive        = empRoleViewModel.IsActive;
         empRole.CreatedDate     = DateTime.Now;
         db.Entry(empRole).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(empRoleViewModel));
 }
コード例 #9
0
ファイル: Org.cs プロジェクト: EagleLizard/WackyWidget
 public static List<Employee> AllPositionsAtHelper(Employee currentEmployee, EmpRole position)
 {
     List<Employee> result = new List<Employee>();
       if(!currentEmployee.HasSubordinates()) return result;
       if(Util.DirectSubordinate(currentEmployee.Position) == position){
     for(int i=0; i<currentEmployee.Subordinates.Count; ++i){
       if(currentEmployee.Subordinates[i].Vacant){
     result.Add(currentEmployee.Subordinates[i]);
       }
     }
       }else{
     for(int i=0; i<currentEmployee.Subordinates.Count; ++i){
       result.AddRange(AllPositionsAtHelper(currentEmployee.Subordinates[i], position));
     }
       }
       return result;
 }
コード例 #10
0
        /// <summary>
        /// 保存该员工的角色信息
        /// </summary>
        /// <param name="Id">要设置角色的员工的ID</param>
        /// <param name="RoleCodes">角色的代码字符串</param>
        /// <returns></returns>
        public JsonResult SaveEmpRole(int[] RoleCodes, int Id)
        {
            EntitySet <EmpRole> empRole = new EntitySet <EmpRole>();

            if (RoleCodes != null)
            {
                foreach (int roleCode in RoleCodes)
                {
                    EmpRole er = new EmpRole();
                    er.RoleId = roleCode;
                    empRole.Add(er);
                }
            }
            Employee emp = db.GetModel(Id);

            db.DeleteAllOnSubmit(emp.EmpRole);
            emp.EmpRole = empRole;
            db.Save(emp);
            return(Json("OK"));
        }
コード例 #11
0
        public ActionResult Edit(int?id)
        {
            EmpRole          empRole          = db.EmpRoles.Find(id);
            EmpRoleViewModel empRoleViewModel = new EmpRoleViewModel();

            empRoleViewModel.EmpRolesID = empRole.EmpRolesID;
            empRoleViewModel.RoleID     = empRole.RoleID;
            empRoleViewModel.EmpID      = empRole.EmpID;
            empRoleViewModel.IsActive   = empRole.IsActive;


            List <Role> rolelist1 = db.Roles.ToList();

            ViewBag.Rolelist = new SelectList(rolelist1, "RoleID", "RoleName", empRole.RoleID);

            List <Employee> employeelist1 = db.Employees.ToList();

            ViewBag.Employeelist = new SelectList(employeelist1, "EmpID", "EmpName", empRole.EmpID);
            return(View(empRoleViewModel));
        }
コード例 #12
0
ファイル: Util.cs プロジェクト: EagleLizard/WackyWidget
 public static Employee VacantEmployee(EmpRole position)
 {
     Employee vacantEmp = EmployeeFromRole(position, "");
       vacantEmp.Vacant = true;
       return vacantEmp;
 }
コード例 #13
0
ファイル: Util.cs プロジェクト: EagleLizard/WackyWidget
 public static string PrefixFromRole(EmpRole role)
 {
     switch(role){
     case EmpRole.President:
       return "P";
     case EmpRole.VicePresident:
       return "V";
     case EmpRole.Supervisor:
       return "S";
     case EmpRole.Worker:
       return "W";
     default:
       throw new OrgException("Invalid prefix");
       }
 }
コード例 #14
0
ファイル: Util.cs プロジェクト: EagleLizard/WackyWidget
 public static string GetRoleString(EmpRole role)
 {
     string result = null;
       switch(role){
     case EmpRole.President:
       result = "President";
       break;
     case EmpRole.Supervisor:
       result = "Supervisor";
       break;
     case EmpRole.VicePresident:
       result = "Vice President";
       break;
     case EmpRole.Worker:
       result = "Worker";
       break;
       }
       return result;
 }
コード例 #15
0
ファイル: Util.cs プロジェクト: EagleLizard/WackyWidget
 public static Employee EmployeeFromRole(EmpRole role, string name)
 {
     return EmployeeFromPrefix(PrefixFromRole(role), name);
 }
コード例 #16
0
        /// <summary>
        /// 添加或修改数据
        /// </summary>
        public ActionResult UpdateData()
        {
            try
            {
                bool     blResult = false;
                int      id       = Request.Form["id"] != "" ? Convert.ToInt32(Request.Form["id"]) : 0;
                Employee model    = GetData(id);

                string writeMsg = "操作失败!";
                if (model != null)
                {
                    if (id < 1)
                    {
                        EnterRepository.GetRepositoryEnter().EmployeeRepository.AddEntity(model);

                        if (EnterRepository.GetRepositoryEnter().SaveChange() > 0)
                        {
                            if (!string.IsNullOrEmpty(model.RoleIDs))
                            {
                                string[] roleIds = model.RoleIDs.Split(',');
                                foreach (var item in roleIds)
                                {
                                    if (item == "")
                                    {
                                        continue;
                                    }
                                    EmpRole empRole = new EmpRole();
                                    empRole.EmpID  = model.ID;
                                    empRole.RoleID = int.Parse(item);
                                    EnterRepository.GetRepositoryEnter().EmpRoleRepository.AddEntity(empRole);
                                }
                                EnterRepository.GetRepositoryEnter().SaveChange();
                            }
                            writeMsg = "增加成功!";
                        }
                        else
                        {
                            writeMsg = "增加失败!";
                        }
                    }
                    else
                    {
                        //清楚context中result对象
                        EnterRepository.GetRepositoryEnter().EmployeeRepository.Get(m => m.ID == id);
                        EnterRepository.GetRepositoryEnter().EmployeeRepository.EditEntity(model, new string[] { "EmpNo", "Pwd", "Name", "Tel" });
                        EnterRepository.GetRepositoryEnter().EmpRoleRepository.DeleteByEmpId(model.ID);

                        if (EnterRepository.GetRepositoryEnter().SaveChange() > 0)
                        {
                            if (!string.IsNullOrEmpty(model.RoleIDs))
                            {
                                string[] roleIds = model.RoleIDs.Split(',');
                                foreach (var item in roleIds)
                                {
                                    if (item == "")
                                    {
                                        continue;
                                    }
                                    EmpRole empRole = new EmpRole();
                                    empRole.EmpID  = model.ID;
                                    empRole.RoleID = int.Parse(item);
                                    EnterRepository.GetRepositoryEnter().EmpRoleRepository.AddEntity(empRole);
                                }
                                EnterRepository.GetRepositoryEnter().SaveChange();
                            }
                            writeMsg = "更新成功!";
                        }
                        else
                        {
                            writeMsg = "更新失败!";
                        }
                    }
                }
                return(Content(writeMsg));
            }
            catch (Exception ex)
            {
                GlobalMethod.log.Error(ex);
                throw;
            }
        }
コード例 #17
0
ファイル: Org.cs プロジェクト: EagleLizard/WackyWidget
 public List<Employee> AllPositionsAt(EmpRole position)
 {
     List<Employee> result = AllPositionsAtHelper(president, position);
       return result;
 }