private void AddWithoutCheck(DataCacheObject obj)
 {
   CacheItemPolicy policy = new CacheItemPolicy();
   policy.AbsoluteExpiration = DateTime.Now + TimeSpan.FromSeconds(obj.CacheTime);
   lock (Cache)
     Cache.Add(new CacheItem(GetKey(obj), obj.Data), policy);
 }
 public void Add(DataCacheObject obj)
 {
     if (Contains(obj))
     {
         Remove(obj);
     }
     AddWithoutCheck(obj);
 }
 public void Update(DataCacheObject obj)
 {
     if (!Contains(obj))
     {
         return;
     }
     UpdateWithoutCheck(obj);
 }
 public void Remove(DataCacheObject obj)
 {
     if (!Contains(obj))
     {
         return;
     }
     Cache.Remove(GetKey(obj));
 }
        private void AddWithoutCheck(DataCacheObject obj)
        {
            CacheItemPolicy policy = new CacheItemPolicy();

            policy.AbsoluteExpiration = DateTime.Now + TimeSpan.FromSeconds(obj.CacheTime);
            lock (Cache)
                Cache.Add(new CacheItem(GetKey(obj), obj.Data), policy);
        }
    public void ClearARP(int id)
    {
      ICacheDataProvider cacheRepository;
      if (Consts.DataCachingTechnology == DataCacheTechnology.MEMORYOBJECT) cacheRepository = new CacheDataProvider();
      else cacheRepository = new AppFabricCacheProviderSystemRegions(Consts.ProductName);

      DataCacheObject dco = new DataCacheObject(DataCacheType.RESOURCE, DataCacheRegions.AUCTIONS, "GETAUCTIONDETAILRESULTPAST", new object[] { id });
      cacheRepository.Remove(dco);
      Logger.LogInfo("[Cache removed: " + DataCacheType.RESOURCE + "_" + DataCacheRegions.AUCTIONS + "_GETAUCTIONDETAILRESULTPAST" + "_" + id + "]");
    }
        //Add
        public void Add(DataCacheObject obj)
        {
            if (Contains(obj))
            {
                Remove(obj);
            }
            DataCache dc = GetDataCache(obj.Type.ToString());

            dc.Put(GetKey(obj), obj.Data, TimeSpan.FromSeconds(obj.CacheTime));
        }
        //Remove
        public void Remove(DataCacheObject obj)
        {
            if (!Contains(obj))
            {
                return;
            }
            DataCache dc = GetDataCache(obj.Type.ToString());

            dc.Remove(GetKey(obj));
        }
 //Put
 public void Put(DataCacheObject obj)
 {
     try{
         DataCache dc = GetDataCache(obj.Type.ToString());
         dc.Put(GetKey(obj), obj.Data, TimeSpan.FromSeconds(obj.CacheTime));
     }
     catch (Exception ex)
     {
         Logger.LogException("APPFABRICCACHEPROVIDERSYSTEMREGIONS_PUT", ex);
     }
 }
 public void Put(DataCacheObject obj)
 {
     if (!Contains(obj))
     {
         AddWithoutCheck(obj);
     }
     else
     {
         UpdateWithoutCheck(obj);
     }
 }
 //GetByCriterias
 private List<AuctionShort> GetByCriterias(string lot, string title, int sortby, bool ordrby, long event_id,
     int pageindex, int pagesize, out int? totalrecord)
 {
     title = String.IsNullOrEmpty(title) ? String.Empty : title.Replace(" ", "%");
     var dco = new DataCacheObject(DataCacheType.RESOURCE, DataCacheRegions.AUCTIONLISTS, "GETBYCRITERIAS",
         new object[] {lot, title, sortby, ordrby, event_id, pageindex, pagesize},
         CachingExpirationTime.Seconds_30);
     var result = CacheRepository.Get(dco) as TableViewResult;
     if (result != null && result.TotalRecords > 0)
     {
         totalrecord = result.TotalRecords;
         return result.Records;
     }
     result = new TableViewResult();
     totalrecord = 0;
     dataContext.CommandTimeout = 600000;
     result.Records =
         (from p in
             dataContext.spAuction_View_Search(event_id, lot, title, String.Empty, -1, -1, sortby - 1, ordrby,
                 pageindex, pagesize, ref totalrecord)
             select new AuctionShort
             {
                 Bids = p.Bids.GetValueOrDefault(0),
                 CurrentBid = p.CurrentBid.GetValueOrDefault(0),
                 Estimate = p.Estimate,
                 IsBold = p.IsBold.GetValueOrDefault(false),
                 IsFeatured = p.IsFeatured.GetValueOrDefault(false),
                 IsUnsoldOrPulledOut =
                     p.IsUnsold.GetValueOrDefault(false) || p.IsPulledOut.GetValueOrDefault(false),
                 LinkParams =
                     new LinkParams
                     {
                         ID = p.Auction_ID.GetValueOrDefault(0),
                         EventTitle = p.EventTitle,
                         MainCategoryTitle = p.MainCategoryTitle,
                         CategoryTitle = p.CategoryTitle
                     },
                 Lot = p.Lot.HasValue ? p.Lot.Value : (short) 0,
                 Price = p.Price.GetValueOrDefault(0),
                 PriceRealized = p.PriceRealized.GetValueOrDefault(0),
                 PulledOut = p.IsPulledOut.GetValueOrDefault(false),
                 Status = p.AuctionStatus.GetValueOrDefault(0),
                 ThumbnailPath = p.ThumbnailPath,
                 Title = p.Title,
                 UnsoldOrPulledOut = p.IsUnsold.GetValueOrDefault(false) ? "UNSOLD" : "WITHDRAWN"
             }).ToList();
     result.TotalRecords = totalrecord.GetValueOrDefault(0);
     if (result.TotalRecords > 0)
     {
         dco.Data = result;
         CacheRepository.Add(dco);
     }
     return result.Records;
 }
 public void Put(DataCacheObject obj)
 {
     try
     {
         DataCache dc = GetDataCache(obj.Type.ToString());
         dc.Put(GetKey(obj), obj.Data, TimeSpan.FromSeconds(obj.CacheTime), obj.Region);
     }
     catch (Exception ex)
     {
         Logger.LogException(obj.Method, ex);
     }
 }
 //Get
 public object Get(DataCacheObject obj)
 {
     try
     {
         DataCache dc = GetDataCache(obj.Type.ToString());
         return(dc.Get(GetKey(obj)));
     } catch (Exception ex)
     {
         Logger.LogException("APPFABRICCACHEPROVIDERSYSTEMREGIONS_GET", ex);
         return(null);
     }
 }
        //Update
        public void Update(DataCacheObject obj)
        {
            DataCache dc = GetDataCache(obj.Type.ToString());

            if (!Contains(obj))
            {
                return;
            }
            DataCacheItem dci = dc.GetCacheItem(GetKey(obj));

            dc.Put(GetKey(obj), obj.Data, dci.Version, dci.Timeout);
        }
 //Get
 public object Get(DataCacheObject obj)
 {
   try
   {
     DataCache dc = GetDataCache(obj.Type.ToString());
     return dc.Get(GetKey(obj));
   } catch(Exception ex)
   {
     Logger.LogException("APPFABRICCACHEPROVIDERSYSTEMREGIONS_GET", ex);
     return null;
   }
 }
 //GetCurrent()
 public Event GetCurrent()
 {
   DataCacheObject dco = new DataCacheObject(DataCacheType.REFERENCE, DataCacheRegions.EVENTS, "GETCURRENT", null, CachingExpirationTime.Hours_01);
   Event evnt = CacheRepository.Get(dco) as Event;
   if (evnt != null) return evnt;
   evnt = dataContext.spEvent_Current().FirstOrDefault();
   if (evnt != null)
   {
     dco.Data = evnt;
     CacheRepository.Add(dco);
   }
   return evnt;
 }
 public object Get(DataCacheObject obj)
 {
   try
   {
     DataCache dc = GetDataCache(obj.Type.ToString());
     return dc.Get(GetKey(obj), obj.Region);
   }
   catch (DataCacheException ex)
   {
     Logger.LogException(obj.Method, ex);
   }
   return null;
 }
 public List<DataCacheObject> AllCache()
 {
     List<DataCacheObject> result = new List<DataCacheObject>();
       DataCacheObject dco;
       foreach (var c in Cache)
       {
     dco = new DataCacheObject();
     dco.Data = c.Value;
     dco.Method = c.Key;
     result.Add(dco);
       }
       return result;
 }
 public void Add(DataCacheObject obj)
 {
   try
   {
     if (Contains(obj)) Remove(obj);
     DataCache dc = GetDataCache(obj.Type.ToString());
     dc.Put(GetKey(obj), obj.Data, TimeSpan.FromSeconds(obj.CacheTime), obj.Region);
   }
   catch (DataCacheException ex)
   {
     Logger.LogException(obj.Method, ex);
   }
 }
 public object Get(DataCacheObject obj)
 {
     try
     {
         DataCache dc = GetDataCache(obj.Type.ToString());
         return(dc.Get(GetKey(obj), obj.Region));
     }
     catch (DataCacheException ex)
     {
         Logger.LogException(obj.Method, ex);
     }
     return(null);
 }
 //Add
 public void Add(DataCacheObject obj)
 {
   try
   {
     if (Contains(obj)) Remove(obj);
     DataCache dc = GetDataCache(obj.Type.ToString());
     dc.Put(GetKey(obj), obj.Data, TimeSpan.FromSeconds(obj.CacheTime));
   }
   catch (Exception ex)
   {
     Logger.LogException("APPFABRICCACHEPROVIDERSYSTEMREGIONS_ADD", ex);
   }
 }
 //GetPastedEventsList
 public List<Event> GetPastedEventsList()
 {
   DataCacheObject dco = new DataCacheObject(DataCacheType.REFERENCE, DataCacheRegions.EVENTS, "GETPASTEDEVENTSLIST",
                                              new object[] { }, CachingExpirationTime.Hours_01);
   List<Event> result = CacheRepository.Get(dco) as List<Event>;
   if (result != null) return result;
   result = dataContext.spEvent_PastList().ToList();
   if (result.Any())
   {
     dco.Data = result;
     CacheRepository.Add(dco);
   }
   return result;
 }
        public List <DataCacheObject> AllCache()
        {
            List <DataCacheObject> result = new List <DataCacheObject>();
            DataCacheObject        dco;

            foreach (var c in Cache)
            {
                dco        = new DataCacheObject();
                dco.Data   = c.Value;
                dco.Method = c.Key;
                result.Add(dco);
            }
            return(result);
        }
 //GetCountries
 public List<Country> GetCountries()
 {
   var dco = new DataCacheObject(DataCacheType.REFERENCE, DataCacheRegions.COUNTRIES, "GETCOUNTRIES", new object[] { },
     CachingExpirationTime.Days_01);
   var result = _cacheRepository.Get(dco) as List<Country>;
   if (result != null) return result;
   result = _dataContext.spCountry_List().ToList();
   if (result.Any())
   {
     dco.Data = result;
     _cacheRepository.Add(dco);
   }
   return result;
 }
 //GetConsignment
 public Consignment GetConsignment(long consignment_id)
 {
   DataCacheObject dco = new DataCacheObject(DataCacheType.ACTIVITY, DataCacheRegions.INVOICES, "GETCONSIGNMENT",
                                             new object[] { consignment_id }, CachingExpirationTime.Hours_01);
   Consignment result = CacheRepository.Get(dco) as Consignment;
   if (result != null) return result;
   result = dataContext.spSelect_Consignment(consignment_id).FirstOrDefault();
   if (result != null)
   {
     dco.Data = result;
     CacheRepository.Add(dco);
   }
   return result;
 }
 //GetUserInvoice
 public UserInvoice GetUserInvoice(long userinvoice_id)
 {
   DataCacheObject dco = new DataCacheObject(DataCacheType.ACTIVITY, DataCacheRegions.INVOICES, "GETUSERINVOICE",
                                             new object[] { userinvoice_id }, CachingExpirationTime.Hours_01);
   UserInvoice ui = CacheRepository.Get(dco) as UserInvoice;
   if (ui != null) return ui;
   ui = dataContext.spSelect_UserInvoices(userinvoice_id).FirstOrDefault();
   if (ui != null)
   {
     dco.Data = ui;
     CacheRepository.Add(dco);
   }
   return ui;
 }
 //GetCountry
 public Country GetCountry(long countryID)
 {
   var dco = new DataCacheObject(DataCacheType.REFERENCE, DataCacheRegions.COUNTRIES, "GETCOUNTRY",
     new object[] { countryID }, CachingExpirationTime.Days_01);
   var result = _cacheRepository.Get(dco) as Country;
   if (result != null) return result;
   result = _dataContext.spCountry_List().FirstOrDefault(t => t.ID == countryID);
   if (result != null)
   {
     dco.Data = result;
     _cacheRepository.Add(dco);
   }
   return result;
 }
 //GetTopBidForItem
 public BidCurrent GetTopBidForItem(long auction_id, bool fromcache = true)
 {
   DataCacheObject dco = new DataCacheObject(DataCacheType.RESOURCE, DataCacheRegions.BIDS, "GETTOPBIDFORITEM", new object[] { auction_id }, CachingExpirationTime.Hours_01);
   BidCurrent result = CacheRepository.Get(dco) as BidCurrent;
   if (result != null && fromcache) return new BidCurrent(result);
   dataContext.CommandTimeout = 600000;
   result = dataContext.spBid_WinningBid(auction_id).FirstOrDefault();
   if (result != null)
   {
     dco.Data = result;
     CacheRepository.Add(dco);
   }
   return result != null ? new BidCurrent(result) : null;
 }
        public void Put(DataCacheObject obj)
        {
            DataCacheItem dci = new DataCacheItem();

            try
            {
                DataCache dc = GetDataCache(obj.Type.ToString());
                dc.Put(GetKey(obj), obj.Data, TimeSpan.FromSeconds(obj.CacheTime), obj.Region);
            }
            catch (DataCacheException ex)
            {
                Logger.LogException(obj.Method + " ~ " + String.Format("cached_value:{0}; new_value:{1}", dci.Value, obj.Data), ex);
            }
        }
 //GetStates
 public List<State> GetStates(long? countryID)
 {
   var dco = new DataCacheObject(DataCacheType.REFERENCE, DataCacheRegions.STATES, "GETSTATES",
     new object[] { countryID.GetValueOrDefault(0) }, CachingExpirationTime.Days_01);
   var result = _cacheRepository.Get(dco) as List<State>;
   if (result != null) return result;
   result = _dataContext.spState_List(countryID).ToList();
   if (result.Any())
   {
     dco.Data = result;
     _cacheRepository.Add(dco);
   }
   return result;
 }
 //GetEventByID
 public Event GetEventByID(long event_id)
 {
   DataCacheObject dco = new DataCacheObject(DataCacheType.REFERENCE, DataCacheRegions.EVENTS, "GETEVENTBYID",
                                              new object[] { event_id }, CachingExpirationTime.Hours_01);
   Event evnt = CacheRepository.Get(dco) as Event;
   if (evnt != null) return evnt;
   evnt = dataContext.spSelect_Event(event_id).SingleOrDefault();
   if (evnt != null)
   {
     dco.Data = evnt;
     CacheRepository.Add(dco);
   }
   return evnt;
 }
 //Remove
 public void Remove(DataCacheObject obj)
 {
     try{
         if (!Contains(obj))
         {
             return;
         }
         DataCache dc = GetDataCache(obj.Type.ToString());
         dc.Remove(GetKey(obj));
     }
     catch (Exception ex)
     {
         Logger.LogException("APPFABRICCACHEPROVIDERSYSTEMREGIONS_REMOVE", ex);
     }
 }
 //GetAuctionImages
 public List<Image> GetAuctionImages(long auctionID)
 {
   var dco = new DataCacheObject(DataCacheType.RESOURCE, DataCacheRegions.IMAGES, "GETAUCTIONIMAGES",
     new object[] { auctionID }, CachingExpirationTime.Minutes_30);
   var result = _cacheRepository.Get(dco) as List<Image>;
   if (result != null && result.Any()) return result;
   _dataContext.CommandTimeout = 600000;
   result = _dataContext.spAuction_GetAuctionImages(auctionID).ToList();
   if (result.Any())
   {
     dco.Data = result;
     _cacheRepository.Add(dco);
   }
   return result;
 }
 public void Add(DataCacheObject obj)
 {
     try
     {
         if (Contains(obj))
         {
             Remove(obj);
         }
         DataCache dc = GetDataCache(obj.Type.ToString());
         dc.Add(GetKey(obj), obj.Data, TimeSpan.FromSeconds(obj.CacheTime), obj.Region);
     }
     catch (Exception ex)
     {
         Logger.LogException(obj.Method, ex);
     }
 }
 //Update
 public void Update(DataCacheObject obj)
 {
     try{
         DataCache dc = GetDataCache(obj.Type.ToString());
         if (!Contains(obj))
         {
             return;
         }
         DataCacheItem dci = dc.GetCacheItem(GetKey(obj));
         dc.Put(GetKey(obj), obj.Data, dci.Version, dci.Timeout);
     }
     catch (Exception ex)
     {
         Logger.LogException("APPFABRICCACHEPROVIDERSYSTEMREGIONS_UPDATE", ex);
     }
 }
 public void Remove(DataCacheObject obj)
 {
     try
     {
         if (!Contains(obj))
         {
             return;
         }
         DataCache dc = GetDataCache(obj.Type.ToString());
         dc.Remove(GetKey(obj), obj.Region);
     }
     catch (DataCacheException ex)
     {
         Logger.LogException(obj.Method, ex);
     }
 }
 public void Update(DataCacheObject obj)
 {
     try
     {
         if (!Contains(obj))
         {
             return;
         }
         DataCache     dc  = GetDataCache(obj.Type.ToString());
         DataCacheItem dci = dc.GetCacheItem(GetKey(obj), obj.Region);
         dc.Put(GetKey(obj), obj.Data, dci.Timeout, obj.Region);
     }
     catch (Exception ex)
     {
         Logger.LogException(obj.Method, ex);
     }
 }
        public void Update(DataCacheObject obj)
        {
            DataCacheItem dci = new DataCacheItem();

            try
            {
                DataCache dc = GetDataCache(obj.Type.ToString());
                if (!Contains(obj))
                {
                    return;
                }
                dci = dc.GetCacheItem(GetKey(obj), obj.Region);
                dc.Put(GetKey(obj), obj.Data, dci.Version, dci.Timeout, obj.Region);
            }
            catch (DataCacheException ex)
            {
                Logger.LogException(obj.Method + " ~ " + String.Format("cached_value:{0}; new_value:{1}", dci.Value, obj.Data), ex);
            }
        }
 //RemoveUserFromCache
 public void RemoveUserFromCache(long user_id, string email)
 {
   User usr = GetUser(user_id, true);
   RemoveUserObjectCache(user_id);
   DataCacheObject dco = new DataCacheObject(DataCacheType.ACTIVITY, DataCacheRegions.USERS, "GETREGISTERINFO", new object[] { user_id });
   CacheRepository.Remove(dco);
   if (usr != null)
   {
     dco.Method = "GETADDRESSCARD";
     dco.Params = new object[] {usr.Billing_AddressCard_ID};
     CacheRepository.Remove(dco);
   }
   if (usr != null && usr.Shipping_AddressCard_ID.HasValue)
   {
     dco.Method = "GETADDRESSCARD";
     dco.Params = new object[] { usr.Shipping_AddressCard_ID.GetValueOrDefault(0) };
     CacheRepository.Remove(dco);
   }
   dco.Method = "GETUSERBYEMAIL";
   dco.Params = new object[] {email};
   CacheRepository.Remove(dco);
 }
 //GetUserReferences
 public UserReference GetUserReferences(long userreference_id)
 {
   DataCacheObject dco = new DataCacheObject(DataCacheType.ACTIVITY, DataCacheRegions.USERS, "GETUSERREFERENCES",
                                             new object[] { userreference_id }, CachingExpirationTime.Minutes_30);
   UserReference result = CacheRepository.Get(dco) as UserReference;
   if (result != null) return result;
   result = dataContext.UserReferences.Where(ur => ur.IDReference == userreference_id).SingleOrDefault();
   if (result != null)
   {
     dco.Data = result;
     CacheRepository.Add(dco);
   }
   return result;      
 }
    //GetRegisterInfo
    public RegisterInfo GetRegisterInfo(long user_id)
    {
      DataCacheObject dco = new DataCacheObject(DataCacheType.ACTIVITY, DataCacheRegions.USERS, "GETREGISTERINFO",
                                                new object[] { user_id }, CachingExpirationTime.Minutes_30);
      RegisterInfo info = CacheRepository.Get(dco) as RegisterInfo;
      if (info != null) return info;
      info = new RegisterInfo();

      IUser user = GetUser(user_id, true);
      if (user == null) return null;

      info.ID = user.ID;
      info.Login = user.Login;
      info.Email = user.Email;
      info.ConfirmEmail = user.Email;
      info.Password = user.Password;
      info.ConfirmPassword = user.Password;
      info.RecieveNewsUpdates = user.RecieveNewsUpdates.GetValueOrDefault(false);
      info.RecieveWeeklySpecials = user.RecieveWeeklySpecials.GetValueOrDefault(false);
      info.Fax = user.Fax;      
      info.BillingLikeShipping = user.BillingLikeShipping;
      info.MobilePhone = user.MobilePhone;
      info.TaxpayerID = user.TaxpayerID;
      info.EbayID = user.EbayID;
      info.DayPhone = user.DayPhone;
      info.EveningPhone = user.EveningPhone;      
      info.EbayFeedback = user.EbayFeedback;
      info.IsModifyed = user.IsModifyed;

      IAddressCard BillingCard = user.Billing_AddressCard_ID != null ? GetAddressCard(user.Billing_AddressCard_ID.GetValueOrDefault(-1), true) : new AddressCard();
      info.BillingFirstName = BillingCard.FirstName;
      info.BillingLastName = BillingCard.LastName;
      info.BillingMIName = BillingCard.MiddleName;
      info.BillingAddress1 = BillingCard.Address1;
      info.BillingAddress2 = BillingCard.Address2;
      info.BillingCity = BillingCard.City;
      info.BillingZip = BillingCard.Zip;
      info.BillingState = BillingCard.State;
      info.BillingPhone = BillingCard.HomePhone;
      info.BillingCountry = BillingCard.Country_ID;
      info.BillingCompany = BillingCard.Company;
      info.BillingInternationalState = BillingCard.InternationalState;

      IAddressCard ShippingCard = user.Shipping_AddressCard_ID != null ? GetAddressCard(user.Shipping_AddressCard_ID.GetValueOrDefault(-1), true) : new AddressCard();
      info.ShippingFirstName = ShippingCard.FirstName;
      info.ShippingLastName = ShippingCard.LastName;
      info.ShippingMIName = ShippingCard.MiddleName;
      info.ShippingAddress1 = ShippingCard.Address1;
      info.ShippingAddress2 = ShippingCard.Address2;
      info.ShippingCity = ShippingCard.City;
      info.ShippingZip = ShippingCard.Zip;
      info.ShippingState = ShippingCard.State;
      info.ShippingWorkPhone = ShippingCard.WorkPhone;
      info.ShippingPhone = ShippingCard.HomePhone;
      info.ShippingCountry = ShippingCard.Country_ID;
      info.ShippingInternationalState = ShippingCard.InternationalState;

      IUserReference Reference1 = user.IDUserReference1.HasValue ? GetUserReferences(user.IDUserReference1.GetValueOrDefault(-1)) : new UserReference();
      info.Reference1AuctionHouse = Reference1.AuctionHouse;
      info.Reference1LastBidPlaced = Reference1.LastBidPlaced;
      info.Reference1PhoneNumber = Reference1.PhoneNumber;

      IUserReference Reference2 = user.IDUserReference2.HasValue ? GetUserReferences(user.IDUserReference2.GetValueOrDefault(-1)) : new UserReference();
      info.Reference2AuctionHouse = Reference2.AuctionHouse;
      info.Reference2LastBidPlaced = Reference2.LastBidPlaced;
      info.Reference2PhoneNumber = Reference2.PhoneNumber;

      dco.Data = info;
      CacheRepository.Add(dco);

      return info;
    }
 //GetAddressCard
 public AddressCard GetAddressCard(long addresscard_id, bool iscache)
 {
   DataCacheObject dco = new DataCacheObject(DataCacheType.ACTIVITY, DataCacheRegions.USERS, "GETADDRESSCARD",
                                             new object[] { addresscard_id }, CachingExpirationTime.Minutes_30);
   AddressCard result = CacheRepository.Get(dco) as AddressCard;
   if (result != null && iscache) return result;
   result = dataContext.spSelect_AddressCard(addresscard_id).SingleOrDefault();
   if (result != null)
   {
     dco.Data = result;
     CacheRepository.Add(dco);
   }
   return result;
 }
 //GetUser
 public User GetUser(long user_id, bool iscache)
 {
   DataCacheObject dco = new DataCacheObject(DataCacheType.ACTIVITY, DataCacheRegions.USERS, "GETUSER",
                                             new object[] { user_id }, CachingExpirationTime.Minutes_10);
   User result = CacheRepository.Get(dco) as User;
   if (result != null && iscache) return result;
   result = dataContext.spSelect_User(user_id, null, null, null, null, null).SingleOrDefault();
   if (result != null)
   {
     dco.Data = result;
     CacheRepository.Add(dco);
   }
   return result;
 }
 private void UpdateWithoutCheck(DataCacheObject obj)
 {
     lock (Cache)
         Cache[GetKey(obj)] = obj.Data;
 }
 public bool Contains(DataCacheObject obj)
 {
     return(Get(obj) != null);
 }
 private BidWatchCurrent GetBidWatch(long user_id, long auction_id, bool iscache)
 {
     var dco = new DataCacheObject(DataCacheType.ACTIVITY, DataCacheRegions.WATCHLISTS, "GETBIDWATCH",
         new object[] {user_id, auction_id}, CachingExpirationTime.Days_01);
     var result = CacheRepository.Get(dco) as BidWatchCurrent;
     if (result != null && iscache) return result;
     result = dataContext.spSelect_BidWatchCurrent(auction_id, user_id).FirstOrDefault();
     if (result != null)
     {
         dco.Data = result;
         CacheRepository.Add(dco);
     }
     return result;
 }
 private AuctionResult GetAuctionResult(long auction_id)
 {
     var dco = new DataCacheObject(DataCacheType.RESOURCE, DataCacheRegions.AUCTIONS, "GETAUCTIONRESULT",
         new object[] {auction_id}, CachingExpirationTime.Minutes_01);
     var result = CacheRepository.Get(dco) as AuctionResult;
     if (result != null) return result;
     result = dataContext.spSelect_AuctionResults(auction_id).FirstOrDefault();
     if (result != null)
     {
         dco.Data = result;
         CacheRepository.Add(dco);
     }
     return result;
 }
        //RemoveAuctionCash
        public void RemoveAuctionCache(long auctionID)
        {
            var auction = dataContext.Auctions.SingleOrDefault(a => a.ID == auctionID);
            if (auction == null) return;
            var dco = new DataCacheObject(DataCacheType.RESOURCE, DataCacheRegions.AUCTIONS, "GETAUCTIONDETAIL",
                new object[] {auction.ID});
            CacheRepository.Remove(dco);

            dco.Method = "GETAUCTIONDETAILRESULTPAST";
            CacheRepository.Remove(dco);

            dco.Method = "GETAUCTIONDETAILRESULT";
            CacheRepository.Remove(dco);

            dco.Data = new object[] {auction.Event_ID};
            dco.Method = "GETAUCTIONUPDATES";
            CacheRepository.Remove(dco);

            dco.Region = DataCacheRegions.IMAGES;
            dco.Method = "GETAUCTIONIMAGES";
            CacheRepository.Remove(dco);

            CacheRepository.Remove(new DataCacheObject(DataCacheType.REFERENCE, DataCacheRegions.CATEGORIES,
                "GETCATEGORIESMENU", new object[] {0}));

            CacheRepository.Remove(new DataCacheObject(DataCacheType.REFERENCE, DataCacheRegions.CATEGORIES,
                "GETCATEGORIESMENU", new object[] {auction.Event_ID}));

            dco = new DataCacheObject(DataCacheType.RESOURCE, DataCacheRegions.AUCTIONS, "GETAUCTIONDETAIL",
                new object[] {auction.ID, auction.Event_ID});
            CacheRepository.Remove(dco);
        }
        //Get
        public object Get(DataCacheObject obj)
        {
            DataCache dc = GetDataCache(obj.Type.ToString());

            return(dc.Get(GetKey(obj)));
        }
 private string GetKey(DataCacheObject obj)
 {
     return(String.Format("{0}{1}", obj.Method, GetKeyByParams(obj.Params)));
 }
 public bool Contains(DataCacheObject obj)
 {
     return(Cache.Contains(GetKey(obj)));
 }
 private List<AuctionShort> GetProductsForTag(long eventID, long tagID, bool ispast, int sort, bool ordrby,
     int pageindex, int pagesize, out int? totalrecords)
 {
     var dco = new DataCacheObject(DataCacheType.RESOURCE, DataCacheRegions.AUCTIONLISTS, "GETPRODUCTSFORTAG",
         new object[] {eventID, tagID, ispast, sort, ordrby, pageindex, pagesize},
         CachingExpirationTime.Seconds_30);
     var result = CacheRepository.Get(dco) as TableViewResult;
     if (result != null && result.TotalRecords > 0)
     {
         totalrecords = result.TotalRecords;
         return result.Records;
     }
     result = new TableViewResult();
     totalrecords = 0;
     dataContext.CommandTimeout = 600000;
     result.Records =
         (from p in
             dataContext.spAuction_View_Tag(eventID, tagID, ispast ? 2 : 1, sort, ordrby, pageindex, pagesize,
                 ref totalrecords)
             select new AuctionShort
             {
                 Bids = p.Bids.GetValueOrDefault(0),
                 CurrentBid = p.CurrentBid.GetValueOrDefault(0),
                 Estimate = p.Estimate,
                 IsBold = p.IsBold.GetValueOrDefault(false),
                 IsFeatured = p.IsFeatured.GetValueOrDefault(false),
                 IsUnsoldOrPulledOut =
                     p.IsUnsold.GetValueOrDefault(false) || p.IsPulledOut.GetValueOrDefault(false),
                 LinkParams =
                     new LinkParams
                     {
                         ID = p.Auction_ID.GetValueOrDefault(0),
                         EventTitle = p.EventTitle,
                         MainCategoryTitle = p.MainCategoryTitle,
                         CategoryTitle = p.CategoryTitle
                     },
                 Lot = p.Lot.HasValue ? p.Lot.Value : (short) 0,
                 Price = p.Price.GetValueOrDefault(0),
                 PriceRealized = p.PriceRealized.GetValueOrDefault(0),
                 PulledOut = p.IsPulledOut.GetValueOrDefault(false),
                 Status = p.AuctionStatus.GetValueOrDefault(0),
                 ThumbnailPath = p.ThumbnailPath,
                 Title = p.Title,
                 UnsoldOrPulledOut = p.IsUnsold.GetValueOrDefault(false) ? "UNSOLD" : "WITHDRAWN"
             }).ToList();
     result.TotalRecords = totalrecords.GetValueOrDefault(0);
     if (result.TotalRecords > 0)
     {
         dco.Data = result;
         CacheRepository.Add(dco);
     }
     return result.Records;
 }
        //Put
        public void Put(DataCacheObject obj)
        {
            DataCache dc = GetDataCache(obj.Type.ToString());

            dc.Put(GetKey(obj), obj.Data, TimeSpan.FromSeconds(obj.CacheTime));
        }
 //GetUserByEmail
 public User GetUserByEmail(string email, bool iscache)
 {
   email = email.ToLower().Trim();
   DataCacheObject dco = new DataCacheObject(DataCacheType.ACTIVITY, DataCacheRegions.USERS, "GETUSERBYEMAIL",
                                             new object[] { email }, CachingExpirationTime.Minutes_30);
   User result = CacheRepository.Get(dco) as User;
   if (result != null && iscache) return result;
   //result = dataContext.Users.Where(U => U.Email == email).SingleOrDefault();
   result = dataContext.spSelect_User(null, null, null, null, null, email).SingleOrDefault();
   if (result != null)
   {
     dco.Data = result;
     CacheRepository.Add(dco);
   }
   return result;
 }
 //GetAuctionDetailResultPast
 public AuctionShort GetAuctionDetailResultPast(long auction_id)
 {
     var dco = new DataCacheObject(DataCacheType.RESOURCE, DataCacheRegions.AUCTIONS,
         "GETAUCTIONDETAILRESULTPAST",
         new object[] {auction_id}, CachingExpirationTime.Days_01);
     var result = CacheRepository.Get(dco) as AuctionShort;
     if (result != null) return result;
     result = GetAuctionDetailResult(auction_id, false);
     if (result != null)
     {
         dco.Data = result;
         CacheRepository.Add(dco);
     }
     return result;
 }
 public object Get(DataCacheObject obj)
 {
     return(Cache.Get(GetKey(obj)));
 }
        //GetAuctionResult

        //UpdateAuctionBiddingResult
        public void UpdateAuctionBiddingResult(long auction_id, long user_id, decimal currentbid, decimal maxbid)
        {
            try
            {
                var ar = GetAuctionResult(auction_id);
                if (ar == null)
                {
                    ar = new AuctionResult();
                    dataContext.AuctionResults.InsertOnSubmit(ar);
                    ar.Auction_ID = auction_id;
                    ar.User_ID = user_id;
                    ar.CurrentBid = 0;
                    ar.MaxBid = 0;
                    ar.Bids = 0;
                    SubmitChanges();
                    CacheRepository.Put(new DataCacheObject(DataCacheType.RESOURCE, DataCacheRegions.AUCTIONS,
                        "GETAUCTIONRESULT", new object[] {auction_id}, CachingExpirationTime.Minutes_01, ar));
                }
                ar.Auction_ID = auction_id;
                ar.User_ID = user_id;
                ar.CurrentBid = currentbid;
                ar.MaxBid = maxbid;
                ar.Bids = dataContext.spBid_LogCount(auction_id).FirstOrDefault().LogCount.GetValueOrDefault(0);
                dataContext.spUpdate_AuctionResults(ar.ID, ar.Auction_ID, ar.User_ID, ar.CurrentBid, ar.Bids, ar.MaxBid);
                var dco = new DataCacheObject(DataCacheType.RESOURCE, DataCacheRegions.AUCTIONS, "GETAUCTIONRESULT",
                    new object[] {auction_id}, CachingExpirationTime.Minutes_01, ar);
                CacheRepository.Put(dco);
                dco.Method = "GETAUCTIONDETAILRESULT";
                var result = CacheRepository.Get(dco) as AuctionShort;
                if (result != null)
                {
                    result.Bids = ar.Bids;
                    result.CurrentBid = ar.CurrentBid;
                    dco.Data = result;
                    CacheRepository.Put(dco);
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(
                    String.Format("[auction_id={0}; user={1}; cb={2}; maxbid={3}", auction_id, user_id, currentbid,
                        maxbid), ex);
            }
        }
 //GetKey
 private string GetKey(DataCacheObject obj)
 {
     return(String.Format("{0}_{1}_{2}{3}", obj.Type, obj.Region, obj.Method, GetKeyByParams(obj.Params)));
 }