public IActionResult PostParcel(ClientParcelViewModel clientParcelViewModel)
        {
            if (ModelState.IsValid)
            {
                clientParcelService.PostOnline(clientParcelViewModel);
                int senderBranchCode = int.Parse(new string(clientParcelViewModel.SenderPostalCode.Take(2).ToArray()));

                var queryModel = (from branches in context.Branches
                                  join parcels in context.Parcels on branches.BranchId equals parcels.LastBranchId
                                  where branches.BranchCode == senderBranchCode
                                  select new ParcelSummaryViewModel
                {
                    ParcelId = parcels.ParcelId,
                    BranchName = branches.BranchName,
                    BranchAddress = branches.BranchAddress,
                    BranchCity = branches.City
                }
                                  );

                ParcelSummaryViewModel model = new ParcelSummaryViewModel
                {
                    ParcelId      = queryModel.First().ParcelId,
                    BranchName    = queryModel.First().BranchName,
                    BranchAddress = queryModel.First().BranchAddress,
                    BranchCity    = queryModel.First().BranchCity
                };

                return(RedirectToAction("ThanksPage", model));
            }

            return(View());
        }
示例#2
0
        public async Task <IActionResult> ParcelSummary()
        {
            if (ManagedYearPlan == null)
            {
                return(ActionIfNotChoosedManagedYearPlan());
            }

            var operators = await _operatorRepository.GetByYearPlan(ManagedYearPlan);

            var fields = await _fieldRepository.GetByYearPlan(ManagedYearPlan);

            IList <Parcel> parcels = new List <Parcel>();

            foreach (var field in fields)
            {
                foreach (var parcel in field.Parcels)
                {
                    parcels.Add(parcel);
                }
            }
            var userPlants = LoggedUser.ChoosedPlants;

            var model = new ParcelSummaryViewModel()
            {
                OperatorSelectList = operators.Select(x => new SelectListItem()
                {
                    Text  = x.GetName,
                    Value = x.GetName
                }),
                PlantSelectList = userPlants.Select(x => new SelectListItem()
                {
                    Text  = x.Plant.Name,
                    Value = x.Plant.Name
                }),
                Parcels = parcels.Select(x => new ParcelSummaryParcel()
                {
                    FieldName       = x.Field.Name,
                    CultivatedArea  = x.CultivatedArea / 100f,
                    FuelApplication = x.GetFuelApplication(),
                    Number          = x.Number,
                    OperatorName    = x.GetOperatorName(),
                    PlantName       = x.GetPlantName(),
                })
            };

            return(View(model));
        }
 public IActionResult ThanksPage(ParcelSummaryViewModel model)
 {
     return(View(model));
 }