示例#1
0
        public bool AddEmployee(Bas_Employee employee, Bas_EmployeeRole bas_EmployeeRole)
        {
            bool result = false;

            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    BeginTran();
                    Bas_Role bas_Role = BllRoleRepository.GetEntityRoleByCode(employee.Bem_Roles);
                    int      value    = BllEmployeeRepository.Add(employee);
                    result = value > 0;
                    if (result)
                    {
                        bas_EmployeeRole.Ber_EmployeeId = value;
                        bas_EmployeeRole.Ber_RoleId     = bas_Role.Bro_Id;
                        result = EmployeeRoleRepository.Add(bas_EmployeeRole) > 0;
                    }
                    if (result)
                    {
                        scope.Complete();
                    }
                    else
                    {
                        RollbackTran();
                    }
                }
                catch (Exception ex)
                {
                    RollbackTran();
                    result = false;
                    throw ex;
                }
            }
            return(result);
        }
示例#2
0
        public bool UpdateEmployee(Bas_Employee employee, Bas_EmployeeRole bas_EmployeeRole)
        {
            bool result = false;

            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    BeginTran();
                    Bas_Role bas_Role = BllRoleRepository.GetEntityRoleByCode(employee.Bem_Roles);
                    result = BllEmployeeRepository.Update(employee);
                    if (result)
                    {
                        Bas_EmployeeRole bas_EmployeeRoleData = EmployeeRoleRepository.GetEmployeeRoleByEmployeeId(employee.Bem_Id);
                        bas_EmployeeRole.ber_Id         = bas_EmployeeRoleData.ber_Id;
                        bas_EmployeeRole.Ber_EmployeeId = employee.Bem_Id;
                        bas_EmployeeRole.Ber_RoleId     = bas_Role.Bro_Id;
                        result = EmployeeRoleRepository.Update(bas_EmployeeRole);
                    }
                    if (result)
                    {
                        scope.Complete();
                    }
                    else
                    {
                        RollbackTran();
                    }
                }
                catch (Exception ex)
                {
                    RollbackTran();
                    result = false;
                }
            }
            return(result);
        }
示例#3
0
        public ActionResult AddOrUpdateEmployee(EmployeeViewModel employeeViewModel)
        {
            bool result = false;
            var  msg    = "";

            try
            {
                #region Bas_Employee
                Bas_Employee bas_Employee = null;
                if (employeeViewModel.Id > 0)
                {
                    bas_Employee = employeeBll.GetEmployeeEntity(employeeViewModel.Id);
                    if (bas_Employee == null)
                    {
                        throw new AbhsException(ErrorCodeEnum.ParameterInvalid, AbhsErrorMsg.ConstParameterInvalid);
                    }
                }
                if (bas_Employee == null)
                {
                    bas_Employee = new Bas_Employee();
                }
                bas_Employee.Bem_Id      = employeeViewModel.Id;
                bas_Employee.Bem_Account = employeeViewModel.Account;
                if (employeeViewModel.Password.HasValue())
                {
                    bas_Employee.Bem_Password = Encrypt.GetMD5Pwd(employeeViewModel.Password);
                }
                bas_Employee.Bem_Name   = employeeViewModel.Name;
                bas_Employee.Bem_Sex    = employeeViewModel.Sex;
                bas_Employee.Bem_Phone  = employeeViewModel.Phone;
                bas_Employee.Bem_Email  = employeeViewModel.Email;
                bas_Employee.Bem_Roles  = employeeViewModel.Roles;
                bas_Employee.Bem_Status = employeeViewModel.Status;
                bas_Employee.Bem_Remark = employeeViewModel.Remark;
                bas_Employee.Bem_Grades = employeeViewModel.Grades.Sum();
                #endregion

                Bas_EmployeeRole bas_EmployeeRole = new Bas_EmployeeRole();
                if (bas_Employee.Bem_Id == 0)
                {
                    bas_Employee.Bem_CreateTime     = DateTime.Now;
                    bas_Employee.Bem_Editor         = CurrentUserID;
                    bas_Employee.Bem_LastLoginTime  = DateTimeExtensions.DefaultDateTime;
                    bas_EmployeeRole.Ber_CreateTime = DateTime.Now;
                    bas_EmployeeRole.Ber_Creator    = CurrentUserID;
                    result = employeeBll.AddEmployee(bas_Employee, bas_EmployeeRole);
                }
                else
                {
                    bas_Employee.Bem_UpdateTime     = DateTime.Now;
                    bas_Employee.Bem_Editor         = CurrentUserID;
                    bas_EmployeeRole.Ber_CreateTime = DateTime.Now;
                    bas_EmployeeRole.Ber_Creator    = CurrentUserID;
                    result = employeeBll.UpdateEmployee(bas_Employee, bas_EmployeeRole);
                }
            }
            catch (Exception ex)
            {
                msg = "异常,请重试";
                //return Json(new JsonSimpleResponse() { State = false, ErrorMsg = ex.Message });
            }
            msg = result ? "操作成功" : "操作失败";
            return(Json(new JsonSimpleResponse()
            {
                State = result, ErrorMsg = msg
            }));
        }