Example #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Entities.User entity = new Entities.User();
            try
            {
                entity.UserID = base.GetInt32("ID");
                entity.Name = txtUserName.Text;
                entity.Password = txtUserPassword.Text;
                entity.Login = txtUserLogin.Text;
                entity.IsEnabled = chkUserIsEnabled.Checked;

                switch (base.Operation)
                {
                    case "I":
                        ServiceFactory.CreateConfigurationService.InsertUser(entity);
                        break;
                    case "U":
                        ServiceFactory.CreateConfigurationService.UpdateUser(entity);
                        break;
                    case "D":
                        ServiceFactory.CreateConfigurationService.DeleteUser(entity);
                        break;
                }
                Response.Redirect("UserList.aspx", false);
            }
            catch
            {
                base.SetMessage(lblMessage, MessageType.Error, ResourceMessages.UnexpectedErrorMessage);
            }
        }
        public void UpdateUser(User user)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var users = from item in context.Users
                            where item.UserID == user.UserID
                            select item;

                User entity = users.SingleOrDefault();

                if (entity != null)
                {
                    entity.Name = user.Name;
                    entity.Password = Cryptography.EncryptData(user.Password, saltKeyword);
                    entity.Login = user.Login;
                    entity.IsEnabled = user.IsEnabled;

                    context.SaveChanges();
                }
            }
        }
 public void InsertUser(User user)
 {
     using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
     {
         user.Password = Cryptography.EncryptData(user.Password, saltKeyword);
         context.AddToUsers(user);
         context.SaveChanges();
     }
 }
        public void DeleteUser(User user)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var users = from item in context.Users
                            where item.UserID == user.UserID
                            select item;

                User entity = users.SingleOrDefault();

                if (entity != null)
                {
                    context.DeleteObject(entity);
                    context.SaveChanges();
                }
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Users EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUsers(User user)
 {
     base.AddObject("Users", user);
 }
 /// <summary>
 /// Create a new User object.
 /// </summary>
 /// <param name="userID">Initial value of the UserID property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="login">Initial value of the Login property.</param>
 /// <param name="password">Initial value of the Password property.</param>
 /// <param name="isEnabled">Initial value of the IsEnabled property.</param>
 public static User CreateUser(global::System.Int32 userID, global::System.String name, global::System.String login, global::System.String password, global::System.Boolean isEnabled)
 {
     User user = new User();
     user.UserID = userID;
     user.Name = name;
     user.Login = login;
     user.Password = password;
     user.IsEnabled = isEnabled;
     return user;
 }