public async Task <IActionResult> Summary() { if (ManagedYearPlan == null) { return(ActionIfNotChoosedManagedYearPlan()); } var fields = await _fieldRepository.GetByYearPlan(ManagedYearPlan); var operators = await _operatorRepository.GetByYearPlan(ManagedYearPlan); var withoutOperator = new SummaryDisplayGroup() { Name = "Bez ARiMR", ShowEfa = false, FuelArea = Field.GetFuelAreaWithoutOperator(fields) / 100f, TotalArea = Field.GetCultivatedAreaWithoutOperator(fields) / 100f, Plants = Field.GetPlantNameListWithoutOperator(fields).Select(x => new SummaryPlant() { Name = x, Area = Field.GetCultivatedAreaByPlantNameWithoutOperator(fields, x) / 100f, AreaPercent = (int)(100 * Field.GetCultivatedAreaByPlantNameWithoutOperator(fields, x) / Field.GetCultivatedAreaWithoutOperator(fields)) }) }; var TotalFarm = new SummaryDisplayGroup() { Name = "Całość", ShowEfa = false, FuelArea = Field.GetTotalFuelArea(fields) / 100f, TotalArea = Field.GetTotalCultivatedArea(fields) / 100f, Plants = Field.GetTotalPlantNameList(fields).Select(x => new SummaryPlant() { Name = x, Area = Field.GetTotalCultivatedAreaByPlantName(fields, x) / 100f, AreaPercent = (int)(100 * Field.GetTotalCultivatedAreaByPlantName(fields, x) / Field.GetTotalCultivatedArea(fields)) }) }; var model = new SummaryViewModel() { DisplayGroups = operators.Select(x => new SummaryDisplayGroup() { Name = x.GetName, TotalArea = x.GetTotalArea() / 100f, FuelArea = x.GetFuelArea() / 100f, ShowEfa = true, EfaPercent = x.GetEfaPercent(), Plants = x.GetPlantNameList().Select(y => new SummaryPlant() { Name = y, Area = x.GetAreaByPlant(y) / 100f, AreaPercent = (int)(100 * x.GetAreaByPlant(y) / x.GetTotalArea()) }) }).Append(withoutOperator).Append(TotalFarm) }; return(View(model)); }
public async Task <IActionResult> Index() { if (ManagedYearPlan == null) { return(ActionIfNotChoosedManagedYearPlan()); } var plants = LoggedUser.ChoosedPlants; var yearPlan2 = await _yearPlanRepository.GetByYearBack(ManagedYearPlan, 2); var yearPlan1 = await _yearPlanRepository.GetByYearBack(ManagedYearPlan, 1); var fields = await _fieldRepository.GetByYearPlan(ManagedYearPlan); var fields1 = await _fieldRepository.GetByYearPlan(yearPlan1); var fields2 = await _fieldRepository.GetByYearPlan(yearPlan2); CropPlanViewModel model = new CropPlanViewModel() { StartYear = ManagedYearPlan.StartYear, EndYear = ManagedYearPlan.EndYear, Fields = fields.Select(x => new FieldViewModel() { Id = x.Id, Name = x.Name, Area = x.GetFieldArea() / 100f, PlantId = x.Plant != null ? x.Plant.Id : Guid.NewGuid(), PlantName2 = Field.GetPlantName(fields2, x), PlantName1 = Field.GetPlantName(fields1, x), PlantVariety = x.PlantVariety, }).ToList(), Plants = plants.Select(x => new SelectListItem() { Text = x.Plant.Name, Value = x.Plant.Id.ToString(), }) }; return(View(model)); }
public async Task <IActionResult> Index() { if (ManagedYearPlan == null) { return(ActionIfNotChoosedManagedYearPlan()); } var fields = await _fieldRepository.GetByYearPlan(ManagedYearPlan); var model = fields.Select(x => new FieldViewModel() { Id = x.Id, Name = x.Name, Number = x.Number, Area = x.GetFieldArea() / 100f, }); return(View(model)); }
public async Task <IActionResult> Create(IList <AddTreatmentViewModel> model) { if (ManagedYearPlan == null) { return(ActionIfNotChoosedManagedYearPlan()); } if (!ModelState.IsValid) { var kinds = await _treatmentKindRepository.GetAll(); var fields = await _fieldRepository.GetByYearPlan(ManagedYearPlan); var fertilizers = await _fertilizerRepository.GetAll(); var KindList = new SelectList(kinds, "Id", "Name"); var FieldList = new SelectList(fields, "Id", "Name"); var FertilizerList = new SelectList(fertilizers, "Id", "Name"); ViewBag.Kinds = KindList; ViewBag.Fields = FieldList; ViewBag.Fertilizers = FertilizerList; return(View(model)); } var treatments = model.Select((x) => new Treatment { Date = x.Date, Notes = x.Notes, DosePerHa = x.DosePerHa, Composition = x.SprayingAgents, ReasonForUse = x.ReasonForUse, Field = _fieldRepository.GetById(x.FieldId).Result, Fertilizer = _fertilizerRepository.GetById(x.FertilizerId).Result, TreatmentKind = _treatmentKindRepository.GetById(x.TreatmentKindId).Result }); await _treatmentRepository.AddRange(treatments); TempData["message"] = "Pomyślnie dodano nowe zabiegi"; return(RedirectToAction("Index")); }