Esempio n. 1
0
        ///EDIT METHODS
        /// <summary>
        /// Updates the tariff with the specified id.  A whole tariff object, including child tariffband objects should be provided, these will be updated to.
        /// NB you cannot included new tariffbands when updating a tariff - create a new band seperately first.
        /// </summary>
        /// <param name="tariffId">id of tariff object to update</param>
        /// <param name="newTariff">tariff object with updated details & tariffbands</param>
        /// <returns>JSON representation of updated Tariff object, including TariffBands, wrapped in EMResponse</returns>
        public string editTariff(int tariffId, string newTariff)
        {
            EMResponse response = new EMResponse();
            try
            {
                tariffMgr = new TariffManager();
                tariffMgr.editTariff(tariffId, newTariff);
                response.status = ok;
            }
            catch (Exception e)
            {
                response.status = error;
                response.data = e.Message;
            }

            return EMConverter.fromObjectToJSON(response);
        }
Esempio n. 2
0
        /// <summary>
        /// Create a tariff band object and saves to tariff with provided id.  NB validity of limits must be checked by client before creation.
        /// </summary>
        /// <param name="upperLimit">the upper kWh of the band.  Use 0 for no upper limit on this band.</param>
        /// <param name="lowerLimit">the lower limit of this band.  Can be 0.</param>
        /// <param name="rate">The unit rate for each kWh that falls into this band, in pence.</param>
        /// <param name="tariffId">id of tariff to which the band belongs.</param>
        /// <returns>JSON representation of id of tariff band object, wrapped in EMResponse</returns>
        public string createTariffBand(int upperLimit, int lowerLimit, double rate, int tariffId)
        {
            EMResponse response = new EMResponse();
            try
            {
                tariffMgr = new TariffManager();
                response.data = EMConverter.fromObjectToJSON(tariffMgr.createTariffBand(upperLimit, lowerLimit, rate, tariffId));
                response.status = ok;
            }
            catch (Exception e)
            {
                response.status = error;
                response.data = e.Message;
            }

            return EMConverter.fromObjectToJSON(response);
        }
Esempio n. 3
0
        //* * * TARIFF MANAGER METHODS
        //// GET METHODS
        /// <summary>
        /// Retreives all Period objects in the database
        /// </summary>
        /// <returns>JSON representation of List[Period], wrapped in EMResponse object.</returns>
        public string getPeriods()
        {
            EMResponse response = new EMResponse();
            try
            {
                tariffMgr = new TariffManager();
                response.data = EMConverter.fromObjectToJSON(tariffMgr.getSCPeriods());
                response.status = ok;
            }
            catch (Exception e)
            {
                response.status = error;
                response.data = e.Message;
            }

            return EMConverter.fromObjectToJSON(response);
        }
Esempio n. 4
0
        ///CREATE METHODS
        /// <summary>
        /// Creates a tariff object with the specifed attributes.  TariffBand objects must be created seperately using emAPI.createTariffBand.
        /// </summary>
        /// <param name="standingChargeValue">Value in £</param>
        /// <param name="startDate">shortdate string</param>
        /// <param name="standingChargePeriodId">id of Period for standing charge value (eg monthly, annually etc)</param>
        /// <param name="bandingPeriodId">id of Period for banding (currently unused)</param>
        /// <param name="meterId">id of meter to which tariff belongs</param>
        /// <returns>JSON representation of id of created tariff - int, wrapped in EMResponse</returns>
        public string createTariff(double standingChargeValue, string startDate, int standingChargePeriodId, int bandingPeriodId, int meterId)
        {
            EMResponse response = new EMResponse();
            try
            {
                tariffMgr = new TariffManager();
                response.data = EMConverter.fromObjectToJSON(tariffMgr.createTariff(standingChargeValue, startDate, standingChargePeriodId, bandingPeriodId, meterId));
                response.status = ok;
            }
            catch (Exception e)
            {
                response.status = error;
                response.data = e.Message;
            }

            return EMConverter.fromObjectToJSON(response);
        }
Esempio n. 5
0
        /// <summary>
        /// Retrieves the date of the tariff before the most recent, used when editing the current tariff.
        /// </summary>
        /// <param name="meterId"></param>
        /// <returns>JSON representation of date string, wrapped in EMResponse</returns>
        public string getMinimumTariffDateForEdit(int meterId)
        {
            EMResponse response = new EMResponse();
            try
            {
                tariffMgr = new TariffManager();
                response.data = EMConverter.fromObjectToJSON(tariffMgr.getMinimumTariffDateForEdit(meterId));
                response.status = ok;
            }
            catch (Exception e)
            {
                response.status = error;
                response.data = e.Message;
            }

            return EMConverter.fromObjectToJSON(response);
        }