Пример #1
0
        public void SaveData()
        {
            using (var conext = new TestGitDataContext())
            {
                var dbItem = conext.UserDatas.SingleOrDefault(i => i.UserId == UserId);

                if (dbItem != null)
                {
                    dbItem.FirstName    = this.FirstName;
                    dbItem.LastName     = this.LastName;
                    dbItem.EmailAddress = this.EmailAddress;

                    conext.SubmitChanges();
                }
                else
                {
                    var newDbItem = new TestGit.Database.UserData();
                    newDbItem.FirstName    = this.FirstName;
                    newDbItem.LastName     = this.LastName;
                    newDbItem.EmailAddress = this.EmailAddress;

                    conext.UserDatas.InsertOnSubmit(newDbItem);
                    conext.SubmitChanges();
                }
            }
        }
Пример #2
0
        public static void DeleteUser(int userId)
        {
            using (var context = new TestGitDataContext())
            {
                var deleteUser = (from userData in context.UserDatas.Where(i => i.UserId == userId)
                                  select userData).Single();

                context.UserDatas.DeleteOnSubmit(deleteUser);
                context.SubmitChanges();
            }
        }