Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void GetUpdateCurrentVechileObject(VehicleObject obj, List<UpdateCurrentVechileObject> routes)
- {
- var dbAllEnumRouteStatus = m_vehicleService.AllEnumRouteStatus();
- string RouteCurrentStatusIsAwating = "", RouteCurrentStatusIsNew = "", RouteCurrentStatusIsDelivered = "", MapLocationName = "london";
- Guid? id = obj.Guid;
- var availableSequences = m_vehicleService.GetAvailableSequences(id.Value);
- var origin = obj.Route.RoutePoints.OrderBy(x => x.Sequence).FirstOrDefault();
- var sourceId = origin.Id;
- var destination = obj.Route.RoutePoints.OrderByDescending(x => x.Sequence).FirstOrDefault();
- var destinationId = destination.Id;
- var lastHubSequence = destination.Sequence;
- /* 0 - Origin Address
- 1 - Origin Store
- 2 - Origin HUb
- Last 3 Destination
- Destination HUb
- Destination Store
- Destination Address
- */
- int totalRoute = obj.Route.RoutePoints.Count;
- int endHubCount = totalRoute > 2 ? (totalRoute - 3) : 0;
- obj.Route.RoutePoints.ForEach(x =>
- {
- var d = new UpdateCurrentVechileObject()
- {
- Id = x.Id,
- Location = x.Location,
- Sequence = x.Sequence,
- SequenceName = "",
- IsOrigin = false,
- IsDestination = false,
- DestinationSequence = lastHubSequence,
- EnableButton = availableSequences.FirstOrDefault(s => s == x.Sequence) != 0,
- AvailableStatus = new List<KeyValue>(),
- IsCurrent = x.IsCurrent,
- ShowAddHubButton = false,
- HubAvailableSequence = new List<KeyValue>()
- };
- if (x.Sequence == 0)
- {
- d.SequenceName = "Origin";
- d.IsOrigin = true;
- }
- else if (x.Sequence == 1)
- {
- d.SequenceName = "Origin Store";
- }
- else if (x.Sequence == totalRoute - 1)
- {
- d.SequenceName = "Destination";
- d.IsDestination = true;
- }
- else if (x.Sequence == totalRoute - 2)
- {
- d.SequenceName = "Destination Store";
- }
- else
- {
- d.SequenceName = "Hub";
- }
- if (x.Sequence >= 2 && x.Sequence < endHubCount)
- {
- d.ShowAddHubButton = true;
- for (int i = x.Sequence; i < endHubCount; i++)
- {
- d.HubAvailableSequence.Add(new KeyValue()
- {
- Key = (i + 1).ToString(),
- Value = $"{AddOrdinal(i)} Hub"
- });
- }
- }
- if (d.EnableButton)
- {
- m_vehicleService.GetAvailableStatus(id.Value, x.Sequence).ForEach(sq =>
- {
- //Skip , New, Awaiting Pickup , delivered
- if (sq != EnumRouteStatus.New && sq != EnumRouteStatus.AwaitingPickup && sq != EnumRouteStatus.Delivered)
- {
- d.AvailableStatus.Add(new KeyValue()
- {
- Key = ((int)sq).ToString(),
- Value = dbAllEnumRouteStatus.FirstOrDefault(rs => rs.Id == (int)sq).Desc
- });
- }
- });
- d.AvailableStatus = d.AvailableStatus.OrderBy(avs => avs.Value).ToList();
- }
- if (d.IsOrigin)
- {
- /*if RouteStaus is "New", the button should be disabled. */
- if (obj.Route.RouteStatus == EnumRouteStatus.New)
- {
- d.EnableButton = false;
- }
- else
- {
- d.EnableButton = true;
- }
- }
- routes.Add(d);
- });
- //origin will be current location if RouteStaus is New
- var r = routes.FirstOrDefault(x => x.IsOrigin && obj.Route.RouteStatus == EnumRouteStatus.New);
- if (r != null)
- {
- routes.ForEach(x =>
- {
- if (x.IsOrigin)
- {
- x.IsCurrent = true;
- }
- else
- {
- x.IsCurrent = false;
- }
- });
- }
- if (obj.Route != null)
- {
- if (obj.Route.RouteStatus.HasValue)
- {
- ViewBag.CurrentRouteStatus = dbAllEnumRouteStatus.FirstOrDefault(x => x.Id == (int)obj?.Route?.RouteStatus)?.Desc;
- RouteCurrentStatusIsAwating = obj.Route.RouteStatus == EnumRouteStatus.AwaitingPickup ? "true" : "false";
- RouteCurrentStatusIsNew = obj.Route.RouteStatus == EnumRouteStatus.New ? "true" : "false";
- RouteCurrentStatusIsDelivered = obj.Route.RouteStatus == EnumRouteStatus.Delivered ? "true" : "false";
- }
- ViewBag.RouteCurrentSequence = obj.Route.CurrentSequence;
- //if current status is "AwaitingPickup" and current sequence=2, show the current location to the first address not the hub
- if (ViewBag.RouteCurrentSequence == 2 && RouteCurrentStatusIsAwating == "true")
- {
- if (origin != null)
- {
- MapLocationName = origin.Location.Name;
- }
- }
- //if current status is "new" show the current location to the first address not the hub
- if (RouteCurrentStatusIsNew == "true")
- {
- if (origin != null)
- {
- MapLocationName = origin.Location.Name;
- }
- }
- }
- if (MapLocationName == "london")
- {
- if (obj.CurrentLocation != null)
- {
- MapLocationName = obj.CurrentLocation.Name;
- }
- }
- // string RouteCurrentStatusIsAwating = "", RouteCurrentStatusIsNew = "", RouteCurrentStatusIsDelivered = "", MapLocationName= "london";
- ViewBag.MapLocationName = MapLocationName;
- ViewBag.RouteCurrentStatusIsDelivered = RouteCurrentStatusIsDelivered;
- ViewBag.RouteCurrentStatusIsNew = RouteCurrentStatusIsNew;
- ViewBag.RouteCurrentStatusIsAwating = RouteCurrentStatusIsAwating;
- ViewBag.CurrentLocationName = obj.CurrentLocation?.Name;
- }
- private string AddOrdinal(int num)
- {
- if (num <= 0) return num.ToString();
- switch (num % 100)
- {
- case 11:
- case 12:
- case 13:
- return num + "th";
- }
- switch (num % 10)
- {
- case 1:
- return num + "st";
- case 2:
- return num + "nd";
- case 3:
- return num + "rd";
- default:
- return num + "th";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement