Ejemplo n.º 1
0
        /// <summary>
        /// Change a user's email.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <param name="newEmail">The new email address.</param>
        /// <param name="role">The role, DJ or mobile.</param>
        /// <returns>The outcome of the operation.</returns>
        public Response ChangeEmail(int ID, string role, string newEmail)
        {
            Response r = new Response();
            if (!role.Equals("DJ") && !role.Equals("Mobile"))
            {
                r.error = true;
                r.message = "Bad role";
                return r;
            }

            // Validate the email address.
            try
            {
                var address = new System.Net.Mail.MailAddress(newEmail);
            }
            catch
            {
                r.error = true;
                r.message = "Email address is not valid";
                return r;
            }

            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                r = db.OpenConnection();
                if (r.error)
                    return r;

                if (role == "DJ")
                    r = db.DJSetEmail(ID, newEmail);
                else
                    r = db.MobileSetEmail(ID, newEmail);

                if (r.error)
                    return r;

                return r;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Change a user's email.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <param name="newEmail">The new email address.</param>
        /// <param name="role">The role, DJ or mobile.</param>
        /// <returns>The outcome of the operation.</returns>
        public Response ChangeEmail(int ID, string role, string newEmail)
        {
            ExpResponse r = new ExpResponse();
            if (!role.Equals("DJ") && !role.Equals("Mobile"))
            {
                r.setErMsgStk(true, "Bad Role Given", Environment.StackTrace);
                return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);
            }

            // Validate the email address.
            try
            {
                var address = new System.Net.Mail.MailAddress(newEmail);
            }
            catch
            {
                r.setErMsg(true, Messages.ERR_BAD_EMAIL);
                return r;
            }

            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                r = db.OpenConnection();
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);

                if (role == "DJ")
                    r = db.DJSetEmail(ID, newEmail);
                else
                    r = db.MobileSetEmail(ID, newEmail);

                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);

                return r;
            }
        }