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 + ")'> </a></td><td style='style='font-size:20px;'><a href='javascript:void(0)' class='btn_delete' onclick='showDeleteAccount(" + aid + ")'><span style='font-size:24px'> </a></td></tr>"; return Content(content); }
public ActionResult deleteAccount(int id) { if (!isLogin()) return RedirectToAction("login", "auth"); Provider db = new Provider(); try { db.deleteAccountTagByAccount(id); db.deleteAccount(id); } catch (Exception e) { return Content("fail"+e.Message); } return Content("ok"); }