public bool CreateUser(User user)
 {
     using(var session = _factory.OpenSession())
     {
         using(var transaction = session.BeginTransaction())
         {
             try
             {
                 session.Save(user);
                 transaction.Commit();
                 return true;
             }
             catch(Exception ex)
             {
                 return false;
             }
         }
     }
 }
Esempio n. 2
0
 public virtual void RemoveAttendee(User attendee)
 {
     attendee.EventsAttended.Remove(this);
     Attendees.Remove(attendee);
 }
Esempio n. 3
0
 public virtual void AddSpeaker(User speaker)
 {
     speaker.EventsPresented.Add(this);
     Speakers.Add(speaker);
 }
Esempio n. 4
0
 public virtual void AddOrganizer(User organizer)
 {
     organizer.EventsOrganized.Add(this);
     Organizers.Add(organizer);
 }
Esempio n. 5
0
 public virtual void AddAttendee(User attendee)
 {
     attendee.EventsAttended.Add(this);
     Attendees.Add(attendee);
 }
Esempio n. 6
0
 public virtual void RemoveSpeaker(User speaker)
 {
     speaker.EventsPresented.Remove(this);
     Speakers.Remove(speaker);
 }
Esempio n. 7
0
 public virtual void RemoveOrganizer(User organizer)
 {
     organizer.EventsOrganized.Remove(this);
     Organizers.Remove(organizer);
 }
 public bool DeleteUser(User user)
 {
     using (var session = _factory.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             try
             {
                 session.Delete(user);
                 transaction.Commit();
                 return true;
             }
             catch
             {
                 return false;
             }
         }
     }
 }
        public IList<Event> GetUpcomingEventsForUser(User user, DateTime time)
        {
            IList<Event> events = null;

            using (var session = _factory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    events = session.CreateCriteria(typeof(Event))
                        .Add(NHibernate.Criterion.Restrictions.Ge("EventBeginDate", time))
                        .Add(NHibernate.Criterion.Restrictions.Le("RegistrationOpenDate", time))
                        .List<Event>();
                }
            }

            return events;
        }
        public void CanUpdateUserInRepository()
        {
            var user = new User
            {
                UserName = "******",
                Bio = "Heyoooooo",
                Email = "*****@*****.**",
                Password = "******",
                DateJoined = DateTime.Now,
                Blog = new Uri("http://blog.msdn.com/blog"),
                IsEnabled = true,
                IsPublic = true,
                EventsAttended = new List<Event>(),
                EventsOrganized = new List<Event>(),
                EventsPresented = new List<Event>(),
                Roles = new List<Role>()
            };

            user.AddRole(_roles[0]);

            _repository.CreateUser(user);

            var originalUserName = user.UserName.Clone();
            var newUserName = "******";
            user.UserName = newUserName;

            _repository.UpdateUser(user);

            var equivalentUser = _repository.GetUserById(user.UserId);
            Assert.AreEqual(newUserName, equivalentUser.UserName, "UserNames should be equivalent");
        }
        public void CanAddNewUserToRepository()
        {
            var user = new User
                           {
                               UserName = "******",
                               Bio = "HAR HAR HAR",
                               Email = "*****@*****.**",
                               Password = "******",
                               DateJoined = DateTime.Now,
                               IsEnabled = true,
                               IsPublic = true,
                               EventsAttended = new List<Event>(),
                               EventsOrganized = new List<Event>(),
                               EventsPresented = new List<Event>(),
                               Roles = new List<Role>()
                           };

            user.AddRole(_roles[0]);

            _repository.CreateUser(user);
            var users = _repository.GetAllUsers();
            var confirmUser = _repository.GetUserById(user.UserId);

            Assert.IsTrue(users.Count > _users.Count);
            Assert.AreEqual(user.UserId, confirmUser.UserId, "User Ids should be equivalent!");
        }
        public ActionResult Register(NewUser newUser)
        {
            if(ModelState.IsValid)
            {
                newUser.EmailAddress = Server.HtmlEncode(newUser.EmailAddress);
                newUser.UserName = Server.HtmlEncode(newUser.UserName);

                var user = new User
                               {
                                   UserName = newUser.UserName,
                                   Email = newUser.EmailAddress,
                                   Password = _passwordCrypto.EncodePassword(newUser.Password.Trim()),
                                   DateJoined = DateTime.Now,
                                   IsEnabled = true,
                                   IsPublic = true
                               };

                var result = _repository.CreateUser(user);

                if(result)
                {
                    _authentication.SignIn(newUser.UserName, true);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", "We were unable to register your account.");
                }

            }

            return View(newUser);
        }