Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public void AddNewOrderDetail(int userId, OrderDetail orderDetail)
        {
            UserOrderDetail order = new UserOrderDetail();
            ShopModel sm = new ShopModel();
            int orderId = sm.GetAvailableUserOrderId();

            try
            {
                UserModel um = new UserModel();
                UserInfo userInfo = um.GetUserInfo(userId);

                order.OrderId = orderId;
                order.DisheId = orderDetail.DisheId;
                order.ShopId = orderDetail.ShopId;
                order.UserId = userInfo.Id;
                order.Price = orderDetail.Price;
                order.OrderCount = orderDetail.Count;
                order.CreateDate = DateTime.Now;

                sm.Add(order);

                orderDetail.Id = order.Id;

                orderDetail.Available = 1;
            }
            catch (Exception ex)
            {

            }

            orderDetail.Available = 1;
            List<string> managers = _ClientInfos.Where(r => r.Value.GradeLevel == 9 || r.Key == userId)
                .Select(r => r.Value.ConnectionId).ToList();

            Clients.Clients(managers).broadcastOrderAdd(new List<OrderDetail> { orderDetail });

            orderDetail.Available = 0;
            Clients.AllExcept(managers.ToArray()).broadcastOrderAdd(new List<OrderDetail> { orderDetail });
        }
Exemplo n.º 3
0
        public ActionResult Edit(string shopData)
        {
            UserModel userModel = new UserModel();
            UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);
            ShopModel shopModel = new ShopModel();
            var jser = new System.Web.Script.Serialization.JavaScriptSerializer();
            ShopEditorObject shopDataObj = jser.Deserialize<ShopEditorObject>(shopData);
            ShopWithSAObject newShopInfo = shopDataObj.ShopBaseInfo;
            int shopId = newShopInfo.Id;

            Shop shopInfo = shopModel.GetShop(shopId);
            if(userInfo.UserGradeCategory.GradeLevel != 9 && userInfo.Id != shopInfo.CreateBy)
                return Redirect("/");
            shopInfo.Name = newShopInfo.Name;
            shopInfo.Address = newShopInfo.Address;
            shopInfo.PhoneNumber = newShopInfo.PhoneNumber;
            shopInfo.CategoryId = newShopInfo.CategoryId;
            shopInfo.OfficeTimeBegin = newShopInfo.OfficeTimeBegin;
            shopInfo.OfficeTimeEnd = newShopInfo.OfficeTimeEnd;
            shopInfo.UpSendPrice = newShopInfo.UpSendPrice;
            shopInfo.Remark = newShopInfo.Remark;
            shopInfo.Latitude = newShopInfo.Latitude;
            shopInfo.Longitude = newShopInfo.Longitude;
            shopInfo.LastModifyAt = DateTime.Now;
            shopInfo.LastModifyBy = userInfo.Id;

            if (!String.IsNullOrWhiteSpace(newShopInfo.Logo))
            {
                string sourcePath = Server.MapPath(newShopInfo.Logo);
                string fileName = Path.GetFileName(sourcePath);
                if (!System.IO.File.Exists(Server.MapPath("~/Contents/ShopImages/") + fileName))
                    System.IO.File.Move(sourcePath, Server.MapPath("~/Contents/ShopImages/") + fileName);
                newShopInfo.Logo = fileName;
            }
            else
                newShopInfo.Logo = new Random().Next(1, 7) + ".jpg";
            shopInfo.Logo = newShopInfo.Logo;
            shopModel.Save();

            ShopModifyLog editLog = new ShopModifyLog();
            editLog.ShopId = shopId;
            editLog.ModifyBy = userInfo.Id;
            editLog.ModifyAt = DateTime.Now;
            shopModel.Add(editLog);

            shopModel.DeleteShopServiceAreas(shopId);
            if (newShopInfo.ServiceAreas != null)
            {
                foreach (int saItem in newShopInfo.ServiceAreas)
                {
                    ShopServiceArea shopServiceArea = new ShopServiceArea();
                    shopServiceArea.ShopId = shopId;
                    shopServiceArea.AreaId = saItem;
                    shopModel.AddWithoutSave(shopServiceArea);
                }
                shopModel.Save();
            }

            shopModel.DeleteDisheCategories(shopId);
            shopModel.DeleteDishes(shopId);
            List<DisheWithCategoryDetailObject> disheWithCats = shopDataObj.DisheWithCategoryDetail;
            foreach (DisheWithCategoryDetailObject dwcItem in disheWithCats)
            {
                ShopDisheCategory disheCategory = new ShopDisheCategory();
                disheCategory.ShopId = shopId;
                disheCategory.Value = dwcItem.CategoryName;
                shopModel.Add(disheCategory);

                foreach (ShopDishe disheItem in dwcItem.Dishes)
                {
                    ShopDishe dishe = disheItem;
                    dishe.ShopId = shopId;
                    dishe.CategoryId = disheCategory.Id;
                    shopModel.AddWithoutSave(dishe);
                }
                shopModel.Save();
            }

            return Json(new { status = 1, url = "/shop/detail/" + shopId }, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 4
0
        public ActionResult CreateNewUserOrder()
        {
            ShopModel sm = new ShopModel();
            UserModel um = new UserModel();

            int availableOrderId = sm.GetAvailableUserOrderId();

            if(availableOrderId != -1)
                return Json(new { status = 0, msg = availableOrderId }, JsonRequestBehavior.AllowGet);

            UserOrder order = new UserOrder();

            UserInfo userInfo = um.GetUserInfo(User.Identity.Name);
            order.Available = true;
            order.CreateBy = userInfo.Id;
            order.CreateTime = DateTime.Now;
            try
            {
                sm.Add(order);
            }
            catch(Exception ex)
            {
                return Json(new { status = 0, msg = ex.Message }, JsonRequestBehavior.AllowGet);
            }

            return Json(new { status = 1, msg = order.Id }, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 5
0
        public ActionResult Create(string shopData)
        {
            ShopModel shopModel = new ShopModel();
            var jser = new System.Web.Script.Serialization.JavaScriptSerializer();
            ShopEditorObject shopDataObj = jser.Deserialize<ShopEditorObject>(shopData);
            ShopWithSAObject newShopInfo = shopDataObj.ShopBaseInfo;
            UserModel userModel = new UserModel();
            UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);

            Shop shopInfo = new Shop();
            shopInfo.Name = newShopInfo.Name;
            shopInfo.Address = newShopInfo.Address;
            shopInfo.PhoneNumber = newShopInfo.PhoneNumber;
            shopInfo.CategoryId = newShopInfo.CategoryId;
            shopInfo.OfficeTimeBegin = newShopInfo.OfficeTimeBegin;
            shopInfo.OfficeTimeEnd = newShopInfo.OfficeTimeEnd;
            shopInfo.UpSendPrice = newShopInfo.UpSendPrice;
            shopInfo.Remark = newShopInfo.Remark;
            shopInfo.Latitude = newShopInfo.Latitude;
            shopInfo.Longitude = newShopInfo.Longitude;
            shopInfo.CreateTime = DateTime.Now;
            shopInfo.LastModifyAt = shopInfo.CreateTime;
            shopInfo.CreateBy = userInfo.Id;
            shopInfo.LastModifyBy = shopInfo.CreateBy;
            shopInfo.Hidden = true;
            if (!String.IsNullOrWhiteSpace(newShopInfo.Logo))
            {
                string sourcePath = Server.MapPath(newShopInfo.Logo);
                string fileName = Path.GetFileName(sourcePath);
                if (!System.IO.File.Exists(Server.MapPath("~/Contents/ShopImages/") + fileName))
                    System.IO.File.Move(sourcePath, Server.MapPath("~/Contents/ShopImages/") + fileName);
                newShopInfo.Logo = fileName;
            }
            else
                newShopInfo.Logo = new Random().Next(1, 7) + ".jpg";
            shopInfo.Logo = newShopInfo.Logo;
            shopModel.Add(shopInfo);
            shopModel.Save();

            int shopId = shopInfo.Id;

            shopModel.DeleteShopServiceAreas(shopId);
            if (newShopInfo.ServiceAreas != null)
            {
                foreach (int saItem in newShopInfo.ServiceAreas)
                {
                    ShopServiceArea shopServiceArea = new ShopServiceArea();
                    shopServiceArea.ShopId = shopId;
                    shopServiceArea.AreaId = saItem;
                    shopModel.AddWithoutSave(shopServiceArea);
                }
                shopModel.Save();
            }
            try
            {
                shopModel.DeleteDisheCategories(shopId);
                shopModel.DeleteDishes(shopId);
                double totalPrice = 0;
                List<DisheWithCategoryDetailObject> disheWithCats = shopDataObj.DisheWithCategoryDetail;
                foreach(DisheWithCategoryDetailObject dwcItem in disheWithCats)
                {
                    ShopDisheCategory disheCategory = new ShopDisheCategory();
                    disheCategory.ShopId = shopId;
                    disheCategory.Value = dwcItem.CategoryName;
                    shopModel.Add(disheCategory);

                    foreach(ShopDishe disheItem in dwcItem.Dishes)
                    {
                        ShopDishe dishe = disheItem;
                        dishe.ShopId = shopId;
                        dishe.CategoryId = disheCategory.Id;
                        shopModel.AddWithoutSave(dishe);
                        totalPrice += dishe.Price;
                    }
                    shopModel.Save();
                }

                ShopRankingAttribute rankingAttribute = new ShopRankingAttribute();
                rankingAttribute.ShopId = shopId;
                rankingAttribute.Stars = 0;
                rankingAttribute.AveragePayMoney = (short)(totalPrice / disheWithCats.Select(r => r.Dishes.Count).Sum(r => r));
                rankingAttribute.DeliveryTime = 30;
                shopModel.Add(rankingAttribute);
            }
            catch(Exception ex)
            {
                return Json(new { status = 0, data = ex.InnerException }, JsonRequestBehavior.AllowGet);
            }

            return Json(new { status = 1, url = "/shop/detail/" + shopId }, JsonRequestBehavior.AllowGet);
        }