Exemplo n.º 1
0
        public ActionResult addAccount(AccountViewModel account)
        {
            if (!isLogin()) return RedirectToAction("login", "auth");
            User user = getCurrentUser();

            account.SubmitTime = DateTime.Now;
            account.State = false;
            if (account.Info==null) account.Info = "";
            account.UserId = user.Id;

            Provider db=new Provider();
            db.insertAccount(account);

            int aid = (int)db.getDataRow("SELECT Id FROM Account ORDER BY Id DESC")["Id"];
            db.deleteAccountTagByAccount(aid);

            string[] tmp = account.Tag.Split(new char[] { ' ', ',', ',', ' ' });
            foreach (string t in tmp)
            {
                Tag tag = db.getTagsByName(t);
                if (tag == null)
                {
                    db.insertTag(new Tag() {Name=t,Count=0, UserId=user.Id });
                }
                db.insertAccountTag(aid, tag.Id);
            }
            string content = "<tr id='account_item_" + aid + "'><td>" + (account.Type ? "收入" : "支出") + "</td><td>" + account.Money + "</td><td>" + account.Time.ToString("yyyy-MM-dd") + "</td><td>" + account.Info + "</td><td>" + account.Tag + "</td><td style='font-size:20px;'><a href='javascript:void(0)' class='btn_edit' onclick='showEditAccount(" + aid + ")'> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></td><td style='style='font-size:20px;'><a href='javascript:void(0)' class='btn_delete' onclick='showDeleteAccount(" + aid + ")'><span style='font-size:24px'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></td></tr>";
            return Content(content);
        }
Exemplo n.º 2
0
        public ActionResult editAccount(int id)
        {
            if (!isLogin()) return RedirectToAction("login", "auth");
            User user = getCurrentUser();

            Provider db=new Provider();
            Account r=db.getAccount(id);
            if (user.Id != r.UserId) return View("msg", new MsgViewModel() { msg = "没有权限" });
            AccountViewModel obj = new AccountViewModel()
            {
                Id = r.Id,
                Info = r.Info,
                Money = r.Money,
                State = r.State,
                SubmitTime = r.SubmitTime,
                Time = r.Time,
                Type = r.Type,
                UserId = r.UserId,
                Tag = getTagString(db.getTagsByAccount(r.Id))
            };
            ViewData["TagCloud"] = db.getTagsByUser(user.Id);

            return View(obj);
        }