public ActionResult AddComment(FormCollection formCollection) { int shopId = int.Parse(formCollection.Get("ShopId")); string star = formCollection.Get("CommentStar"); string payMoney = formCollection.Get("PayMoney"); string deliveryTime = formCollection.Get("DeliveryTime"); string content = formCollection.Get("CommentContent"); string requestUrl = formCollection.Get("RequestUrl"); UserModel userModel = new UserModel(); ShopModel shopModel = new ShopModel(); UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name); ShopComment shopComment = new ShopComment(); shopComment.ShopId = shopId; shopComment.UserId = userInfo.Id; shopComment.Stars = String.IsNullOrWhiteSpace(star) ? (short)0 : short.Parse(star); shopComment.PayMoney = String.IsNullOrWhiteSpace(payMoney) ? (short)0 : short.Parse(payMoney); shopComment.DeliveryTime = String.IsNullOrWhiteSpace(deliveryTime) ? (short)0 : short.Parse(deliveryTime); shopComment.Comment = content; shopComment.CreateTime = DateTime.Now; shopModel.Add(shopComment); short shopAvgStars = (short)Math.Round(shopModel.GetShopComments(shopComment.ShopId).Average(r => r.Stars)); short shopAvgPayMoney = (short)Math.Round(shopModel.GetShopComments(shopComment.ShopId).Average(r => r.PayMoney)); short shopAvgDeliveryTime = (short)Math.Round(shopModel.GetShopComments(shopComment.ShopId).Average(r => r.DeliveryTime)); ShopRankingAttribute shopRankingAttr = shopModel.GetShopRankingAttribute(shopId); shopRankingAttr.Stars = shopAvgStars; shopRankingAttr.AveragePayMoney = shopAvgPayMoney; shopRankingAttr.DeliveryTime = shopAvgDeliveryTime; shopModel.Save(); Shop shopInfo = shopModel.GetShop(shopId); userModel.AddUserPoint(userInfo.Id, "对店铺 <a href=\"/shop/detail/" + shopId + "\">" + shopInfo.Name + "</a> 发表评论", 2); userModel.AddUserMessage(userInfo.Id, "积分动态", "您因对店铺 <a href=\"/shop/detail/" + shopId + "\">" + shopInfo.Name + "</a>进行了评论而获得了" + 2 + "点积分。"); return Redirect(requestUrl); }