// GET api/<controller> public List<ChildInfo> Get(int id) { HttpSessionStateBase Session = (HttpSessionStateBase)HttpContext.Current.Session["SessionBackup"]; Dictionary<string, string> session = SessionHandler.GetSessionData(Session); string query = "select * from childinfo where parentid=@ParentId and ID=@Id;"; Hashtable aHashtable = new Hashtable(); aHashtable.Add("ParentId", session["UserId"]); aHashtable.Add("Id", id); DBGateway aGateway = new DBGateway(); DataSet aSet = aGateway.Select(query, aHashtable); ChildInfo aInfo = new ChildInfo(); List<ChildInfo> aList = new List<ChildInfo>(); foreach (DataRow aRow in aSet.Tables[0].Rows) { aInfo.ID = Convert.ToInt32(aRow["ID"].ToString()); aInfo.Name = aRow["Name"].ToString(); aInfo.ParentID = Convert.ToInt32(aRow["ParentID"].ToString()); aInfo.BirthCertificateID = aRow["BirthCertificateID"].ToString(); aInfo.MotherName = aRow["MotherName"].ToString(); aInfo.BirthDate = Convert.ToDateTime(aRow["Birthdate"].ToString()); } aList.Add(aInfo); return aList; }
public static bool ApiAuthenticate(Dictionary<string, string> sessionData, HttpSessionStateBase Session, System.Web.Http.Controllers.HttpActionContext actionContext) { string code = EncrDecrAction.Encrypt( EncrDecrAction.Encrypt(EncrDecrAction.Encrypt(Session["UserId"].ToString(), true), true) + EncrDecrAction.Encrypt(EncrDecrAction.Encrypt(Session["UserRoleId"].ToString(), true), true) + EncrDecrAction.Encrypt(EncrDecrAction.Encrypt(Session["UserName"].ToString(), true), true) + EncrDecrAction.Encrypt(EncrDecrAction.Encrypt(Session["RoleName"].ToString(), true), true) + EncrDecrAction.Encrypt(EncrDecrAction.Encrypt(Session["ParentRoleName"].ToString(), true), true), true); if (code == Session["SRES"].ToString()) { UrlHelper urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext); var routeValueDictionary = urlHelper.RequestContext.RouteData.Values; string controller = routeValueDictionary["controller"].ToString(); string action = actionContext.Request.Method.ToString(); int argument = actionContext.Request.RequestUri.Segments.Count() - 3; string query = "select * from appviews where LOWER(Controller) = LOWER(@Controller) and LOWER(Action) = LOWER(@Action) and " + sessionData["RoleName"] + "= 1 and Argument=@Argument and ControllerType='api'"; Hashtable conditionTable = new Hashtable(); conditionTable["Controller"] = controller; conditionTable["Action"] = action; conditionTable["Argument"] = argument; DBGateway aDbGateway = new DBGateway(); DataSet aDataSet = aDbGateway.Select(query, conditionTable); if (aDataSet.Tables[0].Rows.Count > 0) { return true; } } return false; }
public static List<MenuItem> GetMenuItemLists(HttpSessionStateBase Session) { Dictionary<string, string> sessionData = SessionHandler.GetSessionData(Session); List<MenuItem> menu = new List<MenuItem>(); DBGateway aGateway = new DBGateway(); DataSet aDataSet = aGateway.Select("select * from appmenuitems, appviews where appmenuitems.AppViewId = appviews.Id and " + sessionData["RoleName"] + " = 1 order by menuorder asc, submenuorder asc"); foreach (DataRow dataRow in aDataSet.Tables[0].Rows) { MenuItem aMenuItem = new MenuItem(); aMenuItem.Id = dataRow["Id"].ToString(); aMenuItem.MenuName = dataRow["MenuName"].ToString(); aMenuItem.MenuParentName = dataRow["MenuParentName"].ToString(); aMenuItem.Controller = dataRow["Controller"].ToString(); aMenuItem.Action = dataRow["Action"].ToString(); menu.Add(aMenuItem); } return menu; }
public static bool Authenticate(string userName, string cellNumber, HttpSessionStateBase Session) { DBAuthentication authentication = new DBAuthentication(userName, cellNumber); bool result = authentication.IsValid(); if (result == false) { return result; } DBGateway aDbGateway = new DBGateway(); Hashtable conditionTable = new Hashtable(); string query = "select * from users,roles where users.UserName='******' and users.UserCellNumber='" + cellNumber + "' and users.UserRoleId = roles.ID"; conditionTable["UserName"] = userName; DataSet aDataSet = aDbGateway.Select(query, conditionTable); aDataSet.Tables[0].Columns.Add("LogInValue"); aDataSet.Tables[0].Rows[0]["LogInValue"] = cellNumber; List<string> cols = new List<string>(); Dictionary<string,string> userData = new Dictionary<string, string>(); foreach (DataColumn column in aDataSet.Tables[0].Columns) { cols.Add(column.ColumnName); } foreach (DataRow row in aDataSet.Tables[0].Rows) { foreach (string col in cols) { userData.Add(col,row[col].ToString()); } } SessionHandler.SetSessionData(userData, Session); return true; }
public HttpResponseMessage Post(ChildInfo childInfo) { if (ModelState.IsValid) { HttpSessionStateBase Session = (HttpSessionStateBase)HttpContext.Current.Session["SessionBackup"]; Dictionary<string, string> session = SessionHandler.GetSessionData(Session); string query = "INSERT INTO `tikaappdb`.`childinfo` (`ParentID`, `Name`, `Birthdate`,`BirthCertificateID`,`MotherName`) " + "VALUES (@ParentId, @Name, @Date,@BirthCertificateID,@MotherName);"; Hashtable aHashtable = new Hashtable(); aHashtable.Add("ParentId", session["UserId"]); aHashtable.Add("Name", childInfo.Name); aHashtable.Add("Date", childInfo.BirthDate); aHashtable.Add("BirthCertificateID", childInfo.BirthCertificateID); aHashtable.Add("MotherName", childInfo.MotherName); DBGateway aGateway = new DBGateway(); aGateway.Insert(query, aHashtable); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, childInfo); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
public CenterPagingController() { aGateway = new DBGateway(); }
public UsersPagingController() { // demoContext = new DemoContext(); aGateway = new DBGateway(); }
public List<UserRole> GetRoleLevels(int roleID) { DBGateway aGateway=new DBGateway(); string query = "select * from roles;"; DataSet aDataSet = aGateway.Select(query); List<UserRole> userRoles = new List<UserRole>(); foreach (DataRow dataRow in aDataSet.Tables[0].Rows) { UserRole aUserRole = new UserRole(); aUserRole.Id = Convert.ToInt32(dataRow["ID"].ToString()); aUserRole.RoleName = dataRow["RoleName"].ToString(); aUserRole.ParentRoleName = dataRow["ParentRoleName"].ToString(); userRoles.Add(aUserRole); } List<UserRole> userRolesFinal = userRoles.Where(c => c.ParentRoleName == c.RoleName).ToList().Select(c => { c.Level = 0; return c; } ).ToList(); bool continueParse = true; List<UserRole> tempList = userRolesFinal; int j = 1; while (continueParse) { List<UserRole> childListLevel = new List<UserRole>(); foreach (UserRole aRole in tempList) { List<UserRole> childList = userRoles.Where(c => c.ParentRoleName == aRole.RoleName && !userRolesFinal.Any(p2 => p2.Id == c.Id)).ToList(); childList = childList.Select(c => { c.Level = j; return c; }).ToList(); if (childList.Count > 0) { childListLevel.AddRange(childList); } } if (childListLevel.Count > 0) { // userRolesFinal.AddRange(childListLevel); userRolesFinal = userRolesFinal.Concat(childListLevel).ToList(); tempList.Clear(); tempList.AddRange(childListLevel); childListLevel.Clear(); j++; } else { continueParse = false; } } int userLevel = userRolesFinal.Where(c => c.Id == roleID).First().Level; List<UserRole> removeRoles = userRolesFinal.Where(s => s.Level <= userLevel).ToList(); foreach (UserRole aRemovableRole in removeRoles) { if (aRemovableRole.Id != roleID) { userRolesFinal.Remove(aRemovableRole); } } return userRolesFinal; }