Ejemplo n.º 1
0
        /// <summary>
        /// 修改用户昵称和头像
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="nickName"></param>
        /// <param name="headPic"></param>
        /// <returns></returns>
        public async Task <OperationResult> EditUserInfo(int userId, string nickName, string headPic)
        {
            UserInfoRepo.UnitOfWork.TransactionEnabled = true;
            var info = UserInfoRepo.GetByKey(userId);

            info.HeadPic = headPic;
            await UserInfoRepo.UpdateAsync(info);

            var sys = info.SysUser;

            sys.NickName = nickName;
            var result = await SysUserRepo.UpdateAsync(sys);

            await UserInfoRepo.UnitOfWork.SaveChangesAsync();

            return(new OperationResult(OperationResultType.Success, "修改成功"));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 保存FeedBack信息(新增/更新)
        /// </summary>
        /// <param name="updateForeignKey">更新时是否更新外键信息</param>
        /// <param name="dtos">要保存的FeedBackDto信息</param>
        /// <returns>业务操作集合</returns>
        public async Task <OperationResult> SaveFeedBacks(bool updateForeignKey = false, params FeedBackDto[] dtos)
        {
            try
            {
                dtos.CheckNotNull("dtos");
                var addDtos    = dtos.Where(p => p.Id == 0).ToArray();
                var updateDtos = dtos.Where(p => p.Id != 0).ToArray();

                FeedBackRepo.UnitOfWork.TransactionEnabled = true;

                Action <FeedBackDto> checkAction = null;
                Func <FeedBackDto, FeedBack, FeedBack> updateFunc = (dto, entity) =>
                {
                    if (dto.Id == 0 || updateForeignKey)
                    {
                        entity.UserInfo = UserInfoRepo.GetByKey(dto.UserInfoId);
                    }
                    return(entity);
                };
                if (addDtos.Length > 0)
                {
                    FeedBackRepo.Insert(addDtos, checkAction, updateFunc);
                }
                if (updateDtos.Length > 0)
                {
                    FeedBackRepo.Update(updateDtos, checkAction, updateFunc);
                }
                await FeedBackRepo.UnitOfWork.SaveChangesAsync();

                return(new OperationResult(OperationResultType.Success, "保存成功"));
            }
            catch (Exception e)
            {
                return(new OperationResult(OperationResultType.Error, e.Message));
            }
        }