Ejemplo n.º 1
0
        /// <summary>
        /// Gets the annual energy costs of all properties in the database.  Properties belonging to the specified user are
        /// marked with a bool isUsers (true).
        /// </summary>
        /// <param name="userId"></param>
        /// <returns>JSON representation of List[AnonymousProperty] objects, wrapped in EMReponse object</returns>
        public string getComparativeCostsForUser(int userId)
        {
            EMResponse response = new EMResponse();
            try
            {
                accountMgr = new AccountManager();
                response.data = EMConverter.fromObjectToJSON(accountMgr.getComparativeCostsForUser(userId));
                response.status = ok;
            }
            catch (Exception e)
            {
                response.status = error;
                response.data = e.Message;
            }

            return EMConverter.fromObjectToJSON(response);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the user object in the database with the details in the newUser object.  NB Child objects are NOT updated.
        /// </summary>
        /// <param name="userId">id of the user to be updated</param>
        /// <param name="newUser">JSON representation of user object containing the details with which to update the user</param>
        /// <returns>JSON representaion of the updated user (incl child objects).  String wrapped in EMResponse object.</returns>
        public string editUser(int userId, string newUser)
        {
            EMResponse response = new EMResponse();
            try
            {
                accountMgr = new AccountManager();
                response.data = EMConverter.fromObjectToJSON(accountMgr.editUser(userId, newUser));
                response.status = ok;
            }
            catch (Exception e)
            {
                response.status = error;
                response.data = e.Message;
            }

            return EMConverter.fromObjectToJSON(response);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Checks existance of given email in the database
        /// </summary>
        /// <param name="email"></param>
        /// <returns>bool wrapped in EMResponse object</returns>
        public string emailIsUnique(string email)
        {
            EMResponse response = new EMResponse();
            try
            {
                accountMgr = new AccountManager();
                response.data = EMConverter.fromObjectToJSON(accountMgr.emailIsUnique(email));

                response.status = ok;
            }
            catch (Exception e)
            {
                response.status = error;
                response.data = e.Message;
            }

            return EMConverter.fromObjectToJSON(response);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a user object and saves it to the database.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="forename"></param>
        /// <param name="surname"></param>
        /// <param name="password">NB Plaintext passwords should not be stored in the database.  Consider a salty hash instead.</param>
        /// <param name="email"></param>
        /// <returns>Id of created user - int wrapped in EMResponse object</returns>
        public string createUser(string username, string forename, string surname, string password, string email)
        {
            EMResponse response = new EMResponse();
            try
            {
                accountMgr = new AccountManager();
                response.data = EMConverter.fromObjectToJSON(accountMgr.createUser(forename, surname, email, username, password));
                response.status = ok;
            }
            catch (Exception e)
            {
                response.status = error;
                response.data = e.Message;
            }

            return EMConverter.fromObjectToJSON(response);
        }