Пример #1
0
        private void Save()
        {
            USER user = new USER();
            user.Login = txtLogin.Text;
            user.Name = txtName.Text;
            user.Email = txtEmail.Text;
            user.Enabled = chkEnabled.Checked;
            //user.Enabled = chkEnabled.Enabled;
            if (ddlRoles.SelectedValue != "-1")
            {
                user.RoleID = Int32.Parse(ddlRoles.SelectedValue);
            }
            bool ignorePass = false;
            if (txtPass.Text != fakePassChars)
            {
                user.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPass.Text, Configuration.PasswordHashMethod).ToLower();
            }
            else
            {
                ignorePass = true;
            }
            // not a new user
            int id = 0;
            lblErrors.Visible = true;
            lblErrors.ForeColor = Color.Green;
            string operation = String.Empty;
            try
            {
                if (!String.IsNullOrWhiteSpace(ID.Value) && Int32.TryParse(ID.Value, out id) && id != 0)
                {
                    user.ID = id;
                    ApplicationContext.Current.Users.Update(user, ignorePass);
                    operation = "updated";
                }
                else
                {
                    ApplicationContext.Current.Users.Insert(user);
                    operation = "inserted";
                    ID.Value = user.ID.ToString();
                }
                lblErrors.Text = "User " + operation + " correctly.";

                //Reset password to fake, otherwise the textbox will be empty
                txtPass.Attributes.Add("value", fakePassChars);
                txtPass2.Attributes.Add("value", fakePassChars);
            }
            catch (Exception ex)
            {
                // TODO log error
                lblErrors.ForeColor = Color.Red;
                lblErrors.Text = "Error occurred: " + ex.Message;
            }
        }
Пример #2
0
        public List<USER> Search(USER User, int PageSize, int PageIndex, out int TotalRecords, string OrderExp, SortDirection SortDirection)
        {
                var result = Context.USER.AsQueryable();
                if (User != null)
                {
                    if (!String.IsNullOrWhiteSpace(User.Email))
                    {
                        result = result.Where(o => o.Email.Contains(User.Email));
                    }
                    if (!String.IsNullOrWhiteSpace(User.Login))
                    {
                        result = result.Where(o => o.Login.Contains(User.Login));
                    }
                    if (!String.IsNullOrWhiteSpace(User.Name))
                    {
                        result = result.Where(o => o.Name.Contains(User.Name));
                    }
                    if (User.RoleID.HasValue)
                    {
                        result = result.Where(o => o.RoleID == User.RoleID.Value);
                    }

                    if (User.Enabled)
                    {
                        result = result.Where(o => o.Enabled == User.Enabled);
                    }
                }

                TotalRecords = result.Count();

                GenericSorterCaller<USER> sorter = new GenericSorterCaller<USER>();
                result = sorter.Sort(result, string.IsNullOrEmpty(OrderExp) ? "ID" : OrderExp, SortDirection);

                // pagination
                return result.Skip( PageIndex * PageSize).Take(PageSize).ToList();
        }
Пример #3
0
 public void Insert(USER User)
 {
         Context.USER.AddObject(User);
         //Context.SaveChanges();
 }
Пример #4
0
 public string ResetPassword(USER user, string Answer)
 {
     // TODO reset password logic
     return String.Empty;
 }
Пример #5
0
 public void DeleteById(int id)
 {
     USER obj = new USER() { ID = id };
     Delete(obj);
 }
Пример #6
0
 public void Delete(USER User)
 {
         Context.USER.Attach(User);
         Context.USER.DeleteObject(User);
         //Context.SaveChanges();
 }
Пример #7
0
 public void Update(USER User)
 {
     Update(User, true);
 }
Пример #8
0
     private void FixupUSER(USER previousValue)
     {
         if (previousValue != null && previousValue.AUDIT.Contains(this))
         {
             previousValue.AUDIT.Remove(this);
         }
 
         if (USER != null)
         {
             if (!USER.AUDIT.Contains(this))
             {
                 USER.AUDIT.Add(this);
             }
             if (UserID != USER.ID)
             {
                 UserID = USER.ID;
             }
         }
         else if (!_settingFK)
         {
             UserID = null;
         }
     }
Пример #9
0
 public void Update(USER Entity)
 {
     _userDAO.Update(Entity);
     Context.SaveChanges();
 }
Пример #10
0
 public void Insert(USER Entity)
 {
     _userDAO.Insert(Entity);
     Context.SaveChanges();
 }
Пример #11
0
 public List<USER> Search(USER Entity, int PageSize, int PageIndex, out int TotalRecords, string OrderExp, Util.SortDirection SortDirection)
 {
     return _userDAO.Search(Entity, PageSize, PageIndex, out TotalRecords, OrderExp, SortDirection);
 }
Пример #12
0
 public string ResetPassword(USER User, string Answer)
 {
     return _userDAO.ResetPassword(User, Answer);
 }
Пример #13
0
 public void Update(USER User, bool IgnorePassword)
 {
     _userDAO.Update(User, IgnorePassword);
     Context.SaveChanges();
 }
Пример #14
0
        private void FixupUSER(USER previousValue)
        {
            if (previousValue != null && previousValue.PRODUCT.Contains(this))
            {
                previousValue.PRODUCT.Remove(this);
            }

            if (USER != null)
            {
                if (!USER.PRODUCT.Contains(this))
                {
                    USER.PRODUCT.Add(this);
                }
                if (ApprovedBy != USER.ID)
                {
                    ApprovedBy = USER.ID;
                }
            }
            else if (!_settingFK)
            {
                ApprovedBy = null;
            }
        }
Пример #15
0
 public void Update(USER User, bool IgnorePassword)
 {
         Context.USER.Attach(User);
         if (IgnorePassword)
         {
             var entry = Context.ObjectStateManager.GetObjectStateEntry(User);
             entry.SetModifiedProperty("Name");
             entry.SetModifiedProperty("Login");
             entry.SetModifiedProperty("Email");
             entry.SetModifiedProperty("RoleID");
             entry.SetModifiedProperty("Enabled");
         }
         else
         {
             Context.ObjectStateManager.ChangeObjectState(User, EntityState.Modified);
         }
         //Context.SaveChanges();
 }
Пример #16
0
 public void Delete(USER Entity)
 {
     _userDAO.Delete(Entity);
     Context.SaveChanges();
 }
Пример #17
0
     private void FixupUSER(USER previousValue)
     {
         if (previousValue != null && previousValue.ORDER_NOTES.Contains(this))
         {
             previousValue.ORDER_NOTES.Remove(this);
         }
 
         if (USER != null)
         {
             if (!USER.ORDER_NOTES.Contains(this))
             {
                 USER.ORDER_NOTES.Add(this);
             }
             if (UserID != USER.ID)
             {
                 UserID = USER.ID;
             }
         }
     }