Exemplo n.º 1
0
        public JsonResult ReceiveShipment(Guid shipment_id)
        {
            AjaxResponse returnModel = new AjaxResponse();

            Shipment found_shipment = context.Shipments.Where(x => x.ShipmentId == shipment_id).FirstOrDefault();

            if (found_shipment != null)
            {
                ShipmentRoute route = context.ShipmentRoutes.Where(x => x.ShipmentRouteId == found_shipment.ShipmentRouteId).FirstOrDefault();
                List <ShipmentRouteDetail> route_details = context.ShipmentRouteDetails.Where(x => x.ShipmentRouteId == route.ShipmentRouteId).ToList();

                ShipmentRouteDetail previous_route = route_details.Where(x => x.ShipmentRouteDetailIndex == found_shipment.ShipmentRouteIndex).FirstOrDefault();

                found_shipment.ShipmentRouteIndex++;

                ShipmentRouteDetail current_route = route_details.Where(x => x.ShipmentRouteDetailIndex == found_shipment.ShipmentRouteIndex).FirstOrDefault();

                if (found_shipment.ShipmentRouteIndex == route_details.Count() - 1)
                {
                    found_shipment.ShipmentStatus = ShipmentStatus.Delivered;
                }
                else
                {
                    found_shipment.ShipmentStatus = ShipmentStatus.Arrived;
                }

                found_shipment.ShipmentCurrentCityId = current_route.CityId;

                ShipmentHistory history = new ShipmentHistory()
                {
                    ShipmentHistoryId = Guid.NewGuid(),
                    ShipmentId        = found_shipment.ShipmentId,
                    ShipmentStatus    = found_shipment.ShipmentStatus,
                    DispatchedCountry = previous_route.CountryId,
                    DispatchedCity    = previous_route.CityId,
                    ReceivedCountry   = current_route.CountryId,
                    ReceivedCity      = current_route.CityId,
                    UpdatedDate       = DateTime.Now
                };

                context.ShipmentHistory.Add(history);

                context.SaveChanges();
            }

            return(Json(returnModel));
        }
Exemplo n.º 2
0
        private ShipmentViewModel BindValues(Shipment shipment)
        {
            ShipmentViewModel viewModel = new ShipmentViewModel();

            List <Country>             countries           = new List <Country>();
            List <City>                cities              = new List <City>();
            ShipmentRoute              route               = new ShipmentRoute();
            List <ShipmentRouteDetail> route_details       = new List <ShipmentRouteDetail>();
            ShipmentRouteDetail        current_route_point = new ShipmentRouteDetail();
            ShipmentRouteDetail        next_route_point    = new ShipmentRouteDetail();

            countries     = context.Countries.ToList();
            cities        = context.Cities.ToList();
            route         = context.ShipmentRoutes.Where(x => x.ShipmentRouteId == shipment.ShipmentRouteId).FirstOrDefault();
            route_details = context.ShipmentRouteDetails.Where(x => x.ShipmentRouteId == shipment.ShipmentRouteId).ToList();

            if (shipment.ShipmentRouteIndex == 0)
            {
                current_route_point = route_details.Where(x => x.ShipmentRouteDetailIndex == shipment.ShipmentRouteIndex).FirstOrDefault();
                next_route_point    = route_details.Where(x => x.ShipmentRouteDetailIndex == (shipment.ShipmentRouteIndex + 1)).FirstOrDefault();

                viewModel.ShipmentNextCityId = next_route_point.CityId;
                viewModel.ShipmentNextCity   = cities.Where(x => x.CityId == next_route_point.CityId).FirstOrDefault().CityName;
            }
            else if (shipment.ShipmentRouteIndex == (route_details.Count() - 1))
            {
                current_route_point = route_details.Where(x => x.ShipmentRouteDetailIndex == shipment.ShipmentRouteIndex).FirstOrDefault();
                //next_route_point = route_details.Where(x => x.ShipmentRouteDetailIndex == (shipment.ShipmentRouteIndex + 1)).FirstOrDefault();
            }
            else
            {
                current_route_point = route_details.Where(x => x.ShipmentRouteDetailIndex == shipment.ShipmentRouteIndex).FirstOrDefault();
                next_route_point    = route_details.Where(x => x.ShipmentRouteDetailIndex == (shipment.ShipmentRouteIndex + 1)).FirstOrDefault();

                viewModel.ShipmentNextCityId = next_route_point.CityId;
                viewModel.ShipmentNextCity   = cities.Where(x => x.CityId == next_route_point.CityId).FirstOrDefault().CityName;

                //    public Guid ShipmentNextCityId { get; set; }
                //public string ShipmentNextCity { get; set; }
            }

            viewModel.ShipmentId            = shipment.ShipmentId;
            viewModel.ShipmentNo            = shipment.ShipmentNo;
            viewModel.ShipmentStatus        = shipment.ShipmentStatus.ToString();
            viewModel.ShipmentCurrentCityId = shipment.ShipmentCurrentCityId;

            viewModel.SenderCountryId      = shipment.SenderCountryId;
            viewModel.SenderCountry        = countries.Where(x => x.CountryId == shipment.SenderCountryId).FirstOrDefault().CountryName;
            viewModel.SenderCityId         = shipment.SenderCityId;
            viewModel.SenderCity           = cities.Where(x => x.CityId == shipment.SenderCityId).FirstOrDefault().CityName;
            viewModel.DestinationCountryId = shipment.DestinationCountryId;
            viewModel.DestinationCountry   = countries.Where(x => x.CountryId == shipment.DestinationCountryId).FirstOrDefault().CountryName;
            viewModel.DestinationCityId    = shipment.DestinationCityId;
            viewModel.DestinationCity      = cities.Where(x => x.CityId == shipment.DestinationCityId).FirstOrDefault().CityName;

            viewModel.ShipmentCurrentCity = cities.Where(x => x.CityId == shipment.ShipmentCurrentCityId).FirstOrDefault().CityName;
            viewModel.ShippingMethod      = shipment.ShippingMethod;
            viewModel.ShipmentRouteId     = shipment.ShipmentRouteId;
            viewModel.ShipmentRouteIndex  = shipment.ShipmentRouteIndex;

            return(viewModel);
        }