Example #1
0
        /// <summary>
        /// Creates the feedback.
        /// </summary>
        /// <param name="feedbacksData">The feedbacks data.</param>
        public void CreateFeedback(RouteNodeWithFeedbacksData feedbacksData)
        {
            var feedbackItemRepository = new FeedbackItemRepository();
            var routeRepository = new RoutesRepository();

            RouteNode routeNode = routeRepository.GetRouteNode(
                feedbacksData.OriginCityNodeId, feedbacksData.DestinationCityNodeId);

            int feedbackId = feedbackItemRepository.AddNewFeedback(routeNode.RouteNodeId, feedbacksData.UserId,
                    feedbacksData.SubmitTime);

            feedbacksData.FeedbackValues.ForEach(feedbackValue => feedbackItemRepository.AddNewFeedbackValue(new FeedbackValueData()
            {
                FeedbackId = feedbackId,
                Value = feedbackValue.Value,
                FeedbackItemId = feedbackValue.FeedbackItemId
            }));
        }
Example #2
0
        /// <summary>
        /// Adds the new feedback and get URL to route.
        /// </summary>
        /// <param name="routesNodeWithFeedbacksData">The routes node with feedbacks data.</param>
        /// <returns>Return URL to route with new feedbacks</returns>
        public string AddNewFeedbackAndGetUrlToRoute(List<RouteNodeWithFeedbacksData> routesNodeWithFeedbacksData)
        {
            RoutesRepository routeRepository = new RoutesRepository();
            FeedbackItemRepository feedbackItemRepository = new FeedbackItemRepository();
            StringBuilder track = new StringBuilder(routesNodeWithFeedbacksData.Count * 5 + routesNodeWithFeedbacksData.Count - 1);

            bool backwardOrder = routesNodeWithFeedbacksData[0].OriginCityNodeId >
                     routesNodeWithFeedbacksData[routesNodeWithFeedbacksData
                     .Count - 1].DestinationCityNodeId;

            routesNodeWithFeedbacksData.ForEach(routeWithFeedback =>
            {
                RouteNode routeNode = routeRepository.GetRouteNode(
                routeWithFeedback.OriginCityNodeId, routeWithFeedback.DestinationCityNodeId) ??
                    new RouteNode()
                    {
                        RouteNodeId = routeRepository.CreateRouteNode(routeWithFeedback.OriginCityNodeId,
                            routeWithFeedback.DestinationCityNodeId)
                    };

                int feedbackId = feedbackItemRepository.AddNewFeedback(routeNode.RouteNodeId, routeWithFeedback.UserId,
                    routeWithFeedback.SubmitTime);

                routeWithFeedback.FeedbackValues.ForEach(feedbackValue => feedbackItemRepository.AddNewFeedbackValue(new FeedbackValueData()
                {
                    FeedbackId = feedbackId,
                    Value = feedbackValue.Value,
                    FeedbackItemId = feedbackValue.FeedbackItemId
                }));

                if (!backwardOrder)
                {
                    track.Append(routeWithFeedback.OriginCityNodeId).Append("-");
                    if (routeWithFeedback.Equals(routesNodeWithFeedbacksData.Last()))
                    {
                        track.Append(routeWithFeedback.DestinationCityNodeId);
                    }
                }
                else
                {
                    track.Insert(0, routeWithFeedback.OriginCityNodeId).Insert(0, "-");
                    if (routeWithFeedback.Equals(routesNodeWithFeedbacksData.Last()))
                    {
                        track.Insert(0, routeWithFeedback.DestinationCityNodeId);
                    }
                }
            });
            BuildRoutes(routesNodeWithFeedbacksData[0].OriginCityNodeId,
                routesNodeWithFeedbacksData[routesNodeWithFeedbacksData.Count - 1].DestinationCityNodeId);

            string hash = routeRepository.GetHashByTrack(track.ToString());
            return String.Format("{0}-{1}-To-{2}", hash,
                routesNodeWithFeedbacksData.First().OriginCityNode,
                routesNodeWithFeedbacksData.Last().DestinationCityNode)
                .Replace(" ", "-")
                .Replace(",", "");
        }