Exemplo n.º 1
0
        public CalculatorViewModel GetViewModel()
        {
            var products     = _repository.Query <InventoryProduct>(x => x.Product.InstantiatingType == "Seed");
            var productItems = _selectListItemService.CreateListWithConcatinatedText(products, x => x.Product.Name, x => x.UnitType, " --> ", x => x.EntityId, true);
            var fieldItems   = _selectListItemService.CreateList <Field>(x => x.Name, x => x.EntityId, true, true);

            return(new OverseedBagsNeededCalcViewModel
            {
                FieldList = fieldItems,
                ProductList = productItems,
                CalculatorDisplayName = WebLocalizationKeys.OVERSEED_BAGS_NEEEDED_DISPLAY.ToString(),
                CalculatorName = WebLocalizationKeys.OVERSEED_BAGS_NEEEDED.ToString(),
                CalculateUrl = UrlContext.GetUrlForAction <CalculatorController>(x => x.Calculate(null)),
                SaveJSSuccssCallback = "kyt.calculator.controller.overseedBagsNeededSuccess"
            });
        }
Exemplo n.º 2
0
        public ActionResult AddEdit(AddEditTaskViewModel input)
        {
            var task = input.EntityId > 0 ? _repository.Find <Task>(input.EntityId) : new Task();

            task.ScheduledDate      = input.ScheduledDate.HasValue ? input.ScheduledDate.Value : task.ScheduledDate;
            task.ScheduledStartTime = input.ScheduledStartTime.HasValue ? input.ScheduledStartTime.Value: task.ScheduledStartTime;
            var fields    = _selectListItemService.CreateList <Field>(x => x.Name, x => x.EntityId, true, true);
            var taskTypes = _selectListItemService.CreateList <TaskType>(x => x.Name, x => x.EntityId, true);

            var dictionary = new Dictionary <string, IEnumerable <SelectListItem> >();
            IEnumerable <InventoryProduct> inventory = _repository.FindAll <InventoryProduct>();
            var chemicals = _selectListItemService.CreateListWithConcatinatedText(inventory.Where(i => i.Product.InstantiatingType == "Chemical"),
                                                                                  x => x.Product.Name,
                                                                                  x => x.UnitType,
                                                                                  "-->",
                                                                                  y => y.EntityId,
                                                                                  false);
            var fertilizer = _selectListItemService.CreateListWithConcatinatedText(inventory.Where(i => i.Product.InstantiatingType == "Fertilizer"),
                                                                                   x => x.Product.Name,
                                                                                   x => x.UnitType,
                                                                                   "-->",
                                                                                   x => x.EntityId,
                                                                                   false);
            var materials = _selectListItemService.CreateListWithConcatinatedText(inventory.Where(i => i.Product.InstantiatingType == "Material"),
                                                                                  x => x.Product.Name,
                                                                                  x => x.UnitType,
                                                                                  "-->",
                                                                                  x => x.EntityId,
                                                                                  false);
            var seeds = _selectListItemService.CreateListWithConcatinatedText(inventory.Where(i => i.Product.InstantiatingType == "Seed"),
                                                                              x => x.Product.Name,
                                                                              x => x.UnitType,
                                                                              "-->",
                                                                              x => x.EntityId,
                                                                              false);

            dictionary.Add(WebLocalizationKeys.CHEMICALS.ToString(), chemicals);
            dictionary.Add(WebLocalizationKeys.MATERIALS.ToString(), materials);
            dictionary.Add(WebLocalizationKeys.FERTILIZERS.ToString(), fertilizer);
            dictionary.Add(WebLocalizationKeys.SEEDS.ToString(), seeds);
            var availableEmployees = _repository.FindAll <Employee>().Select(x => new TokenInputDto {
                id = x.EntityId, name = x.FullName
            });
            var selectedEmployees = task.GetEmployees().Select(x => new TokenInputDto {
                id = x.EntityId, name = x.FullName
            });
            var availableEquipment = _repository.FindAll <Equipment>().Select(x => new TokenInputDto {
                id = x.EntityId, name = x.Name
            });
            var selectedEquipment = task.GetEquipment().Select(x => new TokenInputDto {
                id = x.EntityId, name = x.Name
            });

            var model = new TaskViewModel
            {                //strangly I have to itterate this or NH freaks out
                AvailableEmployees = availableEmployees.ToList(),
                SelectedEmployees  = selectedEmployees.ToList(),
                AvailableEquipment = availableEquipment.ToList(),
                SelectedEquipment  = selectedEquipment,
                FieldList          = fields,
                ProductList        = dictionary,
                TaskTypeList       = taskTypes,
                Task = task,
            };

            if (task.EntityId > 0)
            {
                model.Product = task.GetProductIdAndName();
            }
            decorateModel(input, model);
            if (input.Copy)
            {
                model.Task.EntityId = 0;
                model.Task.Complete = false;
            }

            return(PartialView("TaskAddUpdate", model));
        }