Ejemplo n.º 1
0
        public JsonResponse AccountUserList([FromUri] string Code, string UserId)
        {
            //判断用户是否登录
            if (!TokenHelper.CheckLoginStateByUserId(UserId))
            {
                return(BadResponse("用户未登录", null, false));
            }
            AccountList model = new AccountList();

            model = AccountListBll.GetModelByCode(Code);
            string[]        allUserIdArray = model.AllUserId.Split(',');
            List <UserInfo> AllUserList    = UserInfoBll.GetListByIdList(allUserIdArray).ToList();

            List <AccountListAllUserDto> returnList = new List <AccountListAllUserDto>();

            foreach (var user in AllUserList)
            {
                AccountListAllUserDto userModel = new AccountListAllUserDto
                {
                    NickName = user.Nickname,
                    UserId   = user.Id
                };
                returnList.Add(userModel);
            }
            return(OkResponse(returnList, "请求成功!"));
        }
Ejemplo n.º 2
0
        public JsonResponse AddAccount([FromBody] AccountDto dto)
        {
            //判断用户是否登录
            if (!TokenHelper.CheckLoginStateByUserId(dto.UserId))
            {
                return(BadResponse("用户未登录", null, false));
            }
            string sql = "INSERT INTO " + dto.TableName + " VALUES ";

            foreach (Account model in dto.List)
            {
                //(
                sql += "(";
                //RecorderId
                sql += ("'" + model.RecorderId + "',");
                //UserId
                sql += ("'" + model.UserId + "',");
                //CreateDate
                sql += ("'" + DateTime.Now + "',");
                //Money
                sql += ("" + model.Money + ",");
                //Category
                sql += ("'" + model.Category + "',");
                //Note
                sql += ("'" + model.Note + "'");
                //)
                sql += "),";
            }
            sql = sql.Substring(0, sql.Length - 1);
            if (!BaseBll <Account> .ExecuteSql(sql))
            {
                BadResponse("添加失败!");
            }
            return(OkResponse(null, "添加成功!"));
        }
Ejemplo n.º 3
0
        public JsonResponse SignIn([FromBody] SignInDto dto)
        {
            if (dto.Email == null || dto.Password == null || dto.Verify == null || dto.VerifyId == null)
            {
                return(BadResponse("参数提供不完整"));
            }
            //判断验证码是否输入正确
            if (!TokenHelper.CheckVerify(dto.VerifyId, dto.Verify))
            {
                return(BadResponse("验证码错误"));
            }
            //检查用户名密码是否正确
            UserInfo model = new UserInfo();

            model = UserInfoBll.GetModelByEmail(dto.Email);
            if (model == null)
            {
                return(BadResponse("用户不存在", null));
            }
            //检查用户是否登录,若有登录信息则刷新时间
            //判断用户是否登录
            if (!TokenHelper.CheckLoginStateByUserId(model.Id))
            {
                LoginState loginState = new LoginState
                {
                    UserId    = model.Id,
                    StartTime = DateTime.Now
                };
                LoginStateBll.Insert(loginState);
            }
            return(OkResponse(null));
        }
        public JsonResponse ChangeCategoryName([FromBody] ChangeCategoryNameDto dto)
        {
            //判断用户是否登录
            if (!TokenHelper.CheckLoginStateByUserId(dto.UserId))
            {
                return(BadResponse("用户未登录", null, false));
            }
            //获取更改者信息
            var userModel = UserInfoBll.GetModelById(dto.UserId);

            if (userModel == null)
            {
                return(BadResponse("用户信息出错,请重试!"));
            }
            //查询使用人数
            var categoryModel = AccountCategoryBll.GetModelByName(dto.OldName);

            if (categoryModel == null)
            {
                //此时代表数据库出问题了,应作出处理-----------------------------------------------------------------
                return(BadResponse("分类信息出错,请重试!"));
            }
            //若使用人数为1则直接更新名字
            if (categoryModel.UserNum <= 1)
            {
                categoryModel.Name = dto.NewName;
                if (!AccountCategoryBll.Update(categoryModel))
                {
                    return(BadResponse("网络错误,请重试!"));
                }
            }
            //若有他人使用则新建一条,原条目使用人数-1,将UserInfo中的Category字段更换为新Id
            else
            {
                categoryModel.UserNum--;
                if (!AccountCategoryBll.Update(categoryModel))
                {
                    return(BadResponse("网络错误,请重试!"));
                }
                categoryModel = new AccountCategory
                {
                    Name         = dto.NewName,
                    CreateUserId = dto.UserId
                };
                if (!AccountCategoryBll.Insert(categoryModel))
                {
                    return(BadResponse("网络错误,请重试!"));
                }
            }
            userModel.Category = userModel.Category.Replace(dto.OldName, dto.NewName);
            if (!UserInfoBll.Update(userModel))
            {
                return(BadResponse("网络错误,请重试!"));
            }
            return(OkResponse(null, "修改成功!"));
        }
Ejemplo n.º 5
0
 public JsonResponse CheckLogin(string UserId)
 {
     if (!TokenHelper.CheckLoginStateByUserId(UserId))
     {
         return(BadResponse("用户未登录", null, false));
     }
     else
     {
         return(OkResponse(null));
     }
 }
Ejemplo n.º 6
0
        public JsonResponse UserAccountList([FromUri] string UserId)
        {
            //判断用户是否登录
            if (!TokenHelper.CheckLoginStateByUserId(UserId))
            {
                return(BadResponse("用户未登录", null, false));
            }
            //获取账单列表
            List <AccountList> accountList = new List <AccountList>();

            accountList = AccountListBll.GetListByCreateUserId(UserId).ToList();
            return(OkResponse(accountList, "请求成功!"));
        }
Ejemplo n.º 7
0
        public JsonResponse AddAccountList([FromBody] AccountListDto dto)
        {
            //判断用户是否登录
            if (!TokenHelper.CheckLoginStateByUserId(dto.UserId))
            {
                return(BadResponse("用户未登录", null, false));
            }
            string accountName = "我的手账";

            //若用户没有写账单名则默认为“我的手账”;若有“我的手账”则命名为“我的手账1”
            if (dto.Name != null && dto.Name != "")
            {
                List <AccountList> accountList = AccountListBll.GetListByCreateUserId(dto.UserId).ToList();
                int flag = 1;
                for (int i = 0; i < accountList.Count; i++)
                {
                    if (accountList[i].Name == accountName)
                    {
                        accountName = (accountName + flag.ToString());
                        flag++;
                    }
                }
            }
            else
            {
                accountName = dto.Name;
            }
            //往AccountList写账单基本信息
            DateTime    time  = DateTime.Now;
            AccountList model = new AccountList
            {
                AllUserId = dto.AllUserId,
                Code      = "Z" + (time.Year - 2000).ToString() + time.Month.ToString() + time.Day.ToString()
                            + TokenHelper.GetRandomString(3, false, true, true, false, "") + TokenHelper.GetRandomString(5, true, true, true, false, ""),
                CreateDate   = time,
                CreateUserId = dto.UserId,
                Member       = dto.AllUserId.Split(',').Length,
                Name         = accountName
            };

            //新建账单表
            if (BaseBll <AccountList> .ExecuteSql("exec proc_CreateAccountTable '" + model.Code + "'") &&
                AccountListBll.Insert(model))
            {
                return(OkResponse(null, "添加成功!"));
            }
            else
            {
                return(BadResponse("添加失败!", null));
            }
        }
        public JsonResponse AddCategory([FromBody] AccountCategoryDto dto)
        {
            //判断用户是否登录
            if (!TokenHelper.CheckLoginStateByUserId(dto.UserId))
            {
                return(BadResponse("用户未登录", null, false));
            }
            //查询有没有
            var model = AccountCategoryBll.GetModelByName(dto.Name);

            //有的话则UserNum+1
            if (model != null)
            {
                model.UserNum = model.UserNum + 1;
                if (!AccountCategoryBll.Update(model))
                {
                    return(BadResponse("网络错误,请重试!"));
                }
            }
            //没有则添加
            else
            {
                model = new AccountCategory
                {
                    Name         = dto.Name,
                    CreateUserId = dto.UserId
                };
                if (!AccountCategoryBll.Insert(model))
                {
                    return(BadResponse("网络错误,请重试!"));
                }
            }
            //将Category的Id添加到UserInfo的Category字段中
            model = AccountCategoryBll.GetModelByName(dto.Name);
            var user = UserInfoBll.GetModelById(dto.UserId);

            if (user == null)
            {
                return(BadResponse("用户信息出错,请重试!"));
            }
            user.Category += (model.Name + ",");
            if (!UserInfoBll.Update(user))
            {
                return(BadResponse("网络错误,请重试!"));
            }
            return(OkResponse(null, "添加成功!"));
        }
        public JsonResponse ChangeCategoryShow([FromBody] ChangeCategoryShowDto dto)
        {
            //判断用户是否登录
            if (!TokenHelper.CheckLoginStateByUserId(dto.UserId))
            {
                return(BadResponse("用户未登录", null, false));
            }
            //将所有dto.ShowName的IsShow改为true
            //将所有dto.HideName的IsShow改为false
            //dto.ShowName->"'1','2'"
            var sql = "update AccountCategory set IsShow = 1 where Name in(" + dto.ShowName + ");update AccountCategory set IsShow = 0 where UserId in(" + dto.HideName + ")";

            if (!AccountCategoryBll.ExecuteSql(sql))
            {
                return(BadResponse("网络错误,请重试!"));
            }
            return(OkResponse(null, "修改成功!"));
        }
Ejemplo n.º 10
0
        public JsonResponse DeleteUserCategory([FromBody] AccountCategoryDto dto)
        {
            //判断用户是否登录
            if (!TokenHelper.CheckLoginStateByUserId(dto.UserId))
            {
                return(BadResponse("用户未登录", null, false));
            }
            //查询该类别的Id
            var categoryModel = AccountCategoryBll.GetModelByName(dto.Name);
            //从UserInfo中的Category字段里删除该类别
            var userModel = UserInfoBll.GetModelById(dto.UserId);

            if (userModel == null)
            {
                return(BadResponse("用户信息出错,请重试!"));
            }
            userModel.Category = userModel.Category.Replace((categoryModel.Name + ","), "");
            if (!UserInfoBll.Update(userModel))
            {
                return(BadResponse("网络错误,请重试!"));
            }
            if (categoryModel == null)
            {
                //此时代表数据库出问题了,应作出处理-----------------------------------------------------------------
                return(OkResponse(null, "删除成功!"));
            }
            //类别表中该类别使用数-1,若使用数为0则删除该类别
            if (categoryModel.UserNum == 1)
            {
                AccountCategoryBll.ExecuteSql("delete from AccountCategory where Name='" + categoryModel.Name + "'");
            }
            else
            {
                categoryModel.UserNum--;
                if (AccountCategoryBll.Update(categoryModel))
                {
                    return(BadResponse("网络错误,请重试!"));
                }
            }

            return(OkResponse(null, "删除成功!"));
        }
Ejemplo n.º 11
0
        public JsonResponse ModifyPassword([FromBody] ModifyPasswordDto dto)
        {
            //判断用户是否登录
            if (!TokenHelper.CheckLoginStateByUserId(dto.UserId))
            {
                return(BadResponse("用户未登录", null, false));
            }
            if (dto.UserId == null || dto.OldPassword == null || dto.NewPassword == null || dto.Verify == null || dto.VerifyId == null)
            {
                return(BadResponse("参数提供不完整"));
            }
            //判断验证码是否输入正确
            if (!TokenHelper.CheckVerify(dto.VerifyId, dto.Verify))
            {
                return(BadResponse("验证码错误"));
            }
            UserInfo model = new UserInfo();

            model = UserInfoBll.GetModelById(dto.UserId);

            //判断用户是否存在
            if (model == null)
            {
                return(BadResponse("用户不存在"));
            }
            //新密码加密
            dto.NewPassword = PasswordHelper.PwdStrToHashStr(dto.NewPassword);
            //判断新旧密码是否相同
            if (dto.NewPassword == model.Password)
            {
                return(BadResponse("旧密码与新密码相同"));
            }
            //若不相同新密码写入数据库
            model.Password = dto.NewPassword;
            if (!UserInfoBll.Update(model))
            {
                return(BadResponse("网络错误,请重试"));
            }
            return(OkResponse(null, "密码修改成功"));
        }
Ejemplo n.º 12
0
        public JsonResponse DeleteAccountList([FromBody] AccountListDto dto)
        {
            //判断用户是否登录
            if (!TokenHelper.CheckLoginStateByUserId(dto.UserId))
            {
                return(BadResponse("用户未登录", null, false));
            }
            //获取账单基本信息
            AccountList accountListModel = new AccountList();

            accountListModel = AccountListBll.GetModelByCode(dto.Code);
            if (accountListModel == null)
            {
                return(BadResponse("无该账单信息!", null));
            }
            string[] userIdArray = dto.AllUserId.Split(',');
            if (userIdArray.Length == 1)
            {
                SystemNoticeBll.ExecuteSql("DELETE FROM AccountList WHERE Code='" + dto.Code + "';DROP TTABLE " + dto.Code);
                return(OkResponse(null, "账单已删除。"));
            }
            //获取账单成员并通知账单成员(写入通知表)
            string content = "账单:" + accountListModel.Name + "即将被账单创建者删除,请校验账单信息无资金纠纷后确认删除。";

            SystemNoticeBll.ExecuteSql(SystemNoticeHelper.InsertNotice(dto.AllUserId, content));

            //写入操作记录
            AccountListLog log = new AccountListLog
            {
                Code    = dto.Code,
                NewInfo = "删除账单" + accountListModel.Name,
                Type    = LogType.Delete
            };

            AccountListLogBll.Insert(log);
            //若都确认后、自动删除该表,每一个人确认时都查看此人是否为最后确认的人、若是、则直接删除账单
            //否则十五天后数据库定时作业会删除该表)
            return(OkResponse(null, "账单已提交删除,待所有成员均已确认后账单可立即删除,若确认时间超过15日则自动删除。"));
        }
Ejemplo n.º 13
0
        public JsonResponse ModifyAccountListInfo([FromBody] AccountListDto dto)
        {
            //判断用户是否登录
            if (!TokenHelper.CheckLoginStateByUserId(dto.UserId))
            {
                return(BadResponse("用户未登录", null, false));
            }
            AccountList model = new AccountList();

            model = AccountListBll.GetModelByCode(dto.Code);
            if (model == null)
            {
                return(BadResponse("该账单不存在", null));
            }
            if (dto.Name != null && dto.Name != "" && dto.Name != null && dto.Name != "")
            {
                return(BadResponse("参数提供不完整", null));
            }
            //修改名字
            if (dto.Name != null && dto.Name != "")
            {
                AccountListLog log = new AccountListLog
                {
                    Code    = dto.Code,
                    OldInfo = "账单名:" + model.Name,
                    NewInfo = "账单名:" + dto.Name
                };
                AccountListLogBll.Insert(log);
                model.Name = dto.Name;
            }
            if (dto.AllUserId != null && dto.AllUserId != "")
            {
                //根据AllUserId返回昵称
                AccountListLog log = new AccountListLog();
                log.Code = dto.Code;
                string sql = "proc_GetNicknameByUserId";
                //Old
                DynamicParameters p = new DynamicParameters();
                p.Add("@UserId", model.AllUserId, DbType.String);
                List <UserInfo> oldList = new List <UserInfo>();
                oldList.AddRange(SqlHelper.QuerySP <UserInfo>(sql, p).ToList());
                log.OldInfo = "账单使用人:";
                foreach (UserInfo user in oldList)
                {
                    log.OldInfo += (user.Nickname + ";");
                }
                //New
                p = new DynamicParameters();
                p.Add("@UserId", dto.AllUserId, DbType.String);
                List <UserInfo> newList = new List <UserInfo>();
                newList.AddRange(SqlHelper.QuerySP <UserInfo>(sql, p).ToList());
                log.OldInfo = "账单使用人:";
                foreach (UserInfo user in newList)
                {
                    log.NewInfo += (user.Nickname + ";");
                }
                //Note
                //del
                string delName = "";
                bool   have    = false;
                for (var i = 0; i < oldList.Count; i++)
                {
                    have = false;
                    for (var j = 0; j < newList.Count; j++)
                    {
                        if (oldList[i] == newList[j])
                        {
                            have = true;
                            break;
                        }
                    }
                    if (!have)
                    {
                        delName += oldList[i].Nickname;
                    }
                }
                if (delName != "")
                {
                    log.Note += ("移除成员:" + delName);
                }
                //add
                string addName = "";
                for (var i = 0; i < newList.Count; i++)
                {
                    have = false;
                    for (var j = 0; j < oldList.Count; j++)
                    {
                        if (newList[i] == oldList[j])
                        {
                            have = true;
                            break;
                        }
                    }
                    if (!have)
                    {
                        addName += oldList[i].Nickname;
                    }
                }
                if (addName != "")
                {
                    log.Note += ("新增成员:" + addName);
                }
                AccountListLogBll.Insert(log);
                model.AllUserId = dto.AllUserId;
            }
            if (AccountListBll.Update(model))
            {
                return(OkResponse(null, "修改成功!"));
            }
            else
            {
                return(BadResponse("修改失败!", null));
            }
        }