Пример #1
0
        public ActionResult Feedback(int orderId)
        {
            FeedbackViewModel model = new FeedbackViewModel();
            string errorMessage = "Sorry, we are currently unable to save feedback for this order.";

            try
            {
                Result<Order> result = orderService.GetOrderById(orderId);

                if (WebSecurity.CurrentUserId != result.Data.CustomerId)
                {
                    result.Status = ResultEnum.Fail;
                }

                switch (result.Status)
                {
                    case ResultEnum.Success:
                        model.OrderId = orderId;
                        model.PackageName = result.Data.Package.Name;
                        model.Feedback = result.Data.Feedback;
                        break;

                    case ResultEnum.Fail:
                        ModelState.AddModelError("ErrorMessage", errorMessage);
                        break;

                    default:
                        ModelState.AddModelError("ErrorMessage", errorMessage);
                        break;
                }
            }
            catch
            {
                ModelState.AddModelError("ErrorMessage", errorMessage);
                return View(model);
            }

            return View(model);
        }
Пример #2
0
        public ActionResult Feedback(FeedbackViewModel model)
        {
            Order order = new Order();
            string errorMessage = "Sorry, we are currently unable to save feedback for this order.";

            if (ModelState.IsValid)
            {
                // Get the Order
                try
                {
                    Result<Order> result = orderService.GetOrderById(model.OrderId);
                    if (result.Status == ResultEnum.Success)
                    {
                        order = result.Data;
                    }
                    else
                    {
                        ModelState.AddModelError("ErrorMessage", errorMessage);
                        return View(model);
                    }
                }
                catch
                {
                    ModelState.AddModelError("ErrorMessage", errorMessage);
                    return View(model);
                }

                // Update Order
                try
                {
                    order.Feedback = model.Feedback;
                    ResultEnum result = orderService.UpdateOrder(order);

                    if (result != ResultEnum.Success)
                    {
                        ModelState.AddModelError("ErrorMessage", errorMessage);
                        return View(model);
                    }

                    ViewData["SuccessMessage"] = "Thankyou for your feedback.";
                    return View(model);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("ErrorMessage", errorMessage);
                    return View(model);
                }
            }

            ModelState.AddModelError("ErrorMessage", errorMessage);
            return View(model);
        }