예제 #1
0
        public void UpdateUser(WikiUser u)
        {
            __User updateUser = db.__Users.FirstOrDefault(x => x.ID == u.ID);

            if (updateUser != null)
            {
                updateUser.FirstName = u.FirstName;
                updateUser.LastName = u.LastName;
                updateUser.UserName = u.UserName;

                db.SubmitChanges();
            }
        }
예제 #2
0
        public void DeleteUser(WikiUser u)
        {
            __User deleteUser = db.__Users.FirstOrDefault(x => x.ID == u.ID);

            if (deleteUser != null)
            {
                db.__Users.DeleteOnSubmit(deleteUser);
                db.SubmitChanges();
            }
        }
예제 #3
0
        public void AddUser(WikiUser u)
        {
            __User _u = db.__Users.FirstOrDefault(x => x.Identifier == u.Identifier);

            if (_u == null)
            {
                _u = new __User()
                {
                    ID = u.ID,
                    FirstName = u.FirstName,
                    LastName = u.LastName,
                    UserName = u.UserName,
                    Identifier = u.Identifier
                };

                db.__Users.InsertOnSubmit(_u);
                db.SubmitChanges();
            }
        }
        public void UpdateUser(WikiUser u)
        {
            u.ThrowIfArgumentNull();
            u.UserName.ThrowIfArgumentNull();
            u.LastName.ThrowIfArgumentNull();
            u.FirstName.ThrowIfArgumentNull();
            u.Identifier.ThrowIfArgumentNull();

            var user = users.FindOneById(u.ID);

            if (user != null)
            {
                user.LastName = u.LastName;
                user.FirstName = u.FirstName;
                user.Identifier = u.Identifier;

                if (users.FindOne(Query.EQ("UserName", u.UserName)) == null)
                    user.UserName = u.UserName;

                var update = Update.Replace<WikiUser>(user);
                users.Update(Query.EQ("_id", user.ID), update);
            }
        }
        public void DeleteUser(WikiUser u)
        {
            u.ThrowIfArgumentNull();

            users.Remove(Query.EQ("_id", u.ID));
        }
        public void AddUser(WikiUser u)
        {
            u.ThrowIfArgumentNull();
            u.UserName.ThrowIfArgumentNull();
            u.LastName.ThrowIfArgumentNull();
            u.FirstName.ThrowIfArgumentNull();
            u.Identifier.ThrowIfArgumentNull();

            if (users.FindOne(Query.EQ("UserName", u.UserName)) != null)
                throw new Exception(string.Format("A user with the username ({0}) already exists.", u.UserName));

            if (u.ID == ObjectId.Empty)
                u.ID = ObjectId.GenerateNewId();

            users.Insert(u);
            users.EnsureIndex("Identifier", "UserName");
        }