public void Create()
        {
            entity = new department();
            entity.id = Convert.ToInt32(Request.Form["entity.id"]);
            entity.departname = Request.Form["entity.departname"];
            entity.description = Request.Form["entity.description"];

            string message = "error";
            id = entity.id;
            if (entity != null)
            {
                var b_department = db.department.SingleOrDefault(s => s.departname == entity.departname);

                int checkId = 0;
                if (b_department != null)
                {
                    checkId = b_department.id;
                }

                if (id < 1)
                {
                    if (checkId == 0)
                    {
                        db.department.InsertOnSubmit(entity);
                        db.SubmitChanges();

                        message = "success";
                    }
                }
                else
                {
                    if (checkId == 0 || id == checkId)
                    {
                        var b_department2 = db.department.Single(s => s.id == entity.id);
                        b_department2.departname = entity.departname;
                        b_department2.description = entity.description;
                        db.SubmitChanges();

                        message = "success";
                    }
                }
            }

            if (id < 1)
            {
                // update
                id = entity.id;
            }

            // 重新初始化
            InitCreateView();

            // 弹窗交互
            Response.Write("<script language=javascript>alert('"+message+"');</script>");
        }
        public void InitCreateView()
        {
            if (id == 0)
            {
                // 根据 id 获取实体类
                id = Convert.ToInt32(Request.QueryString["id"]);
            }
            var dbList = from s in db.department
                         where s.id == id
                         select s;

            if (dbList != null && dbList.Count() > 0)
            {
                entity = dbList.First();
            }
            if (entity == null)
            {
                entity = new department();
            }
        }
Example #3
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Model.department model)
 {
     return(dal.Update(model));
 }
Example #4
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public bool Add(Model.department model)
 {
     return(dal.Add(model));
 }
 partial void Deletedepartment(department instance);
 partial void Updatedepartment(department instance);
 partial void Insertdepartment(department instance);