public ActionResult AddFeedback(RDLeaveFeedbackModel id, string[] controlValue, string[] feedbackItemId, string returnUrl) { if (TempData["mandatoryFeedbackItemId"] != null) { var mandatoryFeedbackItemId = (int[])TempData["mandatoryFeedbackItemId"]; if (controlValue.Length == feedbackItemId.Length ) { List<int> mandatoryFeedbackItemIdList = new List<int>(mandatoryFeedbackItemId); id.RDLeaveFeedbackValues = new List<RDLeaveFeedbackValue>(); for (int i = 0; i < controlValue.Length; i++) { if (controlValue[i].Contains(RoadHelper.JsUndefined)) { controlValue[i] = ""; } int controlId; if ((Int32.TryParse(feedbackItemId[i], out controlId) && mandatoryFeedbackItemIdList.Exists(item => item == controlId) && String.IsNullOrEmpty(controlValue[i])) || String.IsNullOrEmpty(id.UserName)) { TempData["AddFeedbackError"] = true; return Redirect(returnUrl); } id.RDLeaveFeedbackValues.Add(new RDLeaveFeedbackValue { Value = controlValue[i], FeedbackItemId = feedbackItemId[i] }); } id.SubmitTime = DateTime.Now; id.UserId = client.GetUserIdOrCreateNewIfNotExist(id.UserName, id.UserName, "TestUserRole"); ; RoadHelper.CreateNewFeedback(client, id); } } return Redirect(returnUrl); }
/// <summary> /// Creates the new feedback. /// </summary> /// <param name="client">The client.</param> /// <param name="leaveFeedback">The leave feedback.</param> public static void CreateNewFeedback(IRoadsService client, RDLeaveFeedbackModel leaveFeedback) { var valueList = new List<FeedbackValueData>(); leaveFeedback.RDLeaveFeedbackValues.ForEach(m => { int feedbackItemId; if (int.TryParse(m.FeedbackItemId, out feedbackItemId)) { valueList.Add(new FeedbackValueData { FeedbackItemId = feedbackItemId, Value = m.Value }); } }); var newFeedback = new RouteNodeWithFeedbacksData { DestinationCityNodeId = leaveFeedback.DestinationCityId, OriginCityNodeId = leaveFeedback.OriginCityId, SubmitTime = leaveFeedback.SubmitTime, UserId = leaveFeedback.UserId, FeedbackValues = valueList.ToArray() }; client.CreateFeedback(newFeedback); }