public List <Domain.Socioboard.Domain.Tasks> getAllTasksOfUserBYDays(Guid Userid, Guid GroupId, int days) { List <Domain.Socioboard.Domain.Tasks> alstTask = new List <Domain.Socioboard.Domain.Tasks>(); try { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { DateTime AssignDate = DateTime.Now; string AssinDate = AssignDate.AddDays(-days).ToString("yyyy-MM-dd HH:mm:ss"); //Proceed action, to get all task of user. //NHibernate.IQuery query = session.CreateQuery("from Tasks where (UserId = :Userid or AssignTaskTo =:Userid) and GroupId =:GroupId and AssignDate>=DATE_ADD(NOW(),INTERVAL -" + days + " DAY)"); NHibernate.IQuery query = session.CreateQuery("from Tasks where UserId = :Userid and GroupId =:GroupId and AssignDate>=:AssinDate"); query.SetParameter("Userid", Userid); query.SetParameter("GroupId", GroupId); query.SetParameter("AssinDate", AssinDate); foreach (var item in query.Enumerable()) { alstTask.Add((Domain.Socioboard.Domain.Tasks)item); } } //End Transaction } //End Session } catch (Exception ex) { Console.WriteLine("Error : " + ex.StackTrace); } return(alstTask); }
/// <checkTaskExists> /// checkTaskExists /// </summary> /// <param name="TaskId">Task id.(String)</param> /// <param name="Userid">User id.(Guid)</param> /// <returns>True and False.(bool)</returns> public bool checkTaskExists(string TaskId, Guid Userid) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { try { //Proceed action, to get task details by userid and task id. NHibernate.IQuery query = session.CreateQuery("from Task where UserId = :userid and Id = :taskid"); query.SetParameter("userid", Userid); query.SetParameter("taskid", TaskId); var result = query.UniqueResult(); if (result == null) { return(false); } else { return(true); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(true); } } //End Transaction } //End Session }
public bool IsUserExist(string Emailid) { using (NHibernate.ISession session = SessionFactory.GetNewSession()) { using (NHibernate.ITransaction transaction = session.BeginTransaction()) { try { NHibernate.IQuery query = session.CreateQuery("from User u where u.EmailId = : email"); query.SetParameter("email", Emailid); var result = query.UniqueResult(); if (result == null) { return(false); } else { return(true); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(true); } } } }
/// <summary> /// Gets the entity list from respersitory. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="hQuery">The hibernate query string.</param> /// <param name="paras">The parameters in the query string,a dictionary,its key represent the parameter name,and its value is the parameter value.</param> /// <returns></returns> public IList <T> GetList <T>(string hQuery, Dictionary <string, object> paras) { try { OpenConnect(); Hib.IQuery query = _Session.CreateQuery(hQuery); if (paras != null) { foreach (string key in paras.Keys) { query.SetParameter(key, paras[key]); } } return(query.List <T>()); } catch (Exception ex) { LogExepttion(ex); throw; } finally { Disconnect(); } }
public List <User> getAllUsers() { using (NHibernate.ISession session = SessionFactory.GetNewSession()) { using (NHibernate.ITransaction transaction = session.BeginTransaction()) { try { NHibernate.IQuery query = session.CreateQuery("from User where Id !=null"); List <User> alstUser = new List <User>(); foreach (User item in query.Enumerable()) { alstUser.Add(item); } return(alstUser); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(null); } } } }
/// <DeleteDiscoverySearchByUserid> /// Delete DiscoverySearch from database by userId(Guid) /// </summary> /// <param name="userid">UserId of DiscoverySearch(Guid)</param> /// <returns>Return integer 1 for true 0 for false</returns> public int DeleteDiscoverySearchByUserid(Guid userid) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { try { //Proceed action to delete discoverysearch by userid. NHibernate.IQuery query = session.CreateQuery("delete from DiscoverySearch where UserId = :userid") .SetParameter("userid", userid); int isUpdated = query.ExecuteUpdate(); transaction.Commit(); return(isUpdated); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(0); } } //End Transaction } //End session }
//public ArrayList getAllTasksOfUser(Guid UserId) //{ // ArrayList alstTask = new ArrayList(); // try // { // //Creates a database connection and opens up a session // using (NHibernate.ISession session = SessionFactory.GetNewSession()) // { // //After Session creation, start Transaction. // using (NHibernate.ITransaction transaction = session.BeginTransaction()) // { // //Proceed action, to get all task of user. // NHibernate.IQuery query = session.CreateQuery("from Tasks where UserId = :UserId and AssignTaskTo !=:UserId"); // query.SetParameter("UserId", UserId); // query.SetParameter("UserId", UserId); // //query.SetParameter("GroupId", GroupId); // foreach (var item in query.Enumerable()) // { // alstTask.Add(item); // } // }//End Transaction // }//End Session // } // catch (Exception ex) // { // Console.WriteLine("Error : " + ex.StackTrace); // } // return alstTask; //} public ArrayList getAllTasksOfUser(Guid UserId) { ArrayList alstTask = new ArrayList(); try { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { //Proceed action, to get all task of user. NHibernate.IQuery query = session.CreateQuery("from Tasks where UserId = :UserId "); query.SetParameter("UserId", UserId); query.SetParameter("UserId", UserId); //query.SetParameter("GroupId", GroupId); foreach (var item in query.Enumerable()) { alstTask.Add(item); } } //End Transaction } //End Session } catch (Exception ex) { Console.WriteLine("Error : " + ex.StackTrace); } return(alstTask); }
public ActionResult Registration(Models.RegistrationModel reg_model) { if (Session["session_key"] != null) { return(RedirectToAction("index")); } using (NHibernate.ISession session = NHibernateSessionManeger.OpenSession()) { if (!ModelState.IsValid) { return(View()); } else { NHibernate.IQuery query = session.CreateQuery("FROM Users WHERE name = '" + reg_model.Name + "'"); if (query.List <Models.Users>().Count() > 0) { ViewData["ErrorMessage"] = " Пользователь с ником " + reg_model.Name + " уже занят "; return(View()); } var usr = new Models.Users(); usr.Email = reg_model.Email; usr.Name = reg_model.Name; var salt = Guid.NewGuid().ToByteArray(); string hashsed_password = Convert.ToBase64String(CryptSharp.Utility.SCrypt.ComputeDerivedKey(System.Text.UTF8Encoding.UTF8.GetBytes(reg_model.Password), salt, 16384, 8, 1, null, 128)); usr.HashPassword = hashsed_password; usr.Salt = Convert.ToBase64String(salt); session.Save(usr); return(RedirectToAction("authorization")); } } }
/// <summary> /// 通过EPCID查询 /// </summary> /// <param name="sql"></param> /// <param name="isSetSupplier"></param> /// <param name="isSetSpec"></param> /// <returns></returns> public AscmContainer GetByEpcId(string epcId, string sessionKey = null) { AscmContainer ascmContainer = null; try { NHibernate.ISession session = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession(); if (sessionKey != null) { session = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession(sessionKey); } NHibernate.IQuery query = session.CreateQuery("from AscmContainer where rfid='" + epcId + "' "); if (query.List().Count > 0) { ascmContainer = query.UniqueResult <AscmContainer>(); if (!string.IsNullOrEmpty(ascmContainer.supplierId.ToString())) { ascmContainer.supplier = MideaAscm.Services.Base.AscmSupplierService.GetInstance().Get(ascmContainer.supplierId, sessionKey); } if (!string.IsNullOrEmpty(ascmContainer.specId.ToString())) { ascmContainer.containerSpec = MideaAscm.Services.SupplierPreparation.AscmContainerSpecService.GetInstance().Get(ascmContainer.specId, sessionKey); } } } catch (Exception ex) { YnBaseClass2.Helper.LogHelper.GetLog().Error("查询失败(Find AscmContainer)", ex); throw ex; } return(ascmContainer); }
/// <summary> /// 得到最新的一次流转记录 /// 根据EPCID得到 /// </summary> /// <param name="strEpcId">根据EPCID</param> /// <returns></returns> public string Get(string strEpcId) { try { using (NHibernate.ISession session = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession()) { if (session.IsOpen) { NHibernate.IQuery query = session.CreateQuery("from AscmTagLog where readTime in (select to_char(max(to_date(readTime,'yyyy-MM-dd HH24:mi:ss')),'yyyy-MM-dd HH24:mi:ss') from AscmTagLog where epcId='" + strEpcId + "' ) and epcId='" + strEpcId + "' "); AscmTagLog ascmTagLog = query.UniqueResult <AscmTagLog>(); if (ascmTagLog != null) { object obj = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select address from AscmReadingHead where id=" + ascmTagLog.readingHeadId + ""); ascmTagLog.place = obj.ToString(); return (YnBaseClass2.Helper.ObjectHelper.Serialize <AscmTagLog>(ascmTagLog)); } else { return(null); } } } } catch (Exception ex) { YnBaseClass2.Helper.LogHelper.GetLog().Error("查询失败(Get AscmContainer)", ex); throw ex; } return(null); }
/// <summary> /// 普通查询 /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="hql">查询语句</param> /// <returns></returns> public static List <T> GetEntitiesByHQL <T>(string hql) { BasicDataManipulation baseData = new BasicDataManipulation(); ISession Session = baseData.GetSession(); List <T> list = new List <T>(); if (Session == null) { throw new Exception("打开数据库连接失败!"); } try { NHibernate.IQuery query = Session.CreateQuery(hql); list = query.List <T>().ToList(); return(list); } catch (Exception ex) { LogAPI.Debug(ex); return(list); } finally { if (Session != null) { Session.Dispose(); Session = null; } } }
/// <deleteTask> /// Delete Task /// </summary> /// <param name="taskid">Task id.(String)</param> /// <param name="userid">User id.(Guid)</param> /// <returns>Return 1 for true and 0 for false.(int)</returns> public int deleteTask(string taskid, Guid userid) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { try { //Proceed action, to delete task by task id and user id. NHibernate.IQuery query = session.CreateQuery("delete from Task where Id = :taskid and UserId = :userid") .SetParameter("taskid", taskid) .SetParameter("userid", userid); int isUpdated = query.ExecuteUpdate(); transaction.Commit(); return(isUpdated); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(0); } } //End Transaction } //End Session }
public IList FindByMainId(string id) { NHibernate.ISession session = HibernateTemplate.SessionFactory.OpenSession(); NHibernate.IQuery query = session.CreateQuery("from MasterInfo m where m.InfoCode=:infoCode"); query.SetParameter("infoCode", id); return(query.List()); }
public IList <User> GetActorByRole(IEnumerable <string> ids) { using ISession session = DbFactory.OpenBussinessSession(); NHibernate.IQuery query = session .GetNamedQuery("queryActorByRole"); IList <User> users = query.SetParameterList("RIDS", ids).List <User>(); return(users); }
/// <summary> /// 分页查询 /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="hql">查询语句</param> /// <param name="skip">页数</param> /// <param name="take">每页显示条数</param> /// <param name="count">总数</param> /// <returns></returns> public static List <T> GetEntitiesByHQL <T>(string hql, int skip, int take, out int count) { BasicDataManipulation baseData = new BasicDataManipulation(); ISession Session = baseData.GetSession(); List <T> list = new List <T>(); if (Session == null) { throw new Exception("打开数据库连接失败!"); } try { NHibernate.IQuery query1 = Session.CreateQuery(hql); string hqlcount = ""; int fromIndex = hql.IndexOf("from"); int toIndex = hql.IndexOf("order"); int len = 0; if (toIndex == -1) { hqlcount = "select count(*) " + hql.Substring(fromIndex); } else { len = toIndex - fromIndex; hqlcount = "select count(*) " + hql.Substring(fromIndex, len); } NHibernate.IQuery querycount = Session.CreateQuery(hqlcount); try { count = int.Parse(querycount.UniqueResult().ToString()); } catch { count = 0; } NHibernate.IQuery query = query1.SetFirstResult(skip).SetMaxResults(take); list = query.List <T>().ToList(); return(list); } catch (Exception ex) { count = 0; LogAPI.Debug(ex); return(list); } finally { if (Session != null) { Session.Dispose(); Session = null; } } }
public Dal.ContainerManage.Entities.AscmCheck Get() { Dal.ContainerManage.Entities.AscmCheck ack = null; try { NHibernate.IQuery query = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().CreateQuery("from AscmCheck where id in (select max(id) from AscmCheck)"); ack = query.UniqueResult <Dal.ContainerManage.Entities.AscmCheck>(); } catch (Exception ex) { YnBaseClass2.Helper.LogHelper.GetLog().Error("查询失败(Get AscmCheck)", ex); throw ex; } return(ack); }
public IEnumerable <T> Get(NHibernate.IQuery query, int baseIndex, short pageSize, out int count, string sortFieldName, SortDirection sortDirection) { count = query.List <T>().Count; //if pageSize>0 then do paging, otherwise no paging and all records will be displayed if (pageSize > 0) { query.SetFirstResult(baseIndex) .SetMaxResults(pageSize) .SetMaxResults(pageSize); } IList <T> result = query.List <T>(); return(result); }
public int DeleteTaskOfGroup(Guid groupId) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { //Proceed action to delete task of user by groupId. NHibernate.IQuery query = session.CreateQuery("delete from Tasks where GroupId = :GroupId") .SetParameter("GroupId", groupId); int isUpdated = query.ExecuteUpdate(); transaction.Commit(); return(isUpdated); } } }
/// <getTaskById> /// Get Task By Id /// </summary> /// <param name="Taskid">Task id.(string)</param> /// <param name="userId">User id.(Guid)</param> /// <returns>Return object of Tasks Class with all Tasks info.(List<Tasks>)</returns> public Domain.Socioboard.Domain.Tasks getTaskById(string Taskid, Guid userId) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { //Proceed action, to get Account details by Fb user id and user id. NHibernate.IQuery query = session.CreateQuery("from FacebookAccount where FbUserId = :Fbuserid and UserId=:userId"); query.SetParameter("Fbuserid", Taskid); query.SetParameter("userId", userId); Domain.Socioboard.Domain.Tasks result = (Domain.Socioboard.Domain.Tasks)query.UniqueResult(); return(result); } //End Transaction } //End Session }
/// <summary> /// 2013/07/17 /// </summary> /// <param name="epc"></param> /// <returns></returns> public AscmRfid GetByEpc(string epcId) { AscmRfid ascmRfid = null; try { NHibernate.ISession session = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession(); NHibernate.IQuery query = session.CreateQuery("from AscmRfid where epcId='" + epcId + "' "); ascmRfid = query.UniqueResult <AscmRfid>(); } catch (Exception ex) { YnBaseClass2.Helper.LogHelper.GetLog().Error("查询失败(Get AscmRfid)", ex); throw ex; } return(ascmRfid); }
public IEnumerable <T> Get(NHibernate.IQuery query, int pageIndex, int pageSize, out int count, string sortFieldName, SortDirection sortDirection) { count = query.List <T>().Count; //if pageSize>0 then do paging, otherwise no paging and all records will be displayed if (pageSize > 0) { query.SetFirstResult((int)pageIndex * pageSize) .SetMaxResults(pageSize) .SetMaxResults(pageSize); } IList <T> result = query.List <T>(); //var rowCount = query.SetFirstResult(0).FutureValue<Int32>(); //count = rowCount.Value; return(result); }
public ArrayList getAllIncompleteTasksOfUsers(Guid UserId) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { //Proceed action, to get values by user id and where status is zero. NHibernate.IQuery query = session.CreateQuery("from Tasks where AssignTaskTo = :userid and TaskStatus = 0 and UserId!=:UserId"); query.SetParameter("userid", UserId); query.SetParameter("UserId", UserId); ArrayList alstTask = new ArrayList(); foreach (var item in query.Enumerable()) { alstTask.Add(item); } return(alstTask); } //End Transaction } //End Session }
public User getUsersById(Guid userId) { using (NHibernate.ISession session = SessionFactory.GetNewSession()) { using (NHibernate.ITransaction transaction = session.BeginTransaction()) { try { NHibernate.IQuery query = session.CreateQuery("from User where Id =: userid"); query.SetParameter("userid", userId); User usr = query.UniqueResult <User>(); return(usr); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(null); } } } }
// Edited by Antima public bool isKeywordPresentforNetwork(string keyword, string Network) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { try { //proceed action to check if keyword is present in database or not. // And Set the reuired paremeters to find the specific values. NHibernate.IQuery query = session.CreateQuery("from DiscoverySearch where SearchKeyword = :keyword and Network = :Network"); query.SetParameter("keyword", keyword); query.SetParameter("Network", Network); List <Domain.Socioboard.Domain.DiscoverySearch> lst = new List <Domain.Socioboard.Domain.DiscoverySearch>(); foreach (Domain.Socioboard.Domain.DiscoverySearch item in query.Enumerable()) { lst.Add(item); } if (lst.Count == 0) { return(false); } else { return(true); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(true); } } //End Transaction } //End session }
public int DeleteUserByUserid(Guid userid) { using (NHibernate.ISession session = SessionFactory.GetNewSession()) { using (NHibernate.ITransaction transaction = session.BeginTransaction()) { try { NHibernate.IQuery query = session.CreateQuery("delete from User where Id = :userid") .SetParameter("userid", userid); int isUpdated = query.ExecuteUpdate(); transaction.Commit(); return(isUpdated); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(0); } } } }
/// <getAllTasksOfUserByStatus> /// Get all tasks of user by status. /// </summary> /// <param name="UserId">User id.(Guid)</param> /// <param name="status">Status.(bool)</param> /// <returns>Return values in the form of array list.(ArrayList)</returns> public ArrayList getAllTasksOfUserByStatus(Guid UserId, bool status) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { //Proceed action, to get Tasks by user id and task status. NHibernate.IQuery query = session.CreateQuery("from Tasks where UserId = :userid and TaskStatus=:TaskStatus"); query.SetParameter("userid", UserId); query.SetParameter("TaskStatus", status); ArrayList alstTask = new ArrayList(); foreach (var item in query.Enumerable()) { alstTask.Add(item); } return(alstTask); } //End Transaction } //End Session }
public User GetUserInfo(string EmailId, string Password) { using (NHibernate.ISession session = SessionFactory.GetNewSession()) { using (NHibernate.ITransaction transaction = session.BeginTransaction()) { try { NHibernate.IQuery query = session.CreateQuery("from User u where u.EmailId = : email and u.Password= :password"); query.SetParameter("email", EmailId); query.SetParameter("password", Password); User result = (User)query.UniqueResult(); return(result); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(null); } } } }
/// <getAllTasksCommentOfUser> /// Get All Tasks Comment Of User /// </summary> /// <param name="UserId">User id.(Guid)</param> /// <param name="TaskId">Task id.(Guid)</param> /// <returns>Return Array list with value.(ArrayList)</returns> public ArrayList getAllTasksCommentOfUser(Guid TaskId) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { //Proceed action, to get Task comments by user id and task id. NHibernate.IQuery query = session.CreateQuery("from TaskComment where TaskId=:taskid"); // query.SetParameter("userid", UserId); query.SetParameter("taskid", TaskId); ArrayList alstTaskcomment = new ArrayList(); foreach (var item in query.Enumerable()) { alstTaskcomment.Add(item); } return(alstTaskcomment); } //End Transaction } //End Session }
/// <getAllMyTasksOfUser> /// Get All My Tasks Of User /// </summary> /// <param name="UserId">User id.(Guid)</param> /// <param name="AssignTo">Assign to.(Guid)</param> /// <returns>Return values in the form of array list.(ArrayList)</returns> public ArrayList getAllMyTasksOfUser(Guid AssignTo, Guid GroupId) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { //Proceed action, to get values by user id and assign task to. NHibernate.IQuery query = session.CreateQuery("from Tasks where AssignTaskTo=:AssignTo and GroupId=:GroupId"); //query.SetParameter("userid", UserId); query.SetParameter("AssignTo", AssignTo); query.SetParameter("GroupId", GroupId); ArrayList alstTask = new ArrayList(); foreach (var item in query.Enumerable()) { alstTask.Add(item); } return(alstTask); } //End Transaction } //End Session }
public ArrayList UnPaidUserCountByMonth() { using (NHibernate.ISession session = SessionFactory.GetNewSession()) { using (NHibernate.ITransaction transaction = session.BeginTransaction()) { ArrayList alstUser = new ArrayList(); try { NHibernate.IQuery query = session.CreateSQLQuery("Select month(CreateDate),Count(*) from User where PaymentStatus='unpaid' group by month(CreateDate)"); foreach (var item in query.List()) { alstUser.Add(item); } return(alstUser); } catch (Exception Err) { Console.Write(Err.StackTrace); return(alstUser); } } } }