Esempio n. 1
0
        public ActionResult del(string id)
        {
            try
            {
                //1.0 将id打断成一个数组
                string[] ids = id.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

                //2.0 遍历ids进行数据的物理删除
                sysKeyValue model;
                foreach (var kid in ids)
                {
                    //实例化要删除的数据实体,此时没有追加到EF中
                    model = new sysKeyValue()
                    {
                        KID = int.Parse(kid)
                    };

                    //2.0 追加到EF容器
                    keyvalSer.Delete(model, false);
                }

                //批量删除操作
                keyvalSer.SaveChanges();

                return(WriteSuccess("数据删除成功"));
            }
            catch (Exception ex)
            {
                return(WriteError(ex));
            }
        }
Esempio n. 2
0
        public ActionResult edit(int id, sysKeyValueView model)
        {
            try
            {
                if (ModelState.IsValid == false)
                {
                    return(WriteError("实体验证失败"));
                }

                //1.0 将model中的Kid补全
                model.KID = id;

                //2.0 进行数据的编辑
                sysKeyValue entity = model.EntityMap();
                keyvalSer.Edit(entity, new string[] { "KType", "KName", "Kvalue", "KRemark" });

                keyvalSer.SaveChanges();

                return(WriteSuccess("数据编辑成功"));
            }
            catch (Exception ex)
            {
                return(WriteError(ex));
            }
        }
Esempio n. 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            sysKeyValue sysKeyValue = db.sysKeyValue.Find(id);

            db.sysKeyValue.Remove(sysKeyValue);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 4
0
 public ActionResult Edit([Bind(Include = "KID,ParentID,KType,KName,Kvalue,KRemark")] sysKeyValue sysKeyValue)
 {
     if (ModelState.IsValid)
     {
         db.Entry(sysKeyValue).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(sysKeyValue));
 }
Esempio n. 5
0
        // GET: sysKeyValues/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            sysKeyValue sysKeyValue = db.sysKeyValue.Find(id);

            if (sysKeyValue == null)
            {
                return(HttpNotFound());
            }
            return(View(sysKeyValue));
        }
Esempio n. 6
0
        public ActionResult Create([Bind(Include = "KID,ParentID,KType,KName,Kvalue,KRemark")] sysKeyValue sysKeyValue)
        {
            if (ModelState.IsValid)
            {
                db.sysKeyValue.Add(sysKeyValue);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", "出大事额");
            }

            return(View(sysKeyValue));
        }
Esempio n. 7
0
        public ActionResult add(sysKeyValueView model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(base.WriteError("实体验证失败"));
                }
                //转换实体
                sysKeyValue entity = model.EntityMap();
                _keyvalSer.Add(entity);

                _keyvalSer.SaveChanges();
                return(base.WriteSuccess("新增成功"));
            }

            catch (Exception ex)
            {
                return(base.WriteError(ex));
            }
        }
Esempio n. 8
0
 public static sysKeyValueView EntityMap(this sysKeyValue model)
 {
     //2.0 将一个实体转换成另外一个实体
     return(Mapper.Map <sysKeyValue, sysKeyValueView>(model));
 }
Esempio n. 9
0
 public static sysKeyValueView EntityMap(this sysKeyValue model)
 {
     return(Mapper.Map <sysKeyValue, sysKeyValueView>(model));
 }