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); } }
// 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; }
// GET api/<controller> //[ApiAuthorize] public UserInfo Get() { string query = "select * from userinfo"; DataSet aSet = aGateway.Select(query); List<UserInfo> userInfos = new List<UserInfo>(); UserInfo aUserInfo = new UserInfo(); foreach (DataRow dataRow in aSet.Tables[0].Rows) { aUserInfo.Id = Convert.ToInt32(dataRow["ID"].ToString()); aUserInfo.UserId = Convert.ToInt32(dataRow["UserID"].ToString()); aUserInfo.UserName = dataRow["UserName"].ToString(); aUserInfo.FullName = dataRow["FullName"].ToString(); aUserInfo.FatherName = dataRow["FatherName"].ToString(); aUserInfo.MotherName = dataRow["MotherName"].ToString(); aUserInfo.PhoneNumber = dataRow["CellNumber"].ToString(); aUserInfo.BirthDate = (DateTime)dataRow["BirthDay"]; aUserInfo.CurrentAddress = dataRow["CurrentAddress"].ToString(); aUserInfo.PermanentAddress = dataRow["PermanentAddress"].ToString(); aUserInfo.BirthCertificateID = dataRow["BirthCertificateID"].ToString(); } query = "select * from childInfo where ParentID=1"; DataSet anotherDataSet = aGateway.Select(query); List<ChildInfo> childList = new List<ChildInfo>(); foreach (DataRow dataRow in anotherDataSet.Tables[0].Rows) { ChildInfo aChildInfo = new ChildInfo(); aChildInfo.ID = Convert.ToInt32(dataRow["ID"].ToString()); aChildInfo.ParentID = Convert.ToInt32(dataRow["ParentID"].ToString()); aChildInfo.Name = dataRow["Name"].ToString(); aChildInfo.BirthCertificateID = dataRow["BirthCertificateID"].ToString(); aChildInfo.BirthDate = (DateTime)dataRow["Birthdate"]; childList.Add(aChildInfo); } aUserInfo.Childs = childList; return aUserInfo; }
public UserInfo Get(int id) { string query = "select * from userinfo where id=@id;"; string query1 = "select userinfo.ID,userinfo.UserID,userinfo.UserName,userinfo.FullName,userinfo.FatherName,userinfo.MotherName,userinfo.CellNumber,userinfo.BirthDay,userinfo.CurrentAddress,userinfo.PermanentAddress,userinfo.BirthCertificateID,users.UserRoleId from userinfo,users where userinfo.id=@id and users.ID=userInfo.UserId;"; Hashtable aTable = new Hashtable() { { "id", id } }; DataSet aSet = aGateway.Select(query1, aTable); List<UserInfo> userInfos = new List<UserInfo>(); UserInfo aUserInfo = new UserInfo(); foreach (DataRow dataRow in aSet.Tables[0].Rows) { aUserInfo.Id = Convert.ToInt32(dataRow["ID"].ToString()); aUserInfo.UserId = Convert.ToInt32(dataRow["UserID"].ToString()); aUserInfo.UserName = dataRow["UserName"].ToString(); aUserInfo.FullName = dataRow["FullName"].ToString(); aUserInfo.FatherName = dataRow["FatherName"].ToString(); aUserInfo.MotherName = dataRow["MotherName"].ToString(); aUserInfo.PhoneNumber = dataRow["CellNumber"].ToString(); aUserInfo.BirthDate = (DateTime)dataRow["BirthDay"]; aUserInfo.CurrentAddress = dataRow["CurrentAddress"].ToString(); aUserInfo.PermanentAddress = dataRow["PermanentAddress"].ToString(); aUserInfo.BirthCertificateID = dataRow["BirthCertificateID"].ToString(); aUserInfo.UserRole = Convert.ToInt32(dataRow["UserRoleId"].ToString()); } query = "select * from childInfo where ParentID=1"; DataSet anotherDataSet = aGateway.Select(query); List<ChildInfo> childList = new List<ChildInfo>(); foreach (DataRow dataRow in anotherDataSet.Tables[0].Rows) { ChildInfo aChildInfo = new ChildInfo(); aChildInfo.ID = Convert.ToInt32(dataRow["ID"].ToString()); aChildInfo.ParentID = Convert.ToInt32(dataRow["ParentID"].ToString()); aChildInfo.Name = dataRow["Name"].ToString(); aChildInfo.BirthCertificateID = dataRow["BirthCertificateID"].ToString(); aChildInfo.BirthDate = (DateTime)dataRow["Birthdate"]; childList.Add(aChildInfo); } aUserInfo.Childs = childList; return aUserInfo; }