Пример #1
0
        public ActionResult ChangeLog(int id, int? AssetId, FormCollection collection)
        {
            AssetChangeLog a = null;
            int assetid = 0;
            DateTime ChangeDate = DateTime.MinValue;
            DateTime.TryParse(collection["ChangeDate"], out ChangeDate);
            if (id == 0)
            {
                a = new AssetChangeLog();
                assetid = (int)AssetId;
                a.AssetId = assetid;
                db.AssetChangeLogs.Add(a);
            }
            else
            {
                a = db.AssetChangeLogs.Find(id);
                if (a == null) throw new Exception("找不到变动记录");
                assetid = a.AssetId;
            }
            //delete
            if (collection["act"] == "delete")
            {
                db.AssetChangeLogs.Remove(a);
                db.SaveChanges();
                return Redirect("~/content/close.htm");
            }
            //create or modify
            Asset asset = db.Assets.Find(a.AssetId);
            //a.ChangeDate = ChangeDate;
            //a.Title = collection["Title"];
            //a.Detail = collection["Detail"];
            //a.UseType = collection["UseType"];
            TryUpdateModel(a, "", null, new string[] { "AssetId" });
            if (ModelState.IsValid)
            {

                db.SaveChanges();
                ViewBag.Message = "ok";
                ViewBag.asset = asset;
                return Redirect("~/content/close.htm");
            }
            else
            {
                ViewBag.asset = asset;
                return View(a);
            }
        }
Пример #2
0
        public ActionResult ChangeLog(int id, int? assetid)
        {
            AssetChangeLog au; Asset asset;
            if (id == 0)
            {
                asset = db.Assets.Find(assetid);
                if (asset == null)
                {//ToDo:异常处理
                }
                au = new AssetChangeLog();
                au.ChangeDate = DateTime.Today;
                au.Title = "其他";
            }
            else
            {
                au = db.AssetChangeLogs.Find(id);
                if (au == null)
                {
                    //ToDo:异常处理
                }
                asset = db.Assets.Find(au.AssetId);
            }
            ViewBag.asset = asset;

            return View(au);
        }