Beispiel #1
0
        public ResultModel CreateHandler(UserModel user, Model.Employee emp, Model.Account acc)
        {
            ResultModel result = new ResultModel();
            DAL.AccountDAL accountDAL = new AccountDAL();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = accountDAL.ValidateAccountName(user, acc.AccountName);
                    if (result.ResultStatus != 0)
                        return result;

                    result = employeeDAL.Insert(user, emp);
                    if (result.ResultStatus != 0)
                        return result;

                    int empId = (int)result.ReturnValue;

                    acc.EmpId = empId;
                    acc.IsValid = true;
                    acc.AccStatus = StatusEnum.已生效;

                    result = accountDAL.Insert(user, acc);
                    if (result.ResultStatus != 0)
                        return result;

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    this.Log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (this.Log.IsInfoEnabled)
                    this.Log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }
Beispiel #2
0
        public override ResultModel Update(UserModel user, IModel obj)
        {
            ResultModel result = new ResultModel();

            try
            {
                Model.Employee obj1 = (Model.Employee)obj;

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = this.Get(user, obj.Id);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.Employee resultObj = (Model.Employee)result.ReturnValue;

                    if (resultObj == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "该数据不存在,不能更新";
                        return result;
                    }

                    resultObj.DeptId = obj1.DeptId;
                    resultObj.EmpCode = obj1.EmpCode;
                    resultObj.Name = obj1.Name;
                    resultObj.Sex = obj1.Sex;
                    resultObj.BirthDay = obj1.BirthDay;
                    resultObj.Telephone = obj1.Telephone;
                    resultObj.Phone = obj1.Phone;
                    resultObj.WorkStatus = obj1.WorkStatus;

                    //result = employeeDAL.IsEmpCodeRepeat(user, resultObj.EmpCode);
                    //if (result.ResultStatus != 0)
                    //    return result;

                    result = this.Operate.Update(user, resultObj);
                    if (result.ResultStatus != 0)
                        return result;

                    if (resultObj.WorkStatus != (int)WorkStatusEnum.在职)
                    {
                        DAL.AccountDAL accountDAL = new AccountDAL();
                        result = accountDAL.UpdateAccountValidate(user, resultObj.EmpId);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    this.Log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (this.Log.IsInfoEnabled)
                    this.Log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }