Ejemplo n.º 1
0
        public static void CreateNewUserDashboard(int uid, UserType utype)
        {
            //Adds 4 entries to dashboardsettings table to give user default dash items 1 item for customers
            LINQ_UsersDataContext dc = new LINQ_UsersDataContext();
            List<string> DefaultDashItems = ListDashboardItems(utype);
            if (utype == UserType.AccountCustomer)
            {
                DashBoardSetting ds = new DashBoardSetting();
                ds.DashBoardNumber = 1;
                ds.DashBoardItem = DefaultDashItems[2];
                ds.UserId = uid;

                dc.DashBoardSettings.InsertOnSubmit(ds);
            }
            else
            {
                for (int i = 1; i <= 4; i++)
                {
                    DashBoardSetting ds = new DashBoardSetting();
                    ds.DashBoardNumber = i;
                    ds.DashBoardItem = DefaultDashItems[i];
                    ds.UserId = uid;

                    dc.DashBoardSettings.InsertOnSubmit(ds);
                }
            }
            try
            {
                dc.SubmitChanges();
            }
            catch (Exception ex)
            {
                Database.WriteException("Error inserting new DashBoardSettings items", uid, "Users.CreateNewUserDashboard", ex);
            }
        }
Ejemplo n.º 2
0
 private void UpdateEmail(string eml)
 {
     try
     {
         LINQ_UsersDataContext de = new LINQ_UsersDataContext();
         var userEmail = (from a in de.WebAccounts
                         where a.id == Convert.ToInt32(thisUserId)
                         select a).FirstOrDefault();
         if (userEmail != null)
         {
             userEmail.Email = eml;
             de.SubmitChanges();
         }
     }
     catch (Exception ex)
     {
         Database.WriteException("Error updating email to web accounts table. Method: UpdateEmail", Page, HttpContext.Current, ex);
     }
 }
Ejemplo n.º 3
0
 private void UpdateAccountRole(int usrid)
 {
     string role = ddWebAccountType.SelectedItem.ToString();
     LINQ_UsersDataContext dc = new LINQ_UsersDataContext();
     var dfd = (from a in dc.WebAccountRoles
                where a.WebUser == usrid
                select a).FirstOrDefault();
     if (dfd != null)
     {
         dfd.RoleId = Users.GetUserChar(role);
         dc.SubmitChanges();
     }
 }
Ejemplo n.º 4
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (hiddenEntityId.Value == "") { Master.SetStatus("Save the record before adding a web user account.", 2); return; }
        if (isNew)
        {
            //string typ = Request.QueryString["type"];
            bool iscst = true;
            if (thisUserType != UserType.AccountCustomer) { iscst = false; }
            int entVal = Convert.ToInt32(hiddenEntityId.Value);
            if (Users.IsUsernameTaken(txtUserName.Text)) { Master.SetStatus("User name is taken. Select a new user name",2); return; }
            //Create new web account user
            try
            {
                LINQ_UsersDataContext dc = new LINQ_UsersDataContext();
                WebAccount wa = new WebAccount();
                wa.UserName = txtUserName.Text;
                wa.Password = Users.EncryptPass(txtPassword1.Text);
                wa.Email = txtEmail.Text;

                wa.AccountType = Users.GetUserChar(ddWebAccountType.SelectedItem.ToString());
                UpdateAccountRole(wa.id);
                wa.Active = true;
                wa.CreatedBy = (string)Session["username"];
                wa.DateOpen = DateTime.Now;
                wa.EmailVerified = false;
                wa.AccountType = Convert.ToChar(userChar);
                wa.FName = txtFName.Text;
                wa.LName = txtLName.Text;
                if (iscst) { wa.Customer = entVal; wa.Account = Users.GetCustomerAccountNumber(entVal); } else { wa.Employee = entVal; wa.Account = Users.GetEmployeeAccountNumber(entVal); }

                dc.WebAccounts.InsertOnSubmit(wa);
                dc.SubmitChanges();
                Users.CreateNewUserDashboard(wa.id, UserType.AccountCustomer);
                Users.SetupUserType(wa.id, Convert.ToChar(userChar));
                Master.SetStatus("Web account created for " + txtFName.Text + " " + txtLName.Text , 1);
            }
            catch (Exception ex)
            {
                Database.WriteException("Error adding web account. btnSave_Click", Page, HttpContext.Current, ex);
                Master.SetStatus("Unable to create web account" , 2);
            }

        }
        else
        {
            string new_username = txtUserName.Text;
            //Validate and then save to DB --- THIS IS ONLY A SAVE FOR THE WEB INFO, NOT THE employee or customer
            try
            {
                if (Users.IsUsernameTaken(new_username) && new_username != Users.GetUserName(thisUserId)) { Master.SetStatus("User name is already taken", 2); return; }
                LINQ_UsersDataContext dc = new LINQ_UsersDataContext();
                var userInfo = (from a in dc.WebAccounts
                                where a.id == Convert.ToInt32(thisUserId)
                                select a).FirstOrDefault();
                if (userInfo != null)
                {
                    if (new_username == "") { throw new NullReferenceException("Change UserName"); }
                    //set vals and update
                    userInfo.FName = txtFName.Text;
                    userInfo.LName = txtLName.Text;
                    userInfo.Email = txtEmail.Text;
                    userInfo.UserName = txtUserName.Text;
                    userInfo.AccountType = Users.GetUserChar(ddWebAccountType.SelectedItem.ToString());
                    UpdateAccountRole(userInfo.id);

                    dc.SubmitChanges();
                    Master.SetStatus("Web account user updated", 1);
                    btnSave.Visible = false;
                    btnEditUser.Visible = true;
                    txtUserName.ReadOnly = true;
                }
            }
            catch (Exception ex)
            {
                Database.WriteException("Error updating WebUser information. btnSave_Click", Page, HttpContext.Current, ex);
                Master.SetStatus("Error updating web account information", 2);
            }
        }
    }
Ejemplo n.º 5
0
 private void SetNewValue(int itemnumber, string item)
 {
     uid = Variables.NullSafe((int)Session["userid"]);
         try
         {
             LINQ_UsersDataContext db = new LINQ_UsersDataContext();
             var dash = (from d in db.DashBoardSettings
                         where d.UserId == uid && d.DashBoardNumber == itemnumber
                         select d).FirstOrDefault();
             dash.DashBoardItem = item;
             db.SubmitChanges();
         }
         catch (Exception ex)
         {
             Database.WriteException("Updating dashboard - SetNewValue()", Page, HttpContext.Current, ex);
         }
 }
Ejemplo n.º 6
0
 public static void SetupUserType(int uid, char typ)
 {
     LINQ_UsersDataContext dc = new LINQ_UsersDataContext();
     WebAccountRole ar = new WebAccountRole();
     ar.WebUser = uid;
     ar.RoleId = typ;
     try
     {
         dc.WebAccountRoles.InsertOnSubmit(ar);
         dc.SubmitChanges();
     }
     catch (Exception ex)
     {
         Database.WriteException("Error inserting new webaccount role", uid, "Users.SetupUserType", ex);
     }
 }