예제 #1
0
        public ActionResult EditSettings(int?ShopID, FormCollection collection)
        {
            var list = new List <ShopSetting>();

            foreach (var shopSetting in CharListDef)
            {
                var settings =
                    DB.ShopSettings.FirstOrDefault(
                        x => x.ShopID == (ShopID ?? DefShopID) && x.ItemKey == shopSetting.ItemKey);
                if (settings == null)
                {
                    settings = new ShopSetting()
                    {
                        ItemKey = shopSetting.ItemKey,
                        Name    = shopSetting.Name,
                        ShopID  = (ShopID ?? DefShopID)
                    };
                    DB.ShopSettings.InsertOnSubmit(settings);
                }
                settings.Value = (string)collection.GetValue(shopSetting.ItemKey).ConvertTo(typeof(string));
                list.Add(settings);
            }
            DB.SubmitChanges();
            ViewBag.Message = "Данные успешно сохранены";
            return(View(list));
        }
예제 #2
0
 public string this[string key]
 {
     get
     {
         ShopSetting setting = null;
         setting = (from ShopSetting settings in this.LINQEnumarable.Where(x => string.Compare(x.key, key, true) == 0)
                    select settings).SingleOrDefault();
         return(setting.value);
     }
 }
예제 #3
0
        public ActionResult EditSettings(int?ShopID)
        {
            ViewBag.NoShops = !CurrentUser.ShopList.Any();

            var charListDef = new ShopSetting[CharListDef.Count];

            CharListDef.CopyTo(charListDef);
            var settings = DB.ShopSettings.Where(x => x.ShopID == (ShopID ?? DefShopID)).ToList();

            foreach (var shopSetting in charListDef)
            {
                var s = settings.FirstOrDefault(x => x.ItemKey == shopSetting.ItemKey);
                if (s != null)
                {
                    shopSetting.Value = s.Value;
                }
            }
            return(View(charListDef));
        }
 public ActionResult Index(ShopSettingViewModel shopSetting)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (_shopSettingRepository.All.Count() == 0)
             {
                 _shopSettingRepository.Add(new ShopSetting()
                 {
                     Id              = Guid.NewGuid().ToString(),
                     PageName        = shopSetting.PageName,
                     Pagetitle       = shopSetting.Pagetitle,
                     PageDescription = shopSetting.PageDescription,
                     Keyword         = shopSetting.Keyword,
                     TaxPercent      = shopSetting.TaxPercent
                 });
                 _shopSettingRepository.Save(requestContext);
             }
             else
             {
                 ShopSetting s = _shopSettingRepository.All.Where(s => s.Id == shopSetting.Id).First();
                 s.PageName        = shopSetting.PageName;
                 s.Pagetitle       = shopSetting.Pagetitle;
                 s.PageDescription = shopSetting.PageDescription;
                 s.Keyword         = shopSetting.Keyword;
                 s.TaxPercent      = shopSetting.TaxPercent;
                 _shopSettingRepository.Save(requestContext);
             }
         }
         catch (Exception)
         {
             return(View(_shopSettingRepository.GetShopSettingViewModel()));
         }
         return(View(_shopSettingRepository.GetShopSettingViewModel()));
     }
     return(View(_shopSettingRepository.GetShopSettingViewModel()));
 }
 public void Execute()
 {
     if (!isRunned)
     {
         var needReturn = false;
         lock (_lock)
         {
             if (isRunned)
             {
                 needReturn = true;
             }
             else
             {
                 isRunned = true;
             }
         }
         if (needReturn)
         {
             return;
         }
         try
         {
             using (Db _db = new Db())
             {
                 var lastProductID = _db.ShopSettings.FirstOrDefault(x => x.Key == LASTIDKEY);
                 int lastID        = 0;
                 if (lastProductID != null)
                 {
                     int.TryParse(lastProductID.Value, out lastID);
                     lastProductID.Value = (lastID + porsionLimit).ToString();
                     _db.SaveChanges();
                 }
                 else
                 {
                     lastProductID = new ShopSetting()
                     {
                         Key = LASTIDKEY, Value = (lastID + porsionLimit).ToString()
                     };
                     _db.ShopSettings.Add(lastProductID);
                     _db.SaveChanges();
                 }
                 int pictureSize = LS.Get <Settings>().FirstOrDefault().ProductBoxImageSize;
                 if (pictureSize == 0)
                 {
                     pictureSize = 174;
                 }
                 var products = _db.Products.Where(x => x.HasImage && x.ID > lastID)
                                .Select(x => new
                 {
                     x.ID,
                     x.Image
                 }).Take(porsionLimit).ToList();
                 if (products.Count == 0)
                 {
                     //reset position
                     lastProductID.Value = 0.ToString();
                     _db.SaveChanges();
                 }
                 foreach (var p in products)
                 {
                     try
                     {
                         SF.GetImage(p.Image, pictureSize, pictureSize, true, true);
                     }
                     catch { }
                 }
             }
         }
         finally
         {
             isRunned = false;
         }
     }
 }