Example #1
0
        public ActionResult EditData(Guid?entryId)
        {
            var entry = context.DataEntries.Find(entryId);

            if (entry == null)
            {
                return(RedirectToAction("EnterData"));
            }
            var calculationId = entry.CalculationId;

            if (calculationId == CarbonKnown.DAL.Models.Constants.Calculation.MigrationId)
            {
                return(RedirectToActionPermanent("Index", "InputHistory"));
            }
            var type     = CalculationModelFactory.EntryTypes[calculationId];
            var viewName = type.Name;
            var model    = new EnterDataModel
            {
                EntryData   = (context.Set(type).Find(entryId) as DataEntry) ?? entry,
                ManualEntry = (string.Equals(entry.Source.SourceType, typeof(ManualDataSource).Name)),
                Variance    = GetVariances(calculationId),
                EntryErrors = entry
                              .Errors
                              .Where(error => error.Column == string.Empty)
                              .Select(error => error.Message),
                CanRevert      = (entry.Source != null) && (entry.Source.InputStatus == SourceStatus.Calculated),
                CanEdit        = (entry.Source != null) && (entry.Source.InputStatus == SourceStatus.PendingCalculation),
                ViewName       = viewName,
                ReferenceNotes = (entry.Source == null) ? string.Empty : entry.Source.ReferenceNotes
            };

            return(ViewInputType(viewName, model));
        }
Example #2
0
        public ActionResult EnterData(Guid?calculationId)
        {
            var initialId = calculationId ?? Settings.Default.InitialCalculationId;

            if (initialId == CarbonKnown.DAL.Models.Constants.Calculation.MigrationId)
            {
                return(RedirectToActionPermanent("Index", "InputHistory"));
            }
            var viewName  = CalculationModelFactory.EntryTypes[initialId].Name;
            var today     = DateTime.Today;
            var startDate = new DateTime(today.Year, today.Month, 1);
            var endDate   = startDate.AddMonths(1).AddDays(-1);
            var model     = new EnterDataModel
            {
                EntryData = new DataEntry
                {
                    StartDate = startDate,
                    EndDate   = endDate
                },
                EntryErrors = new string[] {},
                Variance    = GetVariances(initialId),
                CanRevert   = false,
                CanEdit     = true,
                ManualEntry = true,
                ViewName    = viewName
            };

            return(ViewInputType(viewName, model));
        }
Example #3
0
 private ActionResult ViewInputType(string viewName, EnterDataModel model)
 {
     return(View("~/Views/Input/Calculations/" + viewName + ".cshtml", model));
 }