예제 #1
0
        public JsonResult GiveFeedback(GiveFeedbackViewModel model)
        {
            if (model.ReceiverId != null && ModelState.IsValid && Enum.IsDefined(typeof(Emotions), model.Grade))
            {
                if (model.Comment.Trim() == "")
                {
                    return(null);
                }
                if (model.OrderId != null)
                {
                    Order order = _orderService.GetOrder(model.OrderId.Value, i => i.Seller, i => i.Buyer, i => i.Feedbacks,
                                                         i => i.Seller.FeedbacksMy, i => i.Buyer.FeedbacksMy, i => i.Seller.FeedbacksToOthers, i => i.Buyer.FeedbacksToOthers);

                    if (order != null && order.BuyerId == model.ReceiverId && order.SellerId == User.Identity.GetUserId() && !order.SellerFeedbacked)
                    {
                        order.SellerFeedbacked = true;
                        var feedback = Mapper.Map <GiveFeedbackViewModel, Feedback>(model);

                        if (feedback.Grade == Emotions.Good)
                        {
                            order.Buyer.PositiveFeedbackCount++;
                        }
                        else if (feedback.Grade == Emotions.Bad)
                        {
                            order.Buyer.NegativeFeedbackCount++;
                        }

                        order.Feedbacks.Add(feedback);
                        order.Buyer.FeedbacksMy.Add(feedback);
                        order.Seller.FeedbacksToOthers.Add(feedback);
                        _feedbackService.CreateFeedback(feedback);
                        _feedbackService.SaveFeedback();
                        return(Json(new { }));
                    }
                    else if (order != null && order.Seller.Id == model.ReceiverId && order.BuyerId == User.Identity.GetUserId() && !order.BuyerFeedbacked)
                    {
                        order.BuyerFeedbacked = true;
                        var feedback = Mapper.Map <GiveFeedbackViewModel, Feedback>(model);

                        if (feedback.Grade == Emotions.Good)
                        {
                            order.Seller.PositiveFeedbackCount++;
                        }
                        else if (feedback.Grade == Emotions.Bad)
                        {
                            order.Seller.NegativeFeedbackCount++;
                        }
                        order.Feedbacks.Add(feedback);
                        order.Seller.FeedbacksMy.Add(feedback);
                        order.Buyer.FeedbacksToOthers.Add(feedback);
                        _feedbackService.CreateFeedback(feedback);
                        _feedbackService.SaveFeedback();
                        return(Json(new { }));
                    }
                }
            }
            return(null);
        }
예제 #2
0
        // GET: Feedback/Create
        public ActionResult GiveToSeller(string receiverId, int?orderId)
        {
            if (receiverId != null && orderId != null)
            {
                GiveFeedbackViewModel model = new GiveFeedbackViewModel()
                {
                    ReceiverId = receiverId,
                    OrderId    = orderId.Value
                };
                return(View(model));
            }

            return(HttpNotFound());

            //ViewBag.UserProfileId = new SelectList(db.UserProfiles, "Id", "Discription");
        }
예제 #3
0
        public ActionResult GiveToSeller(GiveFeedbackViewModel model)
        {
            if (model.ReceiverId != null && ModelState.IsValid && Enum.IsDefined(typeof(Emotions), model.Grade))
            {
                if (model.OrderId != null)
                {
                    Order order = _orderService.GetOrder(model.OrderId.Value, i => i.Seller, i => i.Buyer, i => i.Feedbacks);

                    if (order != null && order.Seller.Id == model.ReceiverId && order.BuyerId == User.Identity.GetUserId() && !order.BuyerFeedbacked)
                    {
                        order.BuyerFeedbacked = true;
                        var feedback = Mapper.Map <GiveFeedbackViewModel, Feedback>(model);

                        if (feedback.Grade == Emotions.Good)
                        {
                            order.Seller.PositiveFeedbackCount++;
                        }
                        else if (feedback.Grade == Emotions.Bad)
                        {
                            order.Seller.NegativeFeedbackCount++;
                        }
                        order.Feedbacks.Add(feedback);
                        order.Seller.FeedbacksMy.Add(feedback);
                        order.Buyer.FeedbacksToOthers.Add(feedback);
                        _feedbackService.CreateFeedback(feedback);

                        _orderService.UpdateOrder(order);
                        _userProfileService.UpdateUserProfile(order.Seller);
                        _userProfileService.UpdateUserProfile(order.Buyer);
                        _feedbackService.SaveFeedback();
                        return(View(model));
                    }
                }
            }
            return(HttpNotFound());
        }