Example #1
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);
        }
Example #2
0
 /// <summary>
 /// 用于向 ShopModifyLog EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToShopModifyLog(ShopModifyLog shopModifyLog)
 {
     base.AddObject("ShopModifyLog", shopModifyLog);
 }
Example #3
0
 public void Add(ShopModifyLog modifyLog)
 {
     db.ShopModifyLog.AddObject(modifyLog);
     Save();
 }
Example #4
0
 /// <summary>
 /// 创建新的 ShopModifyLog 对象。
 /// </summary>
 /// <param name="id">Id 属性的初始值。</param>
 /// <param name="shopId">ShopId 属性的初始值。</param>
 /// <param name="modifyBy">ModifyBy 属性的初始值。</param>
 /// <param name="modifyAt">ModifyAt 属性的初始值。</param>
 public static ShopModifyLog CreateShopModifyLog(global::System.Int32 id, global::System.Int32 shopId, global::System.Int32 modifyBy, global::System.DateTime modifyAt)
 {
     ShopModifyLog shopModifyLog = new ShopModifyLog();
     shopModifyLog.Id = id;
     shopModifyLog.ShopId = shopId;
     shopModifyLog.ModifyBy = modifyBy;
     shopModifyLog.ModifyAt = modifyAt;
     return shopModifyLog;
 }