private static MarketGroup GetMarketGroup(IDataContext context, MarketGroup forMarketGroup, OXODoc forDocument)
 {
     MarketGroup marketGroup = null;
     var cacheKey = string.Format("MarketGroup_{0}", forMarketGroup.Id);
     var cachedLookup = HttpContext.Current.Cache.Get(cacheKey);
     if (cachedLookup != null)
     {
         marketGroup = (MarketGroup)cachedLookup;
     }
     else
     {
         marketGroup = context.Market.GetMarketGroup(new VolumeFilter() { MarketGroupId = forMarketGroup.Id, OxoDocId = forDocument.Id, ProgrammeId = forDocument.ProgrammeId });
         if (!(marketGroup is EmptyMarketGroup) && marketGroup.Id != 0)
             HttpContext.Current.Cache.Add(cacheKey, marketGroup, null, DateTime.Now.AddMinutes(60), Cache.NoSlidingExpiration, CacheItemPriority.Default, null);
     }
     return marketGroup;
 }
        public bool MarketGroupSave(MarketGroup obj)
        {
            bool retVal = true;
            string procName = "";
            if (obj.Type == "Master")
            {
                procName = (obj.Id == 0 ? "dbo.OXO_Master_MarketGroup_New" : "dbo.OXO_Master_MarketGroup_Edit");
            }
            else
            {
                procName = (obj.Id == 0 ? "dbo.OXO_Programme_MarketGroup_New" : "dbo.OXO_Programme_MarketGroup_Edit");
            }

			using (IDbConnection conn = DbHelper.GetDBConnection())
            {
				try
				{
                    obj.Save(CurrentCDSID);

					var para = new DynamicParameters();
                    para.Add("@p_Group_Name", obj.GroupName, DbType.String, size: 500);
                    if (obj.Type != "Master")
                    {
                        para.Add("@p_prog_id", obj.ProgrammeId, DbType.Int32);
                    }
                    para.Add("@p_Active", obj.Active, DbType.Boolean);
                    para.Add("@p_Display_Order", obj.DisplayOrder, DbType.Int32);
                    para.Add("@p_Created_By", obj.CreatedBy, DbType.String, size: 8);
                    para.Add("@p_Created_On", obj.CreatedOn, DbType.DateTime);
                    para.Add("@p_Updated_By", obj.UpdatedBy, DbType.String, size: 8);
                    para.Add("@p_Last_Updated", obj.LastUpdated, DbType.DateTime);
                    para.Add("@p_Id", obj.Id, DbType.Int32, ParameterDirection.InputOutput);    					
					conn.Execute(procName, para, commandType: CommandType.StoredProcedure);

					if (obj.Id == 0)
					{
						obj.Id = para.Get<int>("@p_Id");
					}

				}
				catch (Exception ex)
				{
                    Log.Error(ex);
                    throw;
				}
			}

            return retVal;
            
        }