Пример #1
0
        public IActionResult AddUser(AddUser addUserModel)
        {
            if (addUserModel.Password.Equals(addUserModel.ReenterPassword))
            {
                using (var txn = _session.BeginTransaction())
                {
                    string UserName = addUserModel.UserName;
                    string Password = addUserModel.Password;
                    //string ReenterPassword = addUserModel.ReenterPassword;
                    string   Email   = addUserModel.Email;
                    string   Bio     = addUserModel.Bio;
                    DateTime DOB     = addUserModel.DOB;
                    Ctry     Country = addUserModel.Country;

                    User newUser = new User(UserName, Password, Email, Country, Bio, DOB);
                    _session.Save(newUser);
                    txn.Commit();
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", "Passwords Donot Match");
                return(View(addUserModel));
            }
        }
Пример #2
0
        public ActionResult AcceptGift(int Id)
        {
            Gift gift = _session.Get <Gift>(Id);
            Game game = _session.Get <Game>(gift.GameId);
            User user = _session.Get <User>(_context.UserId);

            if (user.GamesOwned.Contains <Game>(game))
            {
                ViewData["error"] = "You already own this game. Please return to sender";
                return(RedirectToAction("MyGifts"));
            }

            List <Game> gamesList = new List <Game> {
                game
            };

            using (var txn = _session.BeginTransaction())
            {
                user.GiftsOwned = user.GiftsOwned.Where(g => g.Id != gift.Id);
                user.GamesOwned = user.GamesOwned.Concat(gamesList);
                _session.SaveOrUpdate(user);
                txn.Commit();
            }

            ViewData["error"] = game.Title + " has been added to your library!";
            return(RedirectToAction("MyGifts"));
        }
Пример #3
0
        /// <summary>
        ///     Creates the specified parameters.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        public void Create(CreateUserParameters parameters)
        {
            parameters.Password = _crypto.Hash(parameters.Password);

            using (ITransaction trans = _session.BeginTransaction())
            {
                _session.CreateCommandProcedure("User_Create", parameters)
                .ExecuteUpdate();

                trans.Commit();
            }
        }
Пример #4
0
        private async Task <IActionResult> Remove <T>(int id) where T : class
        {
            try

            {
                using (NHibernate.ISession session = sessionFactory.OpenSession())
                    using (var transaction = session.BeginTransaction())
                    {
                        //DigitalOutputGroup s;s.
                        var @object = await session.CreateCriteria <T>().Add(Restrictions.Eq("Id", id)).UniqueResultAsync <T>();

                        if (@object == null)
                        {
                            return(BadRequest(ApiResult.BadRequest($"대상 ID {id}가 존재하지 않습니다")));
                        }
                        await session.DeleteAsync(@object);

                        await transaction.CommitAsync();

                        return(Ok(ApiResult.OK_200));
                    }
            }
            catch (Exception ex)
            {
                return(BadRequest(ApiResult.BadRequest(ex.Message)));
            }
        }
 /// <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
 }
Пример #6
0
        public List <User> GetUserByCouponCode(User user)
        {
            List <User> alstUser = new List <User>();

            try
            {
                using (NHibernate.ISession session = SessionFactory.GetNewSession())
                {
                    using (NHibernate.ITransaction transaction = session.BeginTransaction())
                    {
                        try
                        {
                            alstUser = session.CreateQuery("from User where CouponCode=:couponCode")
                                       .SetParameter("couponCode", user.CouponCode)
                                       .List <User>().ToList <User>();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : " + ex.StackTrace);
            }

            return(alstUser);
        }
Пример #7
0
        /********************/

        public List <User> testing()
        {
            using (NHibernate.ISession session = SessionFactory.GetNewSession())
            {
                using (NHibernate.ITransaction transaction = session.BeginTransaction())
                {
                    try
                    {
                        List <User> s = session.CreateQuery("from User").List <User>().ToList <User>();
                        return(s);
                        //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);
                    }
                }
            }
        }
Пример #8
0
 public static void UpdateAccountType(User user)
 {
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             try
             {
                 int i = session.CreateQuery("Update User set ProfileUrl =:profileurl, UserName =: username , EmailId=:emailid,AccountType=:accounttype,UserStatus=:userstatus,ExpiryDate=:expirydate,TimeZone=:timezone where Id = :twtuserid")
                         .SetParameter("twtuserid", user.Id)
                         .SetParameter("profileurl", user.ProfileUrl)
                         .SetParameter("username", user.UserName)
                         .SetParameter("emailid", user.EmailId)
                         .SetParameter("accounttype", user.AccountType)
                         .SetParameter("userstatus", user.UserStatus)
                         .SetParameter("expirydate", user.ExpiryDate)
                         .SetParameter("timezone", user.TimeZone)
                         .ExecuteUpdate();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
             }
         }
     }
 }
Пример #9
0
 public void SetUserByUserId(string emailid, string password, Guid id, string username, string accounttype, string couponcode)
 {
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             try
             {
                 int i = session.CreateQuery("Update User set EmailId=:email, UserName =: username, Password =:pass, AccountType= :acctype,CouponCode=:couponCode where Id = :twtuserid")
                         .SetParameter("twtuserid", id)
                         .SetParameter("email", emailid)
                         .SetParameter("pass", password)
                         .SetParameter("acctype", accounttype)
                         .SetParameter("username", username)
                         .SetParameter("couponCode", couponcode)
                         .ExecuteUpdate();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
             }
         }
     }
 }
Пример #10
0
 /// <updateTaskStatus>
 /// update Task Status
 /// </summary>
 /// <param name="TaskId">Task id.(guid)</param>
 /// <param name="UserId">User id.(Guid)</param>
 /// <param name="status">Status.(Bool)</param>
 public void updateTaskStatus(Guid TaskId, 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())
         {
             try
             {
                 //Proceed action, to get Task status and completion date by user id and task id.
                 session.CreateQuery("Update Tasks set TaskStatus=:TaskStatus, CompletionDate=:completedate where Id = :taskid and UserId = :userid")
                 .SetParameter("userid", UserId)
                 .SetParameter("taskid", TaskId)
                 .SetParameter("TaskStatus", status)
                 .SetParameter("completedate", DateTime.Now)
                 .ExecuteUpdate();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
                 // return 0;
             }
         } //End Transaction
     }     //End Session
 }
Пример #11
0
        /// <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
        }
Пример #12
0
        //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 Create(Anexos anexo, HttpPostedFileBase file = null)
 {
     try
     {
         using (NHibernate.ISession session = NHibernateHelper.AbreSessao())
         {
             if (file != null)
             {
                 var arquivo = Request.Files[0];
                 var nomeArquivo = "Arq" + DateTime.Now.Millisecond.ToString() + ".pdf";
                 if (arquivo != null && arquivo.ContentLength() > 0)
                 {
                     anexo.Caminho_Arquivo = Path.Combine(dirArquivos, file.FileName);
                     var path = Path.Combine(dirArquivos, Path.GetFileName(file.FileName));
                     arquivo.SaveAs(path);
                 }
             }
             using (ITransaction transacao = session.BeginTransaction())
             {
                 session.Save(anexo);
                 transacao.Commit();
             }
         }
         return RedirectToAction(nameof(Index));
     }
     catch
     {
         return View();
     }
 }
Пример #14
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                Expense expense = new Expense();
                expense.account   = collection["title"].ToString();
                expense.amount    = Convert.ToInt32(collection["amount"]);
                expense.category  = collection["category"].ToString();
                expense.colorCode = collection["colorCode"].ToString();
                expense.date      = DateTime.Parse(collection["date"]);
                //expense.id = Convert.ToInt32(collection["id"]);
                expense.impulse = bool.Parse(collection["impulse"]);
                expense.memo    = collection["memo"].ToString();
                expense.payee   = collection["payee"].ToString();
                expense.repeat  = bool.Parse(collection["repeat"]);

                using (ISession session = _nHibernateSession.OpenSession())
                {
                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        session.Save(expense);
                        transaction.Commit();
                    }
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                return(View());
            }
        }
Пример #15
0
        public int UpdateQuery(GroupCampaign groupCamp)
        {
            using (NHibernate.ISession session = SessionFactory.GetNewSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    var query = session.CreateQuery("Update GroupCampaign set Account=:Account,PicFilePath=:PicFilePath,VideoFilePath=:VideoFilePath,MessageFilepath=:MessageFilepath,ScheduleTime=:ScheduleTime,CmpStartTime=:CmpStartTime,Accomplish=:Accomplish,NoOfMessage=:NoOfMessage,MessageMode=:MessageMode,MessageType=:MessageType,TextMessage=:TextMessage where GroupCampaignName=:GroupCampaignName and Module =:module");
                    //session.SaveOrUpdate(groupCamp);
                    query.SetParameter("GroupCampaignName", groupCamp.GroupCampaignName);
                    query.SetParameter("Account", groupCamp.Account);
                    query.SetParameter("PicFilePath", groupCamp.PicFilePath);
                    query.SetParameter("VideoFilePath", groupCamp.VideoFilePath);
                    query.SetParameter("MessageFilepath", groupCamp.MessageFilePath);
                    query.SetParameter("ScheduleTime", groupCamp.ScheduleTime);
                    query.SetParameter("CmpStartTime", groupCamp.CmpStartTime);
                    query.SetParameter("Accomplish", groupCamp.Accomplish);
                    query.SetParameter("NoOfMessage", groupCamp.NoOfMessage);

                    query.SetParameter("MessageMode", groupCamp.MessageMode);
                    query.SetParameter("MessageType", groupCamp.MessageType);
                    query.SetParameter("TextMessage", groupCamp.TextMessage);
                    query.SetParameter("module", groupCamp.Module);
                    int res = query.ExecuteUpdate();
                    transaction.Commit();
                    return(res);
                }
            }
        }
Пример #16
0
        public User getUserInfoByEmail(string emailId)
        {
            List <User> lstUser = new List <User>();
            User        user    = new User();

            using (NHibernate.ISession session = SessionFactory.GetNewSession())
            {
                using (NHibernate.ITransaction transaction = session.BeginTransaction())
                {
                    try
                    {
                        lstUser = session.CreateQuery("from  User u where u.EmailId = : email")
                                  .SetParameter("email", emailId).List <User>().ToList <User>();
                        user = lstUser[0];
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                        user = null;
                    }
                }
            }

            return(user);
        }
Пример #17
0
        public int UpdateUserExpiryDateById(User user)
        {
            int i = 0;

            try
            {
                using (NHibernate.ISession session = SessionFactory.GetNewSession())
                {
                    using (NHibernate.ITransaction transaction = session.BeginTransaction())
                    {
                        try
                        {
                            i = session.CreateQuery("Update User set ExpiryDate=:expirydate, AccountType=:accounttype where Id = :id")
                                .SetParameter("id", user.Id)
                                .SetParameter("accounttype", user.AccountType)
                                .SetParameter("expirydate", user.ExpiryDate)
                                .ExecuteUpdate();
                            transaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }

            return(i);
        }
Пример #18
0
 /// <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
 }
Пример #19
0
        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);
                    }
                }
            }
        }
Пример #20
0
        /// <getTasksByUserwithDetail>
        /// Get Tasks By User with Detail
        /// </summary>
        /// <param name="USerId">User id.(Guid)</param>
        /// <param name="days">Number of Days.(int)</param>
        /// <returns>Return values in the form of array list.(ArrayList)</returns>
        public ArrayList getTasksByUserwithDetail(Guid USerId, int days, 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 details of task. //ts.UserId=:userid and //.SetParameter("userid", USerId)
                    //var queryString = @"SELECT * FROM Tasks ts LEFT JOIN User u on ts.AssignTaskTo=u.Id where ts.UserId=:userid and AssignDate>=DATE_ADD(NOW(),INTERVAL -" + days + " DAY)";
                    //var queryString = @"SELECT * FROM Tasks ts LEFT JOIN User u on ts.AssignTaskTo=u.Id where ts.GroupId=:GroupId and  AssignDate>=DATE_ADD(NOW(),INTERVAL -" + days + " DAY)";
                    try
                    {
                        var queryString = @"select * from tasks where (AssignTaskTo =:userid or UserId =:userid) and GroupId =:GroupId and  AssignDate>=DATE_ADD(NOW(),INTERVAL -" + days + " DAY)";
                        var query       = session.CreateSQLQuery(queryString)
                                          .SetParameter("userid", USerId)
                                          .SetParameter("GroupId", GroupId);
                        //.SetParameter("GroupId", GroupId);

                        ArrayList alstTask = new ArrayList();

                        foreach (var item in query.List())
                        {
                            alstTask.Add(item);
                        }
                        return(alstTask);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                } //End Transaction
            }     //End Session
        }
Пример #21
0
        public int UpdatePaymentStatusByUserId(User user)
        {
            int i = 0;

            try
            {
                using (NHibernate.ISession session = SessionFactory.GetNewSession())
                {
                    using (NHibernate.ITransaction transaction = session.BeginTransaction())
                    {
                        try
                        {
                            i = session.CreateQuery("Update User set PaymentStatus=:paymentStatus  where Id = :userid")
                                .SetParameter("userid", user.Id)
                                .SetParameter("paymentStatus", user.PaymentStatus)
                                .ExecuteUpdate();
                            transaction.Commit();
                        }
                        catch { }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : " + ex.StackTrace);
            }

            return(i);
        }
Пример #22
0
        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);
        }
Пример #23
0
        //public int ResetPassword(Guid id, string password)
        //{
        //    using (NHibernate.ISession session = SessionFactory.GetNewSession())
        //    {
        //        using (NHibernate.ITransaction transaction = session.BeginTransaction())
        //        {
        //            try
        //            {
        //                int i = session.CreateQuery("Update User set Password =:pass where Id = :userid")
        //                          .SetParameter("userid", id)
        //                          .SetParameter("pass", password)
        //                          .ExecuteUpdate();
        //                transaction.Commit();
        //                return i;

        //            }
        //            catch (Exception ex)
        //            {
        //                Console.WriteLine(ex.StackTrace);
        //                return 0;
        //            }


        //        }
        //    }

        //}



        public List <User> GetAllUsersByCreateDate(string date)
        {
            List <User> alstUser = new List <User>();

            try
            {
                using (NHibernate.ISession session = SessionFactory.GetNewSession())
                {
                    using (NHibernate.ITransaction transaction = session.BeginTransaction())
                    {
                        try
                        {
                            alstUser = session.CreateQuery("from User where CreateDate < '2014-02-10' order by CreateDate desc").List <User>().ToList <User>();
                            //.SetParameter("date", date).List<User>().ToList<User>();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                            return(null);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : " + ex.StackTrace);
            }

            return(alstUser);
        }
Пример #24
0
 /// <updateTask>
 /// Update Task
 /// </summary>
 /// <param name="task">Set Values in a Tasks Class Property and Pass the Object of Tasks Class.(Domein.Tasks)</param>
 public void updateTask(Domain.Socioboard.Domain.Tasks task)
 {
     //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 update task
                 session.CreateQuery("Update Tasks set TaskMessage =:TaskMessage,UserId =:UserId,AssignTaskTo =:AssignTaskTo,TaskStatus=:TaskStatus,AssignDate=:AssignDate where Id = :taskid and UserId = :userid")
                 .SetParameter("TaskMessage", task.TaskMessage)
                 .SetParameter("UserId", task.UserId)
                 .SetParameter("AssignTaskTo", task.AssignTaskTo)
                 .SetParameter("TaskStatus", task.TaskStatus)
                 .SetParameter("AssignDate", task.AssignDate)
                 .SetParameter("taskid", task.Id)
                 .SetParameter("userid", task.UserId)
                 .ExecuteUpdate();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
                 // return 0;
             }
         } //End Transaction
     }     //End Session
 }
Пример #25
0
        public int UpdateReferenceUserByUserId(User user)
        {
            int i = 0;

            try
            {
                using (NHibernate.ISession session = SessionFactory.GetNewSession())
                {
                    using (NHibernate.ITransaction transaction = session.BeginTransaction())
                    {
                        try
                        {
                            i = session.CreateQuery("Update User set ReferenceStatus =:referenceStatus where Id = :id")
                                .SetParameter("referenceStatus", user.ReferenceStatus)
                                .SetParameter("id", user.Id)

                                .ExecuteUpdate();
                            transaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }

            return(i);
        }
Пример #26
0
        public int  UpdateCreatDateByUserId(User user)
        {
            int i = 0;

            try
            {
                using (NHibernate.ISession session = SessionFactory.GetNewSession())
                {
                    using (NHibernate.ITransaction transaction = session.BeginTransaction())
                    {
                        try
                        {
                            i = session.CreateQuery("Update User set CreateDate =:createDate, AccountType =: accountType , PaymentStatus=:paymentStatus where Id = :id")
                                .SetParameter("createDate", user.CreateDate)
                                .SetParameter("accountType", user.AccountType)
                                .SetParameter("paymentStatus", user.PaymentStatus)
                                .SetParameter("id", user.Id)
                                .ExecuteUpdate();
                            transaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }

            return(i);
        }
Пример #27
0
        /// <getResultsFromKeyword>
        /// Get result from database by keyword
        /// </summary>
        /// <param name="keyword">Keyword of DiscoverySearch(string)</param>
        /// <returns>List of all results by Keyword</returns>
        public List <Domain.Socioboard.Domain.DiscoverySearch> getResultsFromKeyword(string keyword)
        {
            //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 all results by Keyword.
                        List <Domain.Socioboard.Domain.DiscoverySearch> lst = session.CreateQuery("from DiscoverySearch where SearchKeyword = :keyword")
                                                                              .SetParameter("keyword", keyword)
                                                                              .List <Domain.Socioboard.Domain.DiscoverySearch>()
                                                                              .ToList <Domain.Socioboard.Domain.DiscoverySearch>();

                        #region Oldcode
                        //foreach (DiscoverySearch item in query.Enumerable())
                        //{
                        //    lst.Add(item);
                        //}
                        #endregion
                        return(lst);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                        return(null);
                    }
                } //End Transaction
            }     //End session
        }
Пример #28
0
 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);
             }
         }
     }
 }
Пример #29
0
        public System.Collections.Generic.IList <EventoEN> ReadAllDefault(int first, int size, NHibernate.ISession session)
        {
            System.Collections.Generic.IList <EventoEN> result = null;
            try
            {
                using (ITransaction tx = session.BeginTransaction())
                {
                    if (size > 0)
                    {
                        result = session.CreateCriteria(typeof(EventoEN)).
                                 SetFirstResult(first).SetMaxResults(size).List <EventoEN>();
                    }
                    else
                    {
                        result = session.CreateCriteria(typeof(EventoEN)).List <EventoEN>();
                    }
                }
            }

            catch (Exception ex) {
                SessionRollBack();
                if (ex is NuevoInmueblateGenNHibernate.Exceptions.ModelException)
                {
                    throw ex;
                }
                throw new NuevoInmueblateGenNHibernate.Exceptions.DataLayerException("Error in EventoCAD.", ex);
            }

            return(result);
        }
Пример #30
0
        public int ChangePassword(string newpassword, string oldpassword, string Emailid)
        {
            using (NHibernate.ISession session = SessionFactory.GetNewSession())
            {
                using (NHibernate.ITransaction transaction = session.BeginTransaction())
                {
                    try
                    {
                        //NHibernate.IQuery query = session.CreateQuery("Update User set Password=:password where EmailId = :email and Password = :oldpass");
                        //query.SetParameter("email", Emailid);
                        //query.SetParameter("oldpass",oldpassword);
                        //query.SetParameter("password",newpassword);
                        //query.ExecuteUpdate();

                        int i = session.CreateQuery("Update User set Password=:password where EmailId = :email and Password = :oldpass")
                                .SetParameter("email", Emailid)
                                .SetParameter("oldpass", oldpassword)
                                .SetParameter("password", newpassword)
                                .ExecuteUpdate();
                        transaction.Commit();
                        return(i);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                        return(0);
                    }
                }
            }
        }