Exemplo n.º 1
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, "添加成功!"));
        }
Exemplo n.º 2
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));
            }
        }