Ejemplo n.º 1
0
        public void addCardToUser(string userName, int cardID)
        {
            db = new LinqToSQLDatacontext(connectionString);

            // Create new card in cardbinder
            cardbinder newcard = new cardbinder();
            newcard.id = getLast();
            newcard.userid = userName;
            newcard.cardid = cardID;

            //add new card til cardbinder table
            db.cardbinders.InsertOnSubmit(newcard);
            db.SubmitChanges();
        }
Ejemplo n.º 2
0
        public void editUsername(string userName, string newName)
        {
            db = new LinqToSQLDatacontext(connectionString);

            try
            {
                //Get cardbinder to edit
                var binderQuery =
                    from b in db.cardbinders
                    where b.userid == userName
                    select b;

                foreach (cardbinder b in binderQuery)
                {
                    // create new cardbinder to replace old
                    cardbinder binder = new cardbinder();
                    binder.id = b.id;
                    binder.cardid = b.cardid;
                    binder.userid = newName;

                    db.cardbinders.DeleteOnSubmit(b);
                    db.cardbinders.InsertOnSubmit(binder);
                }

                //Get user to edit
                var query =
                    from u in db.users
                    where u.name == userName
                    select u;

                foreach (user u in query)
                {
                    // create new user and cardbinder to replace old
                    user uNew = new user();
                    uNew.name = newName;
                    uNew.password = u.password;

                    db.users.DeleteOnSubmit(u);
                    db.users.InsertOnSubmit(uNew);
                }

                // Save changes
                db.SubmitChanges();
            }
            catch (Exception e)
            {

                Console.WriteLine(e); ;
            }
        }