Beispiel #1
0
 public ActionResult Create(Models.AppFunction o)
 {
     /// Authentication and authorisation.
     if (Session["UserId"] == null)
     {
         return(RedirectToAction("Login", "home"));
     }
     if (!BAL.AccessBO.CanAccessAppFunctionByUserId(Session["UserId"].ToString(), "appfunc_create"))
     {
         return(RedirectToAction("NoAccess", "home"));
     }
     if (!ModelState.IsValid)
     {
         return(View(o));
     }
     if (o == null)
     {
         ModelState.AddModelError(string.Empty, "AppFunction is NULL.");
         return(View(o));
     }
     /// check whether name already exists in database.
     if (string.IsNullOrEmpty(o.UniqueName))
     {
         o.UniqueName = o.UniqueName.Trim();
     }
     if (DAO.AppFunctionDao.UniqueNameExists(o.UniqueName))
     {
         ModelState.AddModelError(string.Empty, "Unique Name already exists.");
         return(View(o));
     }
     return(View("CreateConfirm", o));
 }
Beispiel #2
0
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            using (var db = new AumentumSecurityContext())
            {
                Models.AppFunction permission = db.Permissions.Single(p => p.AppFunctionType == "field" &&
                                                                      p.Name == LegalPartySearchRebuildAllName);
                db.Permissions.Remove(permission);

                db.SaveChanges();
            }
        }
Beispiel #3
0
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            using (var db = new AumentumSecurityContext())
            {
                Models.AppFunction permission = db.Permissions.Single(p => p.AppFunctionType == "field" &&
                                                                      p.Name == OperationsSystemStopwords);
                db.Permissions.Remove(permission);

                db.SaveChanges();
            }
        }
Beispiel #4
0
 public ActionResult EditResult(Models.AppFunction o)
 {
     /// Authentication and authorisation.
     if (Session["UserId"] == null)
     {
         return(RedirectToAction("Login", "home"));
     }
     if (!BAL.AccessBO.CanAccessAppFunctionByUserId(Session["UserId"].ToString(), "appfunc_edit"))
     {
         return(RedirectToAction("NoAccess", "home"));
     }
     return(View(o));
 }
Beispiel #5
0
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            using (var db = new AumentumSecurityContext())
            {
                var permissionSeeder = new PermissionSeeder(db);

                Models.AppFunction parent = db.Permissions.Single(p => p.AppFunctionType == "Application" &&
                                                                  p.App == "api.LegalPartySearchService");

                db.Permissions.AddRange(permissionSeeder.CreateFields(parent.Id, parent.Name, LegalPartySearchRebuildAllName));

                db.SaveChanges();
            }
        }
Beispiel #6
0
 public ActionResult EditConfirm(Models.AppFunction o)
 {
     /// Authentication and authorisation.
     if (Session["UserId"] == null)
     {
         return(RedirectToAction("Login", "home"));
     }
     if (!BAL.AccessBO.CanAccessAppFunctionByUserId(Session["UserId"].ToString(), "appfunc_edit"))
     {
         return(RedirectToAction("NoAccess", "home"));
     }
     if (o == null || string.IsNullOrWhiteSpace(o.UniqueName))
     {
         return(RedirectToAction("Index"));
     }
     /// If clicking the "Confirm".
     if ("confirm".Equals(BAL.CommonHelper.GetSessionValue(Request, "UiConfirm")?.ToLower()))
     {
         int userId = DAO.UserDao.GetIdByLoginname("admin");
         if (userId < 0)
         {
             userId = 0;
         }
         o.UpdatedBy = o.CreatedBy = userId;
         /// Update database.
         int i = DAO.AppFunctionDao.UpdateUnit(o);
         if (i == 1)
         {
             return(View("EditResult", o));
         }
         else if (i < 1)
         {
             ModelState.AddModelError(string.Empty, "Fail to update it in database.");
             return(View("Edit", o));
         }
         else
         {
             ModelState.AddModelError(string.Empty, "More than ONE record are updated in database.");
             return(View("Edit", o));
         }
     }
     else
     {
         return(View("Edit", o));
     }
 }
Beispiel #7
0
        private static List <Models.AppFunction> GetListByDataTable(DataTable dt)
        {
            if ((dt?.Rows.Count ?? 0) < 1)
            {
                return(null);
            }
            List <Models.AppFunction> rList = new List <Models.AppFunction>();

            foreach (DataRow dr in dt.Rows)
            {
                Models.AppFunction o = Mapping(dr);
                if (o != null)
                {
                    rList.Add(o);
                }
            }
            return(rList);
        }
Beispiel #8
0
        public static IEnumerable <Models.AppFunction> GetAllParentList()
        {
            List <Models.AppFunction> rList;
            DataTable dt = null;

            try
            {
                rList = new List <Models.AppFunction>()
                {
                    new Models.AppFunction()
                    {
                        AppFunctionId  = 0,
                        UniqueName     = "system",
                        DisplayName    = "System",
                        AppFuncLevelId = 0,
                        ParentId       = 0,
                        SequentialNum  = 0,
                        IsDisabled     = false,
                        IsNavItem      = false
                    }
                };
                string sql = "SELECT * FROM AppFunctions WHERE AppFuncLevelId<3 ORDER BY AppFuncLevelId,SequentialNum,DisplayName,UniqueName";
                dt = DbHandler.IsMssqlConnected ?
                     DbHandler.MSSQL.SelectDataTable(sql) :
                     DbHandler.SQLite.SelectDataTable(sql);
                if ((dt?.Rows.Count ?? 0) > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        Models.AppFunction o = Mapping(dr);
                        if (o != null)
                        {
                            rList.Add(o);
                        }
                    }
                }
                return(rList);
            }
            finally { DbHandler.DisposeDataTable(ref dt); }
        }
Beispiel #9
0
 public ActionResult Delete(Models.AppFunction o)
 {
     /// Authentication and authorisation.
     if (Session["UserId"] == null)
     {
         return(RedirectToAction("Login", "home"));
     }
     if (!BAL.AccessBO.CanAccessAppFunctionByUserId(Session["UserId"].ToString(), "appfunc_delete"))
     {
         return(RedirectToAction("NoAccess", "home"));
     }
     if (o == null)
     {
         return(RedirectToAction("Index"));
     }
     /// update database.
     if (DAO.AppFunctionDao.DeleteUnit(o.AppFunctionId) < 1)
     {
         ModelState.AddModelError(string.Empty, "Fail to delete it in database.");
         return(View(o));
     }
     return(RedirectToAction("Index"));
 }
Beispiel #10
0
        public static List <Models.AppFunction> GetList(int AppFuncLevelId, int ParentId, bool?IsNavItem, bool isShort)
        {
            if (AppFuncLevelId > 3 || AppFuncLevelId < 0)
            {
                return(null);
            }
            DataTable           dt         = null;
            List <SqlParameter> listOfPara = null;
            List <System.Data.SQLite.SQLiteParameter> listOfPara2 = null;

            try
            {
                string sql;
                if (isShort)
                {
                    sql = "SELECT AppFunctionId,UniqueName,DisplayName,ActionName,ControllerName,ParentId,AppFuncLevelId FROM AppFunctions WHERE AppFuncLevelId=@AppFuncLevelId AND ParentId=@ParentId" + (IsNavItem.HasValue ? " AND IsNavItem=@IsNavItem" : "") + " ORDER BY SequentialNum,DisplayName,UniqueName";
                }
                else
                {
                    sql = "SELECT * FROM AppFunctions WHERE AppFuncLevelId=@AppFuncLevelId AND ParentId=@ParentId" + (IsNavItem.HasValue ? " AND IsNavItem=@IsNavItem" : "") + " ORDER BY SequentialNum,DisplayName,UniqueName";
                }
                if (DbHandler.IsMssqlConnected)
                {
                    listOfPara = new List <SqlParameter>()
                    {
                        new SqlParameter("@AppFuncLevelId", SqlDbType.Int)
                        {
                            Value = AppFuncLevelId
                        },
                        new SqlParameter("@ParentId", SqlDbType.Int)
                        {
                            Value = ParentId
                        }
                    };
                    if (IsNavItem.HasValue)
                    {
                        listOfPara.Add(new SqlParameter("@IsNavItem", SqlDbType.Bit)
                        {
                            Value = IsNavItem.GetValueOrDefault()
                        });
                    }
                    dt = DbHandler.MSSQL.SelectDataTable(sql, listOfPara.ToArray());
                }
                else
                {
                    listOfPara2 = new List <System.Data.SQLite.SQLiteParameter>()
                    {
                        new System.Data.SQLite.SQLiteParameter("@AppFuncLevelId", DbType.Int32)
                        {
                            Value = AppFuncLevelId
                        },
                        new System.Data.SQLite.SQLiteParameter("@ParentId", DbType.Int32)
                        {
                            Value = ParentId
                        }
                    };
                    if (IsNavItem.HasValue)
                    {
                        listOfPara2.Add(new System.Data.SQLite.SQLiteParameter("@IsNavItem", DbType.Boolean)
                        {
                            Value = IsNavItem.GetValueOrDefault()
                        });
                    }
                    dt = DbHandler.SQLite.SelectDataTable(sql, listOfPara2.ToArray());
                }
                if ((dt?.Rows.Count ?? 0) < 1)
                {
                    return(null);
                }
                List <Models.AppFunction> rList = new List <Models.AppFunction>();
                foreach (DataRow dr in dt.Rows)
                {
                    Models.AppFunction o = Mapping(dr);
                    if (o != null)
                    {
                        //o.ParentId = ParentId;
                        //o.AppFuncLevelId = AppFuncLevelId;
                        o.ChildList = GetList(AppFuncLevelId + 1, o.AppFunctionId, IsNavItem, isShort);
                        rList.Add(o);
                    }
                }
                return(rList);
            }
            finally
            {
                DbHandler.DisposeDataTable(ref dt);
                if (listOfPara != null)
                {
                    listOfPara.Clear(); listOfPara = null;
                }
                if (listOfPara2 != null)
                {
                    listOfPara2.Clear(); listOfPara2 = null;
                }
            }
        }
Beispiel #11
0
        /// Return value = number of records affected.
        public static int UpdateUnit(Models.AppFunction o)
        {
            //if (o == null) return -1;
            string sql = "UPDATE AppFunctions SET UniqueName=@UniqueName,DisplayName=@DisplayName" +
                         ",ControllerName=@ControllerName,ActionName=@ActionName,AppFuncLevelId=@AppFuncLevelId,ParentId=@ParentId,SequentialNum=@SequentialNum,IsNavItem=@IsNavItem" +
                         ",IsDisabled=@IsDisabled,UpdatedDt=GETDATE(),UpdatedBy=@UpdatedBy,Description=@Description" +
                         " WHERE AppFunctionId=@AppFunctionId";

            return(o == null ? -1 : (
                       DbHandler.IsMssqlConnected ?
                       DbHandler.MSSQL.ExecuteNonQuery(sql,
                                                       new SqlParameter("@AppFunctionId", SqlDbType.Int)
            {
                Value = o.AppFunctionId
            },
                                                       new SqlParameter("@UniqueName", SqlDbType.VarChar)
            {
                Value = DbHandler.GetObjectToDb(o.UniqueName)
            },
                                                       new SqlParameter("@DisplayName", SqlDbType.VarChar)
            {
                Value = DbHandler.GetObjectToDb(o.DisplayName)
            },
                                                       new SqlParameter("@ControllerName", SqlDbType.VarChar)
            {
                Value = DbHandler.GetObjectToDb(o.ControllerName)
            },
                                                       new SqlParameter("@ActionName", SqlDbType.VarChar)
            {
                Value = DbHandler.GetObjectToDb(o.ActionName)
            },
                                                       new SqlParameter("@AppFuncLevelId", SqlDbType.Int)
            {
                Value = o.AppFuncLevelId
            },
                                                       new SqlParameter("@ParentId", SqlDbType.Int)
            {
                Value = o.ParentId
            },
                                                       new SqlParameter("@SequentialNum", SqlDbType.Int)
            {
                Value = o.SequentialNum
            },
                                                       new SqlParameter("@IsDisabled", SqlDbType.Bit)
            {
                Value = o.IsDisabled
            },
                                                       new SqlParameter("@IsNavItem", SqlDbType.Bit)
            {
                Value = o.IsNavItem
            },
                                                       new SqlParameter("@UpdatedBy", SqlDbType.Int)
            {
                Value = o.UpdatedBy
            },
                                                       new SqlParameter("@Description", SqlDbType.VarChar)
            {
                Value = DbHandler.GetObjectToDb(o.Description)
            }
                                                       ):
                       DbHandler.SQLite.ExecuteNonQuery(sql,
                                                        new System.Data.SQLite.SQLiteParameter("@AppFunctionId", DbType.Int32)
            {
                Value = o.AppFunctionId
            },
                                                        new System.Data.SQLite.SQLiteParameter("@UniqueName", DbType.AnsiString)
            {
                Value = DbHandler.GetObjectToDb(o.UniqueName)
            },
                                                        new System.Data.SQLite.SQLiteParameter("@DisplayName", DbType.AnsiString)
            {
                Value = DbHandler.GetObjectToDb(o.DisplayName)
            },
                                                        new System.Data.SQLite.SQLiteParameter("@ControllerName", DbType.AnsiString)
            {
                Value = DbHandler.GetObjectToDb(o.ControllerName)
            },
                                                        new System.Data.SQLite.SQLiteParameter("@ActionName", DbType.AnsiString)
            {
                Value = DbHandler.GetObjectToDb(o.ActionName)
            },
                                                        new System.Data.SQLite.SQLiteParameter("@AppFuncLevelId", DbType.Int32)
            {
                Value = o.AppFuncLevelId
            },
                                                        new System.Data.SQLite.SQLiteParameter("@ParentId", DbType.Int32)
            {
                Value = o.ParentId
            },
                                                        new System.Data.SQLite.SQLiteParameter("@SequentialNum", DbType.Int32)
            {
                Value = o.SequentialNum
            },
                                                        new System.Data.SQLite.SQLiteParameter("@IsDisabled", DbType.Boolean)
            {
                Value = o.IsDisabled
            },
                                                        new System.Data.SQLite.SQLiteParameter("@IsNavItem", DbType.Boolean)
            {
                Value = o.IsNavItem
            },
                                                        new System.Data.SQLite.SQLiteParameter("@UpdatedBy", DbType.Int32)
            {
                Value = o.UpdatedBy
            },
                                                        new System.Data.SQLite.SQLiteParameter("@Description", DbType.AnsiString)
            {
                Value = DbHandler.GetObjectToDb(o.Description)
            }
                                                        )));
        }
Beispiel #12
0
        /// Insert the record.
        public static int InsertUnit(Models.AppFunction o)
        {
            string sql = "INSERT INTO AppFunctions (UniqueName,DisplayName,ControllerName,ActionName,AppFuncLevelId,ParentId,SequentialNum,IsDisabled,IsNavItem,CreatedDt,CreatedBy,UpdatedDt,UpdatedBy,Description) VALUES (@UniqueName,@DisplayName,@ControllerName,@ActionName,@AppFuncLevelId,@ParentId,@SequentialNum,@IsDisabled,@IsNavItem,GETDATE(),@CreatedBy,GETDATE(),@UpdatedBy,@Description)";

            return(o == null ? -1 : (
                       DbHandler.IsMssqlConnected ?
                       DbHandler.MSSQL.ExecuteNonQuery(sql,
                                                       new SqlParameter("@UniqueName", SqlDbType.VarChar)
            {
                Value = DbHandler.GetObjectToDb(o.UniqueName)
            },
                                                       new SqlParameter("@DisplayName", SqlDbType.VarChar)
            {
                Value = DbHandler.GetObjectToDb(o.DisplayName)
            },
                                                       new SqlParameter("@ControllerName", SqlDbType.VarChar)
            {
                Value = DbHandler.GetObjectToDb(o.ControllerName)
            },
                                                       new SqlParameter("@ActionName", SqlDbType.VarChar)
            {
                Value = DbHandler.GetObjectToDb(o.ActionName)
            },
                                                       new SqlParameter("@AppFuncLevelId", SqlDbType.Int)
            {
                Value = o.AppFuncLevelId
            },
                                                       new SqlParameter("@ParentId", SqlDbType.Int)
            {
                Value = o.ParentId
            },
                                                       new SqlParameter("@SequentialNum", SqlDbType.Int)
            {
                Value = o.SequentialNum
            },
                                                       new SqlParameter("@IsDisabled", SqlDbType.Bit)
            {
                Value = o.IsDisabled
            },
                                                       new SqlParameter("@IsNavItem", SqlDbType.Bit)
            {
                Value = o.IsNavItem
            },
                                                       //new SqlParameter("@CreatedDt", SqlDbType.DateTime) { Value = o.CreatedDt },
                                                       new SqlParameter("@CreatedBy", SqlDbType.Int)
            {
                Value = o.CreatedBy
            },
                                                       //new SqlParameter("@CreatedByDisplayName", SqlDbType.VarChar) { Value = o.CreatedByDisplayName },
                                                       //new SqlParameter("@UpdatedDt", SqlDbType.DateTime) { Value = o.UpdatedDt },
                                                       new SqlParameter("@UpdatedBy", SqlDbType.Int)
            {
                Value = o.UpdatedBy
            },
                                                       //new SqlParameter("@UpdatedByDisplayName", SqlDbType.VarChar) { Value = o.UpdatedByDisplayName },
                                                       new SqlParameter("@Description", SqlDbType.VarChar)
            {
                Value = DbHandler.GetObjectToDb(o.Description)
            }
                                                       ):
                       DbHandler.SQLite.ExecuteNonQuery(sql,
                                                        new System.Data.SQLite.SQLiteParameter("@UniqueName", DbType.AnsiString)
            {
                Value = DbHandler.GetObjectToDb(o.UniqueName)
            },
                                                        new System.Data.SQLite.SQLiteParameter("@DisplayName", DbType.AnsiString)
            {
                Value = DbHandler.GetObjectToDb(o.DisplayName)
            },
                                                        new System.Data.SQLite.SQLiteParameter("@ControllerName", DbType.AnsiString)
            {
                Value = DbHandler.GetObjectToDb(o.ControllerName)
            },
                                                        new System.Data.SQLite.SQLiteParameter("@ActionName", DbType.AnsiString)
            {
                Value = DbHandler.GetObjectToDb(o.ActionName)
            },
                                                        new System.Data.SQLite.SQLiteParameter("@AppFuncLevelId", DbType.Int32)
            {
                Value = DbHandler.GetObjectToDb(o.AppFuncLevelId)
            },
                                                        new System.Data.SQLite.SQLiteParameter("@ParentId", DbType.Int32)
            {
                Value = DbHandler.GetObjectToDb(o.ParentId)
            },
                                                        new System.Data.SQLite.SQLiteParameter("@SequentialNum", DbType.Int32)
            {
                Value = DbHandler.GetObjectToDb(o.SequentialNum)
            },
                                                        new System.Data.SQLite.SQLiteParameter("@IsDisabled", DbType.Boolean)
            {
                Value = DbHandler.GetObjectToDb(o.IsDisabled)
            },
                                                        new System.Data.SQLite.SQLiteParameter("@IsNavItem", DbType.Boolean)
            {
                Value = DbHandler.GetObjectToDb(o.IsNavItem)
            },
                                                        //new System.Data.SQLite.SQLiteParameter("@CreatedDt", DbType.DateTime) { Value = DbHandler.GetObjectToDb(o.CreatedDt) },
                                                        new System.Data.SQLite.SQLiteParameter("@CreatedBy", DbType.Int32)
            {
                Value = DbHandler.GetObjectToDb(o.CreatedBy)
            },
                                                        //new System.Data.SQLite.SQLiteParameter("@UpdatedDt", DbType.DateTime) { Value = DbHandler.GetObjectToDb(o.UpdatedDt) },
                                                        new System.Data.SQLite.SQLiteParameter("@UpdatedBy", DbType.Int32)
            {
                Value = DbHandler.GetObjectToDb(o.UpdatedBy)
            },
                                                        new System.Data.SQLite.SQLiteParameter("@Description", DbType.AnsiString)
            {
                Value = DbHandler.GetObjectToDb(o.Description)
            }
                                                        )));
        }