Exemplo n.º 1
0
 public JsonResult Create(Role role)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var dao    = new RoleDao();
             var result = dao.Insert(role);
             if (result == 1)
             {
                 SetAlert("Thêm bản ghi thành công!", "success");
                 return(Json("Saved Successfully!", JsonRequestBehavior.AllowGet));
             }
             else
             {
                 SetAlert("Không thể thêm bản ghi này!", "error");
                 return(Json("Not Saved!", JsonRequestBehavior.AllowGet));
             }
         }
         else
         {
             var errorList = (from item in ModelState
                              where item.Value.Errors.Any()
                              select item.Value.Errors[0].ErrorMessage).ToList();
             SetAlert("Not Saved!", "error");
             return(Json(errorList, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         SetAlert("Không thể thêm bản ghi này!", "error");
         var errormessage = "Error occured: " + ex.Message;
         return(Json(errormessage, JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 2
0
        private void B_ADD_Click(object sender, EventArgs e)
        {
            if (isValidInputData())
            {
                ModelRole model = new ModelRole();
                model.id        = this.id;
                model.role_code = role_code.Text;
                model.role_name = role_name.Text;

                Boolean result = false;
                switch (B_ADD.Text)
                {
                case "บันทึก":
                    result = roleDao.Insert(model);
                    if (result)
                    {
                        MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว");
                    }
                    break;

                case "แก้ไข":
                    result = roleDao.Update(model);
                    if (result)
                    {
                        MessageBox.Show("แก้ไขข้อมูลเรียบร้อยแล้ว");
                    }
                    break;
                }
                if (result)
                {
                    refresh();
                }
            }
        }
Exemplo n.º 3
0
 public ActionResult Add(tb_Roles entity)
 {
     if (ModelState.IsValid)
     {
         Dao.Insert(entity);
         return(RedirectToAction("Index"));
     }
     return(View(entity));
 }
Exemplo n.º 4
0
        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        public Result Insert(Role role)
        {
            int row = roleDao.Insert(role);

            if (row > 0)
            {
                return(Result.添加成功);
            }
            else
            {
                return(Result.添加失败);
            }
        }
Exemplo n.º 5
0
        public JsonResult SaveData(string strRole)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            Role   role    = serializer.Deserialize <Role>(strRole);
            bool   status  = false;
            string action  = string.Empty;
            string message = string.Empty;
            bool   res     = new RoleDao().CheckIDExist(role.ID);

            if (res)
            {
                var model = new RoleDao();
                try
                {
                    model.Insert(role);
                    status = true;
                    action = "insert";
                }
                catch (Exception ex)
                {
                    status  = false;
                    message = ex.Message;
                }
            }
            else
            {
                try
                {
                    var model = new RoleDao().Update(role);
                    status = true;
                    action = "update";
                }
                catch (Exception ex)
                {
                    status  = false;
                    message = ex.Message;
                }
            }

            return(Json(new
            {
                status = status,
                message = message,
                action = action
            }));
        }
Exemplo n.º 6
0
 public ActionResult Index(AdminModel entity)
 {
     if (ModelState.IsValid)
     {
         var  RoleName = entity.RoleName;
         long RoleId   = 0;
         var  Role     = Dao.GetByName(RoleName);
         if (Role != null)
         {
             RoleId = Role.Id;
             var User = new tb_Users();
             User.Date         = DateTime.Now;
             User.Modified     = DateTime.Now;
             User.RoleId       = RoleId;
             User.Status       = true;
             User.UserEmail    = entity.UserEmail;
             User.UserName     = entity.UserName;
             User.UserPassword = mhPass.MahoaMD5(entity.UserPassword);
             UDao.Insert(User);
         }
         else
         {
             Role                 = new tb_Roles();
             Role.RoleName        = RoleName;
             Role.RoleDescription = "Người quản trị cao nhất!";
             Role.RoleAction      = 7;
             Dao.Insert(Role);
             RoleId = Role.Id;
             var User = new tb_Users();
             User.Date         = DateTime.Now;
             User.Modified     = DateTime.Now;
             User.RoleId       = RoleId;
             User.Status       = true;
             User.UserEmail    = entity.UserEmail;
             User.UserName     = entity.UserName;
             User.UserPassword = mhPass.MahoaMD5(entity.UserPassword);
             UDao.Insert(User);
         }
         return(RedirectToAction("Index"));
     }
     return(View(entity));
 }
Exemplo n.º 7
0
 public bool Insert(RoleObject ob)
 {
     return(ModelRole.Insert(ob));
 }