protected void ui_save_button_Click(object sender, EventArgs e)
        {
            UserController userController = new UserController();

            User user = new User();
            int user_id;

            //getting hidden field id
            if (int.TryParse(ui_id_hiddenfield.Value, out user_id))
            {
                user.id = Convert.ToInt32(ui_id_hiddenfield.Value);
            }
            if (user.id > 0)
            {
                user = userController.actionGetUserByID(user.id);
            }
            //fields validation
            if (String.IsNullOrEmpty(ui_email_textbox.Text) || String.IsNullOrEmpty(ui_password_textbox.Text))
            {
                Response.Cookies.Add(new HttpCookie("flash_message", "Field(s) marked with * can't be empty.") { Path = "/" });
                Response.Cookies.Add(new HttpCookie("flash_css", "alert alert-error") { Path = "/" });
                return;
            }

            //setting up object
            user.username = ui_username_textbox.Text;
            user.password = ui_password_textbox.Text;
            user.firstname = ui_firstname_textbox.Text;
            user.lastname = ui_lastname_textbox.Text;
            user.phone_number = ui_phonenumber_textbox.Text;
            user.email = ui_email_textbox.Text;
            user.department = null;

            //updating db;
            Message message;
            if (user.id > 0)
            {
                message = userController.actionUpdateUser(user);
            }
            else
            {
                //Default user creation is 1//Employee
                user.user_type = 4;
                message = userController.actionCreateUser(user);
            }

            //redirecting
            if (message.condition)
            {
                Response.Cookies.Add(new HttpCookie("flash_message", "Successfully Saved.") { Path = "/" });
                Response.Cookies.Add(new HttpCookie("flash_css", "alert alert-success") { Path = "/" });
                Response.Redirect("~/StoreSupervisor/ClerkDetail.aspx?id=" + user.id);
            }
            else
            {
                Response.Cookies.Add(new HttpCookie("flash_message", message.message) { Path = "/" });
                Response.Cookies.Add(new HttpCookie("flash_css", "alert alert-error") { Path = "/" });
                Response.Redirect("~/StoreSupervisor/ClerkDetail.aspx?id=" + user.id);
            }
        }
 public Message actionCreateUser(User objIn)
 {
     AuthenticationController authController = new AuthenticationController();
     try
     {
         User user = data.Users.Where(o => (o.username == objIn.username)).FirstOrDefault();
         if (user != null) {
             return new Message(false, "Username already taken! User create failed.");
         }
         objIn.password = authController.getEncryptedString(objIn.password);
         data.Users.AddObject(objIn);
         return this.getNewDefaultMessageForDBOperations(data.SaveChanges() == 1);
     }
     catch (Exception e)
     {
         return this.getNewDefaultMessageForException(e);
     }
 }
        public Message actionUpdateUser(User objIn)
        {
            AuthenticationController authController = new AuthenticationController();
            try
            {
                User user = data.Users.Where(o => o.id == objIn.id).Single();
                //objIn.EntityKey = data.Users.Where(o => o.id == objIn.id).Single().EntityKey;

                //user.username = objIn.username;
                user.password = authController.getEncryptedString(objIn.password);
                user.firstname = objIn.firstname;
                user.lastname = objIn.lastname;
                user.email = objIn.email;
                user.phone_number = objIn.phone_number;
                user.department = objIn.department;
                user.user_type = objIn.user_type;

                //data.Users.ApplyCurrentValues(user);
                data.SaveChanges();
                return this.getNewDefaultMessageForDBOperations(true);
            }
            catch (Exception e)
            {
                return this.getNewDefaultMessageForException(e);
            }
        }
 /// <summary>
 /// Create a new User object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="username">Initial value of the username property.</param>
 /// <param name="password">Initial value of the password property.</param>
 /// <param name="user_type">Initial value of the user_type property.</param>
 public static User CreateUser(global::System.Int32 id, global::System.String username, global::System.String password, global::System.Int32 user_type)
 {
     User user = new User();
     user.id = id;
     user.username = username;
     user.password = password;
     user.user_type = user_type;
     return user;
 }
 /// <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);
 }