Exemplo n.º 1
0
        public void GetDataToImportTest()
        {
            // Arrange
            var yearPlanToImportData = new YearPlan()
            {
                Fields = new List <Field>()
                {
                    new Field()
                    {
                        Parcels = new List <Parcel>()
                        {
                            new Parcel()
                            {
                                CultivatedArea = 12, FuelApplication = true, Number = "844/1"
                            },
                            new Parcel()
                            {
                                CultivatedArea = 2, FuelApplication = false, Number = "844/5"
                            }
                        }
                    }
                },
                Operators = new List <Operator>()
                {
                    new Operator()
                    {
                        FirstName = "Jan", LastName = "Kowalski"
                    }
                }
            };

            var newYearPlan = new YearPlan();

            // Act
            newYearPlan.GetDataToImport(yearPlanToImportData);
            // Assert
            Assert.AreEqual(yearPlanToImportData.Fields.Count(), newYearPlan.Fields.Count());
            Assert.AreEqual(yearPlanToImportData.Operators.Count(), newYearPlan.Operators.Count());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create(YearPlanViewModel model, Guid yearPlanImportId)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            var yearPlan = new YearPlan()
            {
                StartYear = model.StartYear,
                EndYear   = model.StartYear + 1,
                User      = LoggedUser,
            };

            var yearPlanImport = await _yearPlanRepository.GetByIdToImport(yearPlanImportId);

            if (yearPlanImport != null)
            {
                yearPlan.GetDataToImport(yearPlanImport);
            }
            await _yearPlanRepository.Add(yearPlan);

            TempData["message"] = "Utworzono nowy plan: " + yearPlan.GetYearPlanName;
            return(RedirectToAction("Create"));
        }