Exemplo n.º 1
0
        /// <summary>
        /// Read water meter reading with matching guid from database.
        /// </summary>
        /// <param name="context">VesiPortal DbContext</param>
        /// <param name="waterMeterReadingGuid">Guid used for searching the database</param>
        /// <returns></returns>
        public static WaterMeterReading Get(VesiPortalDbContext context, Guid waterMeterReadingGuid)
        {
            try
            {
                WaterMeterReading waterMeterReading = context.WaterMeterReadings.Where(x => x.Guid == waterMeterReadingGuid)
                                                      .FirstOrDefault();

                return(waterMeterReading);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add new water meter reading to database
        /// </summary>
        /// <param name="context">VesiPortal DbContext</param>
        /// <param name="waterMeterReading">Reading to be added</param>
        /// <returns></returns>
        public static WaterMeterReading Add(VesiPortalDbContext context, WaterMeterReading waterMeterReading)
        {
            try
            {
                if (waterMeterReading.Guid == null || waterMeterReading.Guid == Guid.Empty)
                {
                    waterMeterReading.Guid = Guid.NewGuid();
                }

                waterMeterReading.Timestamp = DateTimeOffset.Now;

                context.WaterMeterReadings.Create();
                context.WaterMeterReadings.Add(waterMeterReading);
                context.SaveChanges();
                return(waterMeterReading);
            }
            catch (Exception)
            {
                throw;
            }
        }