Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
 public void Add(Shop shop)
 {
     db.Shop.AddObject(shop);
     Save();
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 用于向 Shop EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToShop(Shop shop)
 {
     base.AddObject("Shop", shop);
 }
Ejemplo n.º 4
0
 public ShopDetailEditorModel(Shop shopInfo, List<V_ShopDisheWithCategory> disheWithCategory)
 {
     ShopInfo = shopInfo;
     ShopDishesList = disheWithCategory;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 创建新的 Shop 对象。
 /// </summary>
 /// <param name="id">Id 属性的初始值。</param>
 /// <param name="name">Name 属性的初始值。</param>
 /// <param name="address">Address 属性的初始值。</param>
 /// <param name="phoneNumber">PhoneNumber 属性的初始值。</param>
 /// <param name="officeTimeBegin">OfficeTimeBegin 属性的初始值。</param>
 /// <param name="officeTimeEnd">OfficeTimeEnd 属性的初始值。</param>
 /// <param name="stars">Stars 属性的初始值。</param>
 /// <param name="upSendPrice">UpSendPrice 属性的初始值。</param>
 /// <param name="deliveryTime">DeliveryTime 属性的初始值。</param>
 /// <param name="longitude">Longitude 属性的初始值。</param>
 /// <param name="latitude">Latitude 属性的初始值。</param>
 /// <param name="categoryId">CategoryId 属性的初始值。</param>
 /// <param name="hidden">Hidden 属性的初始值。</param>
 /// <param name="createTime">CreateTime 属性的初始值。</param>
 /// <param name="createBy">CreateBy 属性的初始值。</param>
 /// <param name="lastModifyBy">LastModifyBy 属性的初始值。</param>
 /// <param name="lastModifyAt">LastModifyAt 属性的初始值。</param>
 public static Shop CreateShop(global::System.Int32 id, global::System.String name, global::System.String address, global::System.String phoneNumber, global::System.TimeSpan officeTimeBegin, global::System.TimeSpan officeTimeEnd, global::System.Int16 stars, global::System.Int16 upSendPrice, global::System.Int16 deliveryTime, global::System.Double longitude, global::System.Double latitude, global::System.Int32 categoryId, global::System.Boolean hidden, global::System.DateTime createTime, global::System.Int32 createBy, global::System.Int32 lastModifyBy, global::System.DateTime lastModifyAt)
 {
     Shop shop = new Shop();
     shop.Id = id;
     shop.Name = name;
     shop.Address = address;
     shop.PhoneNumber = phoneNumber;
     shop.OfficeTimeBegin = officeTimeBegin;
     shop.OfficeTimeEnd = officeTimeEnd;
     shop.Stars = stars;
     shop.UpSendPrice = upSendPrice;
     shop.DeliveryTime = deliveryTime;
     shop.Longitude = longitude;
     shop.Latitude = latitude;
     shop.CategoryId = categoryId;
     shop.Hidden = hidden;
     shop.CreateTime = createTime;
     shop.CreateBy = createBy;
     shop.LastModifyBy = lastModifyBy;
     shop.LastModifyAt = lastModifyAt;
     return shop;
 }