示例#1
0
        public async Task <ActionResult> Edit(int id, UpdateRouteCommentModel comment)
        {
            try
            {
                var oldComment = new RouteCommentViewModel(await CommentService.GetByCommentIdAsync(id));
                await CommentService.UpdateCommentAsync(new services.models.UpdateComment
                {
                    CommentId    = id,
                    Status       = (comment.IsInternal ? 2 : 3),
                    ShortComment = comment.Category,
                    LongComment  = comment.LongComment,
                    UpdatedBy    = LastFirstName.ToUpperInvariant()
                });

                return(RedirectToAction("ListByBillToShipTo", new { billTo = comment.BillTo, shipTo = comment.ShipTo, stopNumber = comment.StopNumber, routePlanId = oldComment.RoutePlanId, centerNumber = comment.CenterNumber, screen = comment.Screen }));
            }
            catch
            {
                return(null);
            }
        }
示例#2
0
        public async Task <ActionResult> Move(MoveStopViewModel model)
        {
            try
            {
                model.CreatedBy = LastFirstName.ToUpperInvariant();
                await RouteService.MoveStopAsync(model);

                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.OK));
            }
            catch (System.Net.Http.HttpRequestException e)
            {
                if (e.Message.Contains("404"))
                {
                    return(new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound));
                }
                if (e.Message.Contains("409"))
                {
                    return(new HttpStatusCodeResult(System.Net.HttpStatusCode.Conflict));
                }
                throw e;
            }
        }
示例#3
0
        public async Task <ActionResult> CommonCreate(CreateRouteCommentModel comment)
        {
            try
            {
                await CommentService.AddCommentAsync(new services.models.AddComment
                {
                    CenterNumber      = comment.CenterNumber,
                    CreatedBy         = LastFirstName.ToUpperInvariant(),
                    Status            = (comment.IsInternal ? 2 : 3),
                    PrimaryRecordId   = $"{comment.BillTo}-{comment.ShipTo}",
                    SecondaryRecordId = comment.RoutePlanId.ToString(),
                    Screen            = comment.Screen,
                    ShortComment      = comment.Category,
                    LongComment       = comment.LongComment
                });

                return(RedirectToAction("ListByBillToShipTo", new { billTo = comment.BillTo, shipTo = comment.ShipTo, stopNumber = comment.StopNumber, routePlanId = comment.RoutePlanId, centerNumber = comment.CenterNumber, screen = comment.Screen }));
            }
            catch
            {
                return(null);
            }
        }
        public async Task <ActionResult> ChangeStopTime(UpdateRouteWithStopsViewModel route)
        {
            var updatedRouteStopList = new List <atm.services.models.UpdateStop>();
            var stops = route.Stops;

            //Get the current version of the route from the API
            var existingRoute = await RouteService.GetByRouteIdAsync(route.RouteId);

            var existingRouteStops = existingRoute.RouteStops;

            for (int x = 0; x < stops.Count(); x++)
            {
                var existingStop = existingRouteStops.Single(s => s.RoutePlanId == stops[x].RoutePlanId);
                var updatedStop  = new UpdateStop()
                {
                    RoutePlanId = stops[x].RoutePlanId,
                    RouteId     = stops[x].RouteId,
                    BillTo      = stops[x].BillTo,
                    ShipTo      = stops[x].ShipTo,
                    AdjustedDeliveryDateTime  = stops[x].AdjustedDeliveryDateTime,
                    ScheduledDeliveryDateTime = stops[x].ScheduledDeliveryDateTime,
                    Comment   = stops[x].LastCustomerCommunicationComment,
                    EarlyLate = stops[x].EarlyLate,
                    RoutePlanModificationTypeId = stops[x].RoutePlanModificationTypeId,
                    RouteNumber         = stops[x].RouteNumber,
                    AdjustedRouteNumber = stops[x].AdjustedRouteNumber,
                    StopNumber          = stops[x].AdjustedStopNumber,
                    AdjustedStopNumber  = stops[x].AdjustedStopNumber,
                };
                //Set the comment to empty string if value is null otherwise leave it alone
                existingStop.Comment = existingStop.Comment ?? "";
                updatedStop.Comment  = updatedStop.Comment ?? "";

                //if User has updated the Comment and/or ScheduledDeliveryDateTime
                if (!System.DateTime.Equals(updatedStop.AdjustedDeliveryDateTime, existingStop.AdjustedDeliveryDateTime) || !System.DateTime.Equals(updatedStop.ScheduledDeliveryDateTime, existingStop.ScheduledDeliveryDateTime) || updatedStop.Comment != existingStop.LastCustomerCommunicationComment)
                {
                    //If stop currently has RoutePlanModificationTypeId of NONE or stop was added and time modified.
                    if (updatedStop.RoutePlanModificationTypeId == 0 || updatedStop.RoutePlanModificationTypeId == 2)
                    {
                        //Set status to Time Changed.  If the original modification type was a 2, the API will reset it back to 2.
                        updatedStop.RoutePlanModificationTypeId = 3;
                    }

                    if (updatedStop.StopNumber != existingStop.StopNumber)
                    {
                        updatedStop.IncludesStopChanges = true;
                    }
                    if (!System.DateTime.Equals(updatedStop.ScheduledDeliveryDateTime, existingStop.ScheduledDeliveryDateTime))
                    {
                        updatedStop.IncludesStopScheduledDateTimeChanges = true;
                        if (!System.DateTime.Equals(updatedStop.AdjustedDeliveryDateTime, updatedStop.ScheduledDeliveryDateTime))
                        {
                            updatedStop.IncludesStopAdjustedDateTimeChanges = true;
                        }
                    }
                    else
                    {
                        if (!System.DateTime.Equals(updatedStop.AdjustedDeliveryDateTime, existingStop.AdjustedDeliveryDateTime))
                        {
                            updatedStop.IncludesStopAdjustedDateTimeChanges = true;
                        }
                    }


                    //Save the stop
                    updatedRouteStopList.Add(updatedStop);
                }
            }

            var updateRouteWithStops = new UpdateRouteWithStops()
            {
                SygmaCenterNo = route.SygmaCenterNo,
                RouteNumber   = route.RouteNumber,
                RouteId       = route.RouteId,
                RouteName     = route.RouteName,
                RouteStops    = updatedRouteStopList
            };

            await RouteService.UpdateRouteAsync(route.RouteNumber, route.SygmaCenterNo, updateRouteWithStops);

            foreach (var stop in updateRouteWithStops.RouteStops)
            {
                if (!string.IsNullOrEmpty(stop.Comment.Trim()))
                {
                    var existingStop = existingRouteStops.Single(s => s.RoutePlanId == stop.RoutePlanId);
                    if (existingStop.LastCustomerCommunicationComment != stop.Comment)
                    {
                        await CommentService.AddCommentAsync(new services.models.AddComment
                        {
                            CenterNumber      = updateRouteWithStops.SygmaCenterNo,
                            CreatedBy         = LastFirstName.ToUpperInvariant(),
                            Status            = 3, // non-internal
                            PrimaryRecordId   = $"{((int)stop.BillTo).ToString()}-{((int)stop.ShipTo).ToString()}",
                            SecondaryRecordId = stop.RoutePlanId.ToString(),
                            Screen            = "RT",
                            ShortComment      = "Customer Communication",
                            LongComment       = stop.Comment
                        });
                    }
                }

                if (stop.IncludesStopChanges)
                {
                    var existingStop = existingRouteStops.Single(s => s.RoutePlanId == stop.RoutePlanId);
                    await CommentService.AddCommentAsync(new services.models.AddComment
                    {
                        CenterNumber      = updateRouteWithStops.SygmaCenterNo,
                        CreatedBy         = LastFirstName.ToUpperInvariant(),
                        Status            = 2, // internal
                        PrimaryRecordId   = $"{((int)stop.BillTo).ToString()}-{((int)stop.ShipTo).ToString()}",
                        SecondaryRecordId = stop.RoutePlanId.ToString(),
                        Screen            = "RT",
                        ShortComment      = "Stop Adjustment",
                        LongComment       = $"Stop moved from Stop: {stop.StopNumber} at {existingStop.AdjustedDeliveryDateTime} to Stop: {stop.AdjustedStopNumber} at {stop.AdjustedDeliveryDateTime}"
                    });
                }

                if (stop.IncludesStopAdjustedDateTimeChanges)
                {
                    var existingStop = existingRouteStops.Single(s => s.RoutePlanId == stop.RoutePlanId);
                    await CommentService.AddCommentAsync(new services.models.AddComment
                    {
                        CenterNumber      = updateRouteWithStops.SygmaCenterNo,
                        CreatedBy         = LastFirstName.ToUpperInvariant(),
                        Status            = 2, // internal
                        PrimaryRecordId   = $"{((int)stop.BillTo).ToString()}-{((int)stop.ShipTo).ToString()}",
                        SecondaryRecordId = stop.RoutePlanId.ToString(),
                        Screen            = "RT",
                        ShortComment      = "Time Adjustment",
                        LongComment       = $"Stop {stop.StopNumber} adjusted delivery was changed from {existingStop.AdjustedDeliveryDateTime} to {stop.AdjustedDeliveryDateTime}"
                    });
                }
                if (stop.IncludesStopScheduledDateTimeChanges)
                {
                    var existingStop = existingRouteStops.Single(s => s.RoutePlanId == stop.RoutePlanId);
                    await CommentService.AddCommentAsync(new services.models.AddComment
                    {
                        CenterNumber      = updateRouteWithStops.SygmaCenterNo,
                        CreatedBy         = LastFirstName.ToUpperInvariant(),
                        Status            = 2, // internal
                        PrimaryRecordId   = $"{((int)stop.BillTo).ToString()}-{((int)stop.ShipTo).ToString()}",
                        SecondaryRecordId = stop.RoutePlanId.ToString(),
                        Screen            = "RT",
                        ShortComment      = "Time Adjustment",
                        LongComment       = $"Stop {stop.StopNumber} scheduled delivery was changed from {existingStop.ScheduledDeliveryDateTime} to {stop.ScheduledDeliveryDateTime}"
                    });
                }
            }

            return(new HttpStatusCodeResult(System.Net.HttpStatusCode.Created));
        }