Exemple #1
0
 public int Insert(CSF_Functions entity)
 {
     try
     {
         entity.CreateDate = System.DateTime.Now;
         entity.ParentID   = entity.ParentID != null ? entity.ParentID : 0;
         MyContext.CSF_Functions.Add(entity);
         MyContext.SaveChanges();
         return(entity.ID);
     }
     catch (Exception ex)
     {
         Logs.WriteLog(ex);
         throw;
     }
 }
Exemple #2
0
 public bool Update(CSF_Functions entity)
 {
     try
     {
         var obj = MyContext.CSF_Functions.Find(entity.ID);
         obj.Name              = entity.Name;
         obj.Description       = entity.Description;
         obj.ModuleID          = entity.ModuleID;
         obj.ParentID          = entity.ParentID;
         obj.Controller_Action = entity.Controller_Action;
         MyContext.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         Logs.WriteLog(ex);
         return(false);
     }
 }
Exemple #3
0
 public JsonResult EditSubmit(string ID, string Name, string Description, string ParentID, string ModuleID, string Controller_Action)
 {
     try
     {
         CSF_Functions_DAO objFunctionsDAO = new CSF_Functions_DAO();
         CSF_Functions     objFunc         = new CSF_Functions();
         if (ParentID != "")
         {
             objFunc.ParentID = Convert.ToInt32(ParentID);
             if (Convert.ToInt32(ID) == Convert.ToInt32(ParentID))
             {
                 return(Json(new { status = false, message = "Không thể chọn chức năng cha chính nó" }, JsonRequestBehavior.AllowGet));
             }
         }
         else
         {
             objFunc.ParentID = 0;
         }
         if (objFunctionsDAO.CheckControllerAction(Convert.ToInt32(ID), Controller_Action))
         {
             return(Json(new { status = false, message = "Controller-Action đã tồn tại!" }, JsonRequestBehavior.AllowGet));
         }
         objFunc.ID                = Convert.ToInt32(ID);
         objFunc.Name              = Name;
         objFunc.Description       = Description;
         objFunc.ModuleID          = Convert.ToInt32(ModuleID);
         objFunc.Controller_Action = Controller_Action;
         if (objFunctionsDAO.Update(objFunc))
         {
             SetAlert("Cập nhật chức năng thành công", AlertType.Success);
             return(Json(new { status = true, message = "" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json(new { status = false, message = "Lỗi cập nhật chức năng" }, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         Logs.WriteLog(ex);
         return(Json(new { status = false, message = "Lỗi: " + ex }, JsonRequestBehavior.AllowGet));
     }
 }
Exemple #4
0
        public ActionResult Create(FormCollection fc, CSF_Functions func)
        {
            try
            {
                //if (!this.HasPermission) return RedirectToAction("Unauthorized", "Home");
                if (ModelState.IsValid)
                {
                    CSF_Functions_DAO objFunctionsDAO  = new CSF_Functions_DAO();
                    string            controllerAction = fc["listController"] + "-" + fc["listAction"];
                    //Kiểm tra trùng tên ControllerAction
                    if (objFunctionsDAO.CheckControllerAction(0, controllerAction))
                    {
                        SetAlert("Controller-Action đã tồn tại!", AlertType.Error);
                        return(View());
                    }

                    func.Controller_Action = controllerAction;
                    int ReturnID = objFunctionsDAO.Insert(func);
                    if (ReturnID > 0)
                    {
                        SetAlert("Thêm chức năng thành công", AlertType.Success);
                        return(RedirectToAction("Index", "QT_Functions"));
                    }
                    else
                    {
                        SetAlert("Thêm chức năng không thành công", AlertType.Error);
                    }
                }
                return(View());
            }
            catch (Exception ex)
            {
                SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error);
                Logs.WriteLog(ex);
                return(View());
            }
        }