Exemple #1
0
        public bool AddValueIfChanged(IClassifiable entity, string name, decimal value, DateTime at, string descr = null)
        {
            var metricsid = GetIdFor(entity, name);

            if (metricsid == 0)
            {
                var metrics = CreateMetrics(name, entity, descr);
                metrics.AddEntry(value, at);
                metricsRepo.Update(metrics);
                return(true);
            }
            var dbVal = metricsEntryRepo.GetValueAt(metricsid, at);

            if (dbVal != value)
            {
                var metrics = GetOrCreateFor(entity, name, descr);
                var me      = new MetricsEntryEntity()
                {
                    Metrics    = metrics,
                    RecordDate = at,
                    Value      = value
                };
                metricsEntryRepo.Save(me);
                return(true);
            }
            return(false);
        }