Пример #1
0
        public static void AddUser(User user)
        {
            using (var hdc = new WebserviceDataContext())
            {
                hdc.Users.InsertOnSubmit(new User
                {
                    Username = user.Username,
                    Password = user.Password,
                    Description = user.Description,
                    UpdateUser = user.UpdateUser,
                    UpdateDateTime = DateTime.Now
                });

                try
                {
                    hdc.SubmitChanges();
                }
                catch (SqlException ex)
                {
                    if (ex.Number == 2601 || ex.Number == 2627)
                    {
                        throw;
                    }
                }
            }
        }
Пример #2
0
 public static void DeleteUser(int userId)
 {
     using (var hdc = new WebserviceDataContext())
     {
         var user = hdc.Users.Single(item => item.UserId == userId);
         hdc.Users.DeleteOnSubmit(user);
         try
         {
             hdc.SubmitChanges();
         }
         catch (SqlException ex)
         {
             if (ex.Number == 2601 || ex.Number == 2627)
             {
                 throw;
             }
         }
     }
 }
Пример #3
0
        public static void UpdateUser(User user)
        {
            using (var hdc = new WebserviceDataContext())
            {
                var usr = hdc.Users.Single(item => item.UserId == user.UserId);

                usr.Username = user.Username;
                usr.Password = user.Password;
                usr.Description = user.Description;
                usr.UpdateUser = user.UpdateUser;
                usr.UpdateDateTime = DateTime.Now;

                try
                {
                    hdc.SubmitChanges();
                }
                catch (SqlException ex)
                {
                    if (ex.Number == 2601 || ex.Number == 2627)
                    {
                        throw;
                    }
                }
            }
        }