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); }
/// <summary> /// 用于向 ShopComment EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddToShopComment(ShopComment shopComment) { base.AddObject("ShopComment", shopComment); }
public void Add(ShopComment shopComment) { db.ShopComment.AddObject(shopComment); Save(); }
/// <summary> /// 创建新的 ShopComment 对象。 /// </summary> /// <param name="id">Id 属性的初始值。</param> /// <param name="shopId">ShopId 属性的初始值。</param> /// <param name="userId">UserId 属性的初始值。</param> /// <param name="comment">Comment 属性的初始值。</param> /// <param name="stars">Stars 属性的初始值。</param> /// <param name="payMoney">PayMoney 属性的初始值。</param> /// <param name="deliveryTime">DeliveryTime 属性的初始值。</param> /// <param name="createTime">CreateTime 属性的初始值。</param> public static ShopComment CreateShopComment(global::System.Int32 id, global::System.Int32 shopId, global::System.Int32 userId, global::System.String comment, global::System.Int16 stars, global::System.Int16 payMoney, global::System.Int16 deliveryTime, global::System.DateTime createTime) { ShopComment shopComment = new ShopComment(); shopComment.Id = id; shopComment.ShopId = shopId; shopComment.UserId = userId; shopComment.Comment = comment; shopComment.Stars = stars; shopComment.PayMoney = payMoney; shopComment.DeliveryTime = deliveryTime; shopComment.CreateTime = createTime; return shopComment; }