//* * * UPDATE METHODS public User editUser(int userId, string userJSON) { User updatedUser = EMConverter.fromJSONtoA <User>(userJSON); updatedUser = mediator.DataManager.editUser(userId, updatedUser); return(updatedUser); }
public void editMeterReading(int readingId, int meterId, string readingJSON, int propertyId) { ///desrialise reading and update in the database MeterReading updatedReading = EMConverter.fromJSONtoA <MeterReading>(readingJSON); mediator.DataManager.editMeterReading(readingId, updatedReading); ///get the meter (now with updated reading) and recalc the consumption for each reading Meter meter = mediator.DataManager.getMeter(meterId); meter.Register = meter.Register.OrderBy(rdg => rdg.Date).ToList(); foreach (MeterReading rdg in meter.Register) { if (rdg.Date >= updatedReading.Date) { MeterReading revisedReading = new MeterReading { Date = rdg.Date, Reading = rdg.Reading }; revisedReading.Consumption = calculatekWh(revisedReading, meter); mediator.DataManager.editMeterReading(rdg.Id, revisedReading); } } mediator.updateAnnualCO2(propertyId); mediator.updatePropertyAnnualTotalkWh(propertyId); }
//* * * UPDATE METHODS public Tariff editTariff(int tariffId, string tariffJSON) { Tariff updatedTariff = EMConverter.fromJSONtoA <Tariff>(tariffJSON); updatedTariff = mediator.DataManager.editTariff(tariffId, updatedTariff); return(updatedTariff); }
//* * * UPDATE METHODS public Meter editMeter(int meterId, string meterJSON) { Meter updatedMeter = EMConverter.fromJSONtoA <Meter>(meterJSON); updatedMeter = mediator.DataManager.editMeter(meterId, updatedMeter); return(updatedMeter); }
/// <summary> /// Validates invoice from invoice Id only. Ensures Invoice.Meter object is complete with all required tariff information. /// Returns JSON string. /// </summary> /// <param name="invoiceId">id of invoice to validate</param> /// <param name="saveAfterValidation">whether the changes to the invoice should be saved after validation</param> /// <returns>JSON representation of the validated Invoice, wrapped in EMRepsonse.</returns> public string validateInvoice(int invoiceId, bool saveAfterValidation) { Invoice invoice = mediator.DataManager.getInvoice(invoiceId); invoice = validateInvoice(invoice, saveAfterValidation); return(EMConverter.fromObjectToJSON(invoice)); }
//* * * UPDATE METHODS public Annotation editAnnotation(int noteId, string AnnotationJSON) { Annotation updatedNote = EMConverter.fromJSONtoA <Annotation>(AnnotationJSON); updatedNote = mediator.DataManager.editNote(noteId, updatedNote); return(updatedNote); }
public List <AnonymousProperty> getAnonymousProperties(string propertyIdsJSON) { List <int> propertyIds = EMConverter.fromJSONtoA <List <int> >(propertyIdsJSON); List <AnonymousProperty> anonProperties = mediator.DataManager.getAnonymousProperties(propertyIds); return(anonProperties); }
//* * * UPDATE METHODS public string editInvoice(int invoiceId, string invoiceJSON, int propertyId) { Invoice updatedInvoice = EMConverter.fromJSONtoA <Invoice>(invoiceJSON); updatedInvoice = mediator.DataManager.editInvoice(invoiceId, updatedInvoice); ///validate updated invoice mediator.validateInvoice(updatedInvoice.Id, true); mediator.updatePropertyAnnualTotalCost(propertyId); return(EMConverter.fromObjectToJSON(updatedInvoice)); }
//* * * UPDATE METHODS public Property editProperty(int propertyId, string propertyJSON) { Property updatedProperty = EMConverter.fromJSONtoA <Property>(propertyJSON); updatedProperty = mediator.DataManager.editProperty(propertyId, updatedProperty); ///need to update benchmark stats in case property type has been changed EMDatabaseStats.updateBenchmarkStats(); return(updatedProperty); }