Пример #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;
            }
        }
Пример #2
0
        public static WaterMeter Add(VesiPortalDbContext context, WaterMeter waterMeter)
        {
            try
            {
                if (waterMeter.Guid == Guid.Empty || waterMeter.Guid == null)
                {
                    waterMeter.Guid = Guid.NewGuid();
                }
                waterMeter.Timestamp = BitConverter.GetBytes(DateTime.Now.Ticks);

                context.WaterMeters.Create();
                context.WaterMeters.Add(waterMeter);
                context.SaveChanges();

                return(waterMeter);
            }
            catch
            {
                throw;
            }
        }
Пример #3
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;
            }
        }
Пример #4
0
        /// <summary>
        /// Add new feedback to database
        /// </summary>
        /// <param name="context">VesiPortal DbContext</param>
        /// <param name="feedback">Feedback to be added</param>
        /// <returns></returns>
        public static Feedback Add(VesiPortalDbContext context, Feedback feedback)
        {
            try
            {
                if (feedback.Guid == null || feedback.Guid == Guid.Empty)
                {
                    feedback.Guid = Guid.NewGuid();
                }

                feedback.Timestamp = DateTimeOffset.Now;

                context.Feedback.Create();
                context.Feedback.Add(feedback);
                context.SaveChanges();
                return(feedback);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #5
0
        public static WaterMeter Get(VesiPortalDbContext context, Guid guid)
        {
            WaterMeter waterMeter = context.WaterMeters.Where(x => x.Guid == guid).FirstOrDefault();

            return(waterMeter);
        }
Пример #6
0
        /// <summary>
        /// Get water meter readings from database
        /// </summary>
        /// <param name="context">VesiPortalDB context</param>
        /// <param name="waterMeter">Water meter for query</param>
        /// <param name="startDate">Optional: if value give, only includes readings where reading date is later or equal to this date</param>
        /// <param name="endDate">Optional: if value give, only includes readings where reading date is earlier or equal to this date</param>
        /// <returns></returns>
        public static IQueryable <RegisteredWaterMeterReading> GetRegisteredWaterMeterReadings(VesiPortalDbContext context, WaterMeter waterMeter, DateTime?startDate = null, DateTime?endDate = null)
        {
            try
            {
                IQueryable <RegisteredWaterMeterReading> waterMeterReadings = context.WaterMeterReadings.OfType <RegisteredWaterMeterReading>()
                                                                              .Where(x => x.WaterMeterGuid == waterMeter.Guid);

                if (startDate.HasValue)
                {
                    waterMeterReadings = waterMeterReadings.Where(x => x.ReadingDate >= startDate.Value);
                }

                if (endDate.HasValue)
                {
                    waterMeterReadings = waterMeterReadings.Where(x => x.ReadingDate <= endDate.Value);
                }

                return(waterMeterReadings);
            }
            catch
            {
                throw;
            }
        }
Пример #7
0
 public VesiPortalRoleStore(VesiPortalDbContext context)
     : base(context)
 {
 }
Пример #8
0
 public VesiPortalUserStore(VesiPortalDbContext context)
     : base(context)
 {
 }