Пример #1
0
        public ActionResult Index(Guid sourceId)
        {
            if (context.DataSources.FirstOrDefault(source => source.Id == sourceId) == null)
            {
                return(RedirectToAction("Index", "InputHistory"));
            }
            if (context.DataEntries.Any(
                    entry => (entry.SourceId == sourceId) &&
                    (entry.CalculationId == Calcs.MigrationId)))
            {
                return(RedirectToAction("Index", "InputHistory"));
            }
            var manualSource = context
                               .Set <ManualDataSource>()
                               .Include("DataEntries")
                               .FirstOrDefault(source => source.Id == sourceId);

            if ((manualSource != null) && (!manualSource.DataEntries.Any()))
            {
                return(RedirectToAction("Index", "InputHistory"));
            }
            if (manualSource != null)
            {
                var entry = manualSource.DataEntries.First();
                return(RedirectToAction("EditData", "Input", new { entryId = entry.Id }));
            }
            var model =
                (from source in context.DataSources
                 join fileDataSource in context.Set <FileDataSource>()
                 on source.Id equals fileDataSource.Id into jn
                 from subFileSource in jn.DefaultIfEmpty(null)
                 join feedDataSource in context.Set <FeedDataSource>()
                 on source.Id equals feedDataSource.Id into fjn
                 from subFeedDataSource in fjn.DefaultIfEmpty(null)
                 where source.Id == sourceId
                 select new EditSourceModel
            {
                Name = (subFileSource == null)
                            ? subFeedDataSource.ScriptPath
                            : subFileSource.OriginalFileName,
                EditDate = source.DateEdit,
                CurrentFileName = (subFileSource == null)
                            ? subFeedDataSource.SourceUrl
                            : subFileSource.CurrentFileName,
                UserName = source.UserName,
                Type = (subFileSource == null)
                            ? subFeedDataSource.HandlerName
                            : subFileSource.HandlerName,
                SourceStatus = source.InputStatus,
                SourceId = source.Id,
                Comment = source.ReferenceNotes,
                SourceErrors = source.SourceErrors
            }).First();

            model.DataEntries = context
                                .DataEntries
                                .Count(entry => entry.SourceId == sourceId);
            model.DataEntriesInError =
                (from entry in context.DataEntries.Include("Errors")
                 from error in entry.Errors
                 where
                 (entry.SourceId == sourceId)
                 group error by error.DataEntryId
                 into g
                 select g.Key).Count();
            model.ErrorTypeCount = new Dictionary <DataErrorType, int>();
            foreach (var value in Enum.GetValues(typeof(DataErrorType)))
            {
                var errorType = (DataErrorType)value;
                var amount    =
                    (from entry in context.DataEntries.Include("Errors")
                     from error in entry.Errors
                     where
                     (error.ErrorType == errorType) &&
                     (entry.SourceId == sourceId)
                     group error by error.DataEntryId
                     into g
                     select g.Key).Count();
                if (amount > 0)
                {
                    model.ErrorTypeCount[errorType] = amount;
                }
            }

            model.SourceContainsErrors =
                sourceDataContext.SourceContainsErrors(sourceId) ||
                sourceDataContext.SourceContainsDataEntriesInError(sourceId);
            model.Calculations =
                (from entry in context.DataEntries.Include("Calculation")
                 where entry.SourceId == sourceId
                 group entry by entry.Calculation
                 into g
                 select new { g.Key, amount = g.Count() })
                .ToDictionary(arg => arg.Key, arg => arg.amount);
            return(View(model));
        }