public ActionResult Index(Guid?componentId, Guid?counterId, DateTime?from, DateTime?to)
        {
            var eDate = to ?? DateTime.Now;
            var sDate = from ?? eDate.AddDays(-1);

            Component component = null;

            if (componentId.HasValue)
            {
                var componentRepository = CurrentAccountDbContext.GetComponentRepository();
                component = componentRepository.GetById(componentId.Value);
            }

            var model = new CounterDataListModel()
            {
                ComponentId = componentId,
                From        = sDate,
                To          = eDate
            };

            if (component != null)
            {
                var counterRepository = CurrentAccountDbContext.GetMetricTypeRepository();

                MetricType metricType;
                if (counterId.HasValue)
                {
                    metricType        = counterRepository.GetById(counterId.Value);
                    model.CounterId   = metricType.Id;
                    model.CounterName = metricType.SystemName;
                }
                else
                {
                    var metricTypes = component.Metrics.Where(t => t.IsDeleted == false && t.MetricType.IsDeleted == false).Select(t => t.MetricType);
                    metricType        = metricTypes.OrderBy(t => t.SystemName).FirstOrDefault();
                    model.CounterId   = metricType != null ? metricType.Id : (Guid?)null;
                    model.CounterName = metricType != null ? metricType.SystemName : null;
                }

                if (model.CounterId.HasValue)
                {
                    var storageContext          = CurrentAccountDbContext;
                    var metricHistoryRepository = storageContext.GetMetricHistoryRepository();

                    var rows = metricHistoryRepository
                               .GetByPeriod(component.Id, sDate, eDate, new[] { model.CounterId.Value })
                               .OrderByDescending(t => t.BeginDate)
                               .ToArray();

                    model.Data  = rows.ToArray();
                    model.Graph = GetCounterGraphDataModel(metricType, rows.OrderBy(t => t.BeginDate).ToArray());
                }
            }

            return(View(model));
        }
        public JsonResult CheckName(EditModel model)
        {
            var repository = CurrentAccountDbContext.GetMetricTypeRepository();
            var counter    = repository.GetOneOrNullByName(model.SystemName);

            if (counter != null && (!model.Id.HasValue || model.Id != counter.Id))
            {
                return(Json("Метрика с таким именем уже существует", JsonRequestBehavior.AllowGet));
            }
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Index(string search)
        {
            var countersRepository = CurrentAccountDbContext.GetMetricTypeRepository();

            var query = countersRepository
                        .QueryAll()
                        .Where(t => t.IsDeleted == false);

            if (!string.IsNullOrEmpty(search))
            {
                query = query.Where(t => t.Id.ToString().Equals(search, StringComparison.OrdinalIgnoreCase) || t.SystemName.Contains(search));
            }

            var counters = query.OrderBy(t => t.SystemName);

            var model = new ListModel()
            {
                Items  = counters,
                Search = search
            };

            return(View(model));
        }