コード例 #1
0
        public void Add()
        {
            Administrator administrator = new Administrator(auth);

            try
            {
                AdministratorDetails administratorDetails = new AdministratorDetails
                {
                    EmailAddress = "*****@*****.**",
                    Name         = "test",
                };

                administrator.Add(administratorDetails);
            }
            catch (CreatesendException ex)
            {
                ErrorResult error = (ErrorResult)ex.Data["ErrorResult"];
                Console.WriteLine(error.Code);
                Console.WriteLine(error.Message);
            }
            catch (Exception ex)
            {
                // Handle some other failure
                Console.WriteLine(ex.ToString());
            }
        }
コード例 #2
0
    //===============================================================
    // Function: saveButton_Click
    //===============================================================
    protected void saveButton_Click(object sender, EventArgs e)
    {
        Administrator adminUser = new Administrator(Session["loggedInAdministratorName"].ToString());
        adminUser.administratorName = nameTextBox.Text;
        adminUser.emailAddress = emailAddress.Text;
        adminUser.Add();

        adminUser.UpdatePassword(userPassword.Text);

        Response.Redirect("editAdministrator.aspx?AID=" + adminUser.administratorID.ToString());
    }
コード例 #3
0
        public ActionResult edit(FormCollection collection)
        {
            // Get the current domain
            Domain currentDomain = Tools.GetCurrentDomain();
            ViewBag.CurrentDomain = currentDomain;

            // Get the return url
            string returnUrl = collection["returnUrl"];
            ViewBag.QueryParams = new QueryParams(returnUrl);

            // Check if the administrator is authorized
            if (Administrator.IsAuthorized(new string[] { "Administrator" }) == true)
            {
                ViewBag.AdminSession = true;
            }
            else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true)
            {
                ViewBag.AdminSession = true;
                ViewBag.AdminErrorCode = 1;
                ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC");
                return View("index");
            }
            else
            {
                // Redirect the user to the start page
                return RedirectToAction("index", "admin_login");
            }

            // Get all the form values
            Int32 id = Convert.ToInt32(collection["txtId"]);
            string userName = collection["txtUserName"];
            string password = collection["txtPassword"];
            string role = collection["selectAdminRole"];

            // Get the default admin language id
            Int32 adminLanguageId = currentDomain.back_end_language;

            // Get translated texts
            KeyStringList tt = StaticText.GetAll(adminLanguageId, "id", "ASC");

            // Get the administrator
            Administrator administrator = Administrator.GetOneById(id);
            bool postExists = true;

            // Check if the administrator exists
            if (administrator == null)
            {
                // Create an empty administrator
                administrator = new Administrator();
                postExists = false;
            }

            // Update values
            administrator.admin_user_name = userName;
            administrator.admin_role = role;

            // Create a error message
            string errorMessage = string.Empty;

            // Get a administrator on user name
            Administrator adminOnUserName = Administrator.GetOneByUserName(userName);

            // Check for errors in the administrator
            if (adminOnUserName != null && administrator.id != adminOnUserName.id)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_unique"), tt.Get("user_name")) + "<br/>";
            }
            if (administrator.admin_user_name.Length > 50)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("user_name"), "50") + "<br/>";
            }

            // Check if there is errors
            if (errorMessage == string.Empty)
            {
                // Check if we should add or update the administrator
                if (postExists == false)
                {
                    // Add the administrator
                    Int32 insertId = (Int32)Administrator.Add(administrator);
                    Administrator.UpdatePassword(insertId, PasswordHash.CreateHash(password));
                }
                else
                {
                    // Update the administrator
                    Administrator.Update(administrator);

                    // Only update the password if it has changed
                    if (password != "")
                    {
                        Administrator.UpdatePassword(administrator.id, PasswordHash.CreateHash(password));
                    }
                }

                // Redirect the user to the list
                return Redirect("/admin_administrators" + returnUrl);
            }
            else
            {
                // Set form values
                ViewBag.ErrorMessage = errorMessage;
                ViewBag.Administrator = administrator;
                ViewBag.TranslatedTexts = tt;
                ViewBag.ReturnUrl = returnUrl;

                // Return the edit view
                return View("edit");
            }

        } // End of the edit method