Exemplo n.º 1
0
 public async Task <IEnumerable <Field> > GetByYearPlan(YearPlan yearplan)
 {
     return(await DbInclude(_context.Fields)
            .Where(x => x.YearPlan == yearplan)
            .OrderBy(x => x.Number)
            .ToListAsync());
 }
        public async Task <IActionResult> Index()
        {
            var Users = await _userRepository.GetAll();

            var YearPlans = await _yearPlanRepository.GetAll();

            var Treatments = await _treatmentRepository.GetAll();

            var FieldsCount        = YearPlan.GetTotalFieldsCount(YearPlans);
            var FieldsArea         = YearPlan.GetTotalFieldsArea(YearPlans);
            var YearPlansCount     = YearPlans.Count();
            var InActiveUsersCount = AgroSup.Core.Domain.User.GetInActiveUsers(Users).Count();
            var TreatmentsCount    = Treatments.Count();

            var Model = new SummaryViewModel
            {
                TotalUsers       = Users.Count(),
                AverageFieldArea = Math.Round((double)FieldsArea / (YearPlansCount * 100), 2),
                AverageTreatmentCountPerField = Math.Round((double)TreatmentsCount / FieldsCount, 2),
                AverageYearPlansCountPerUser  = Math.Round((double)YearPlans.Count() / Users.Count(), 2),
                InActiveAccounts = InActiveUsersCount,
            };

            return(View(Model));
        }
Exemplo n.º 3
0
        private async Task <int> GetNumberForNewField(YearPlan yearPlan)
        {
            var yearPlanFields = await _fieldRepository.GetByYearPlan(yearPlan);

            if (yearPlanFields.Count() > 0)
            {
                return(yearPlanFields.Max(x => x.Number) + 1);
            }
            return(1);
        }
Exemplo n.º 4
0
        public async Task <YearPlan> GetByYearBack(YearPlan yearPlan, int backYear)
        {
            var startYear = yearPlan.StartYear - backYear;
            var user      = yearPlan.User;

            return(await _context.YearPlans
                   .Where(x => x.User == user)
                   .Where(x => x.StartYear == startYear)
                   .FirstOrDefaultAsync());
        }
Exemplo n.º 5
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.º 6
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"));
        }
Exemplo n.º 7
0
 public async Task <IEnumerable <Treatment> > GetAllByYearPlan(YearPlan yearPlan)
 {
     return(await DbInclude(_context.Treatments)
            .Where(x => x.Field.YearPlan == yearPlan)
            .ToListAsync());
 }
 public async Task <IEnumerable <Operator> > GetByYearPlan(YearPlan yearplan)
 {
     return(await DbInclude(_context.Operators)
            .Where(x => x.YearPlan == yearplan)
            .ToListAsync());
 }
Exemplo n.º 9
0
        public ActionResult btnSubmit_YearPlan_Click(string[] Grid1_fields, JArray Grid1_modifiedData, int pageIndex)
        {
            foreach (JObject mergedRow in Grid1_modifiedData)
            {
                string  status   = mergedRow.Value <string>("status");
                int     rowIndex = mergedRow.Value <int>("index");
                JObject values   = mergedRow.Value <JObject>("values");

                if (status == "modified")
                {
                    int id = mergedRow.Value <int>("id");

                    YearPlan yp = db.YearPlan.Where(p => p.ID == id).FirstOrDefault();

                    string Factory      = values.Value <string>("Factory");
                    int?   Year         = values.Value <int?>("Year");
                    double?SellYearPlan = values.Value <double?>("SellYearPlan");
                    double?YearPlan1    = values.Value <double?>("YearPlan1");

                    if (Factory != null)
                    {
                        yp.Factory = Factory;
                    }
                    if (Year != null)
                    {
                        yp.Year = (int)Year;
                    }
                    if (SellYearPlan != null)
                    {
                        yp.SellYearPlan = (double)SellYearPlan;
                    }
                    if (YearPlan1 != null)
                    {
                        yp.YearPlan1 = (double)YearPlan1;
                    }

                    db.SaveChanges();
                }
                else if (status == "newadded")
                {
                    YearPlan yp = new YearPlan();

                    string Factory      = values.Value <string>("Factory");
                    int?   Year         = values.Value <int?>("Year");
                    double?SellYearPlan = values.Value <double?>("SellYearPlan");
                    double?YearPlan1    = values.Value <double?>("YearPlan1");

                    if (Factory != null)
                    {
                        yp.Factory = Factory;
                    }
                    if (Year != null)
                    {
                        yp.Year = (int)Year;
                    }
                    if (SellYearPlan != null)
                    {
                        yp.SellYearPlan = (double)SellYearPlan;
                    }
                    if (YearPlan1 != null)
                    {
                        yp.YearPlan1 = (double)YearPlan1;
                    }


                    db.YearPlan.Add(yp);
                    db.SaveChanges();
                }
                else if (status == "deleted")
                {
                    int id = mergedRow.Value <int>("id");

                    YearPlan yp = db.YearPlan.Where(p => p.ID == id).FirstOrDefault();

                    db.YearPlan.Remove(yp);

                    db.SaveChanges();
                }
            }

            List <YearPlan> ypList;

            ypList = db.YearPlan.ToList();

            var dataSource = PagingHelper <YearPlan> .GetPagedDataTable(pageIndex, 20, ypList.Count(), ypList);

            UIHelper.Grid("Grid1").DataSource(dataSource, Grid1_fields);
            Alert.Show("操作成功!");

            return(UIHelper.Result());
        }
Exemplo n.º 10
0
 public async Task Update(YearPlan YearPlan)
 {
     _context.Update(YearPlan);
     await _context.SaveChangesAsync();
 }
Exemplo n.º 11
0
 public async Task Delete(YearPlan YearPlan)
 {
     _context.Remove(YearPlan);
     await _context.SaveChangesAsync();
 }
Exemplo n.º 12
0
 public async Task Add(YearPlan yearPlan)
 {
     _context.YearPlans.Add(yearPlan);
     await _context.SaveChangesAsync();
 }
Exemplo n.º 13
0
 public override void OnActionExecuting(ActionExecutingContext context)
 {
     base.OnActionExecuting(context);
     LoggedUser      = GetLoggedUser();
     ManagedYearPlan = GetManagedYearPlan(LoggedUser);
 }