Example #1
0
 public ActionResult Create(UserGroupViewModel model)
 {
     ViewBag.Role = _userGrDao.ListAllRole();
     try
     {
         if (ModelState.IsValid)
         {
             var userGr = new UserGroup();
             userGr.UpdateUserGroup(model);
             int id = _userGrDao.Insert(userGr);
             new CredentialDao().Create(userGr, model.Role);
             if (id == 0)
             {
                 ModelState.AddModelError("", "Tên đã tồn tại");
             }
             else if (id > 0)
             {
                 SetAlert("Thêm thành công", "success");
                 return(RedirectToAction("Index", "UserGroup"));
             }
             else
             {
                 ModelState.AddModelError("", "Thêm thất bại");
             }
         }
         return(View(model));
     }
     catch
     { return(View()); }
 }
Example #2
0
        public ActionResult Create(UserGroupViewModel model)
        {
            ViewBag.Role = _userGrDao.ListAllRole();
            try
            {
                if (ModelState.IsValid)
                {
                    var userGr = new USERGROUP();
                    userGr.ID   = StringHelper.ToUnsignString(model.Name);
                    userGr.Name = model.Name;
                    int id = _userGrDao.Insert(userGr);

                    if (id == -1)
                    {
                        ModelState.AddModelError("", "Tên đã tồn tại");
                    }
                    else if (id == 1)
                    {
                        new CredentialDao().Create(userGr, model.Role);
                        SetAlert("Thêm thành công", "success");
                        return(RedirectToAction("Index", "UserGroup"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Thêm thất bại");
                    }
                }
                return(View(model));
            }
            catch
            { return(View()); }
        }
Example #3
0
        public JsonResult SaveData(string strUserGroup)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            UserGroup            userGroup  = serializer.Deserialize <UserGroup>(strUserGroup);
            bool   status  = false;
            string action  = string.Empty;
            string message = string.Empty;
            bool   res     = new UserGroupDao().CheckIDExist(userGroup.ID);

            if (res)
            {
                var model = new UserGroupDao();
                try
                {
                    model.Insert(userGroup);
                    status = true;
                    action = "insert";
                }
                catch (Exception ex)
                {
                    status  = false;
                    message = ex.Message;
                }
            }
            else
            {
                //update existing DB
                //save db
                try
                {
                    var model = new UserGroupDao().Update(userGroup);
                    status = true;
                    action = "update";
                }
                catch (Exception ex)
                {
                    status  = false;
                    message = ex.Message;
                }
            }

            return(Json(new
            {
                status = status,
                message = message,
                action = action
            }));
        }
Example #4
0
 public ActionResult Create(NhomTK tt)
 {
     if (ModelState.IsValid)
     {
         var  dao = new UserGroupDao();
         long id  = dao.Insert(tt);
         if (id > 0)
         {
             SetAlert("Thêm nhóm user thành công", "success");
             return(RedirectToAction("Index", "UserGroup"));
         }
         else
         {
             ModelState.AddModelError("", "Thêm nhóm tài khoản không thành công");
         }
     }
     return(View("Index"));
 }
Example #5
0
 public ActionResult Create(UserGroup model)
 {
     if (ModelState.IsValid)
     {
         var    dao = new UserGroupDao();
         string id  = dao.Insert(model);
         if (id != null)
         {
             SetAlert("Thêm user group thành công", "success");
             return(RedirectToAction("Index", "UserGroup"));
         }
         else
         {
             SetAlert("Thêm user group thất bại", "error");
             ModelState.AddModelError("", "Thêm user thất bại");
         }
     }
     return(View("Index"));
 }