Пример #1
0
 /// <summary>
 /// 修改员工
 /// </summary>
 /// <param name="dto"></param>
 /// <returns></returns>
 /// <inheritdoc cref="" />
 public Result <string> Update(StaffDto dto)
 {
     try
     {
         var staff = dto.MapTo <StaffEntity>();
         var rlt   = UnitOfWorkService.Execute(() =>
         {
             var rlt1 = ObjectContainer.Resolve <IStaffRepository>().Update(staff);
             if (rlt1)
             {
                 return new Result <string> {
                     Status = true
                 }
             }
             ;
             return(new Result <string> {
                 Status = false, Message = "数据库写入失败"
             });
         }
                                               );
         if (!rlt.Status)
         {
             Logger.Error($"修改员工失败:{dto.Id}");
             return(rlt);
         }
         return(rlt);
     }
     catch (Exception ex)
     {
         Logger.Error($"update staff to exception:{ex}");
         return(new Result <string> {
             Status = false, Message = ex.Message
         });
     }
 }
Пример #2
0
        /// <summary>
        /// 增加员工
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// <inheritdoc cref="" />
        public Result <string> Add(StaffDto dto, int orgId, UserType roleId)
        {
            try
            {
                var staff      = dto.MapTo <StaffEntity>();
                var userInRole = new UserInRoleEntity
                {
                    RoleId = ((int)dto.UserType).ToString(),
                    UserId = dto.Id
                };
                var rlt = UnitOfWorkService.Execute(() =>
                {
                    var sta = _repo.Get(dto.Id);
                    if (sta != null)
                    {
                        return(new Result <string> {
                            Status = false, Message = "该账号已存在"
                        });
                    }
                    var rlt1      = _repo.InsertAndGetId(staff);
                    var rlt2      = _userInRoleRepository.InsertAndGetId(userInRole);
                    var dataInOrg = new DataInOrgEntity
                    {
                        DataId   = rlt1,
                        DataType = (int)DataType.Staff,
                        OrgId    = orgId,
                        RoleId   = ((int)roleId).ToString()
                    };
                    var dataRlt    = _dataInOrgRepository.Inserts(dataInOrg);//数据部门权限
                    var executeRlt = rlt1.IsNotEmpty() && rlt2 > 0 && dataRlt;
                    if (executeRlt)
                    {
                        return new Result <string> {
                            Status = true
                        }
                    }
                    ;

                    return(new Result <string> {
                        Status = false, Message = "数据库写入失败"
                    });
                });

                if (!rlt.Status)
                {
                    Logger.Error($"新增员工失败:{dto.Id}");
                    return(rlt);
                }
                return(rlt);
            }
            catch (Exception ex)
            {
                Logger.Error($" add staff to exception:{ex}");
                return(new Result <string> {
                    Status = false, Message = ex.Message
                });
            }
        }