public ActionResult RevertToDefaultTable(long id)
        {
            if (!DomainManager.AllowEdit())
            {
                throw new Exception("Data modified is not allowed");
            }
            try
            {
                if (DomainManager.CurrentDomainID != Constant.SystemDomainID)
                {
                    LiveCasinoTableAccessor lta   = LiveCasinoTableAccessor.CreateInstance <LiveCasinoTableAccessor>();
                    ceLiveCasinoTable       table = lta.GetTable(DomainManager.CurrentDomainID, id);
                    bool isExist = table != null;
                    SqlQuery <ceLiveCasinoTable> query2 = new SqlQuery <ceLiveCasinoTable>();
                    if (isExist)
                    {
                        query2.Delete(table);
                        return(this.Json(new { success = true }, JsonRequestBehavior.AllowGet));
                    }

                    return(this.Json(new { success = false, error = "Table not found!" }, JsonRequestBehavior.AllowGet));
                }

                return(this.Json(new { success = false }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Logger.Exception(ex);
                return(this.Json(new { success = false, error = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        private bool InternalUpdateProperty(long id, AvailableEditTableProperty property, object value, bool updatingBase, PropertyEditType editType, bool setToDefault)
        {
            if (updatingBase && setToDefault)
            {
                return(false);
            }
            bool succeed = false;

            using (DbManager db = new DbManager())
            {
                db.BeginTransaction();
                try
                {
                    LiveCasinoTableAccessor          lcta      = LiveCasinoTableAccessor.CreateInstance <LiveCasinoTableAccessor>(db);
                    SqlQuery <ceLiveCasinoTableBase> query     = new SqlQuery <ceLiveCasinoTableBase>(db);
                    ceLiveCasinoTableBase            tableBase = null;
                    ceLiveCasinoTable tableDomain = null;

                    if (id > 0)
                    {
                        tableBase = query.SelectByKey(id);
                        if (tableBase != null)
                        {
                            string column                = string.Empty;
                            object defaultValue          = null;
                            bool   useBaseValueAsDefault = false;

                            if (!updatingBase)
                            {
                                tableDomain = lcta.GetTable(DomainManager.CurrentDomainID, id);
                            }

                            bool isExist = tableDomain != null;

                            #region Resolve and assignment property
                            bool tempBool;

                            column = property.ToString();

                            bool valueVerified = setToDefault;
                            bool changed       = true;
                            bool valueResolved = false;
                            switch (property)
                            {
                                #region bool properies
                            case AvailableEditTableProperty.OpVisible:
                            case AvailableEditTableProperty.Enabled:
                            case AvailableEditTableProperty.NewTable:
                            case AvailableEditTableProperty.TurkishTable:
                            case AvailableEditTableProperty.VIPTable:
                                useBaseValueAsDefault = true;
                                if (!setToDefault)
                                {
                                    if (bool.TryParse(value as string, out tempBool))
                                    {
                                        valueVerified = true;
                                        value         = tempBool;
                                    }
                                }
                                break;
                                #endregion bool properies

                            default:
                                column  = null;
                                changed = false;
                                break;
                            }

                            if (!valueResolved && !string.IsNullOrWhiteSpace(column))
                            {
                                value = ResolveValue(updatingBase, setToDefault, tableBase, tableDomain, column, value, defaultValue, useBaseValueAsDefault, out changed);
                            }
                            #endregion Resolve and assignment property

                            if (changed)
                            {
                                succeed = true;
                                if (updatingBase)
                                {
                                    LiveCasinoTableAccessor.UpdateTableBaseProperty(column, value, tableBase.ID);
                                }
                                else
                                {
                                    SqlQuery <ceCasinoGame> query2 = new SqlQuery <ceCasinoGame>(db);
                                    if (isExist)
                                    {
                                        LiveCasinoTableAccessor.UpdateTableProperty(column, value, tableDomain.ID);
                                    }
                                    else
                                    {
                                        LiveCasinoTableAccessor.InsertNewTableWithSpecificProperty(DomainManager.CurrentDomainID
                                                                                                   , tableBase.ID
                                                                                                   , CurrentUserSession.SessionID
                                                                                                   , CurrentUserSession.UserID
                                                                                                   , column
                                                                                                   , value
                                                                                                   , tableBase.Enabled
                                                                                                   , tableBase.OpVisible
                                                                                                   );
                                    }
                                }
                            }
                        }
                    }

                    db.CommitTransaction();

                    return(succeed);
                }
                catch (Exception ex)
                {
                    Logger.Exception(ex);
                    db.RollbackTransaction();
                }
            }
            return(false);
        }
        public ActionResult SaveTable(ceLiveCasinoTableBaseEx updatedTable
                                      , HttpPostedFileBase thumbnailFile
                                      )
        {
            if (!DomainManager.AllowEdit())
            {
                throw new Exception("Data modified is not allowed");
            }

            try
            {
                string imageFileName;
                byte[] imageBuffer;
                if (ImageAsset.ParseImage(thumbnailFile, out imageFileName, out imageBuffer))
                {
                    imageFileName = ImageAsset.GetImageFtpFilePath(imageFileName);
                    FTP.UploadFile(DomainManager.CurrentDomainID, imageFileName, imageBuffer);
                }

                SqlQuery <ceLiveCasinoTableBase> query     = new SqlQuery <ceLiveCasinoTableBase>();
                ceLiveCasinoTableBase            baseTable = query.SelectByKey(updatedTable.ID);

                ceCasinoGameBaseEx game = CasinoGameAccessor.GetDomainGame(Constant.SystemDomainID, baseTable.CasinoGameBaseID);

                if (CurrentUserSession.IsSystemUser && DomainManager.CurrentDomainID == Constant.SystemDomainID)
                {
                    baseTable.TableName               = updatedTable.TableName;
                    baseTable.Category                = updatedTable.Category;
                    baseTable.ExtraParameter1         = updatedTable.ExtraParameter1;
                    baseTable.ExtraParameter2         = updatedTable.ExtraParameter2;
                    baseTable.ExtraParameter3         = updatedTable.ExtraParameter3;
                    baseTable.ExtraParameter4         = updatedTable.ExtraParameter4;
                    baseTable.LaunchParams            = updatedTable.LaunchParams;
                    baseTable.OpenHoursStart          = updatedTable.OpenHoursStart;
                    baseTable.OpenHoursEnd            = updatedTable.OpenHoursEnd;
                    baseTable.OpenHoursTimeZone       = updatedTable.OpenHoursTimeZone;
                    baseTable.Limit                   = ParseLimit();
                    baseTable.VIPTable                = updatedTable.VIPTable;
                    baseTable.NewTable                = updatedTable.NewTable;
                    baseTable.NewTableExpirationDate  = updatedTable.NewTable ? updatedTable.NewTableExpirationDate : DateTime.Now.AddDays(-1);
                    baseTable.ExcludeFromRandomLaunch = updatedTable.ExcludeFromRandomLaunch;
                    baseTable.TurkishTable            = updatedTable.TurkishTable;
                    baseTable.BetBehindAvailable      = updatedTable.BetBehindAvailable;
                    baseTable.SeatsUnlimited          = updatedTable.SeatsUnlimited;
                    baseTable.DealerGender            = updatedTable.DealerGender;
                    baseTable.DealerOrigin            = updatedTable.DealerOrigin;
                    baseTable.TableStudioUrl          = updatedTable.TableStudioUrl;

                    //if (game.VendorID == VendorID.EvolutionGaming)
                    {
                        baseTable.ClientCompatibility = updatedTable.ClientCompatibility;
                    }

                    if (!string.IsNullOrWhiteSpace(imageFileName))
                    {
                        baseTable.Thumbnail = imageFileName;
                    }

                    query.Update(baseTable);

                    //updating properties that are inherited from basetable and disabled for edit in child tables
                    var propertiesValues = new Dictionary <string, object>
                    {
                        { "BetBehindAvailable", updatedTable.BetBehindAvailable },
                        { "SeatsUnlimited", updatedTable.SeatsUnlimited },
                        { "DealerGender", updatedTable.DealerGender },
                        { "DealerOrigin", updatedTable.DealerOrigin }
                    };
                    LiveCasinoTableAccessor.UpdateChildTablesProperties(propertiesValues, baseTable.ID);
                }
                else if (DomainManager.CurrentDomainID != Constant.SystemDomainID)
                {
                    LiveCasinoTableAccessor lta   = LiveCasinoTableAccessor.CreateInstance <LiveCasinoTableAccessor>();
                    ceLiveCasinoTable       table = lta.GetTable(DomainManager.CurrentDomainID, updatedTable.ID);
                    bool isExist    = table != null;
                    bool isModified = false;
                    if (!isExist)
                    {
                        table = new ceLiveCasinoTable()
                        {
                            DomainID = DomainManager.CurrentDomainID, LiveCasinoTableBaseID = updatedTable.ID
                        };
                        table.Ins                    = DateTime.Now;
                        table.SessionUserID          = CurrentUserSession.UserID;
                        table.SessionID              = CurrentUserSession.UserSessionID;
                        table.OpVisible              = baseTable.OpVisible;
                        table.ClientCompatibility    = null;
                        table.NewTableExpirationDate = baseTable.NewTableExpirationDate == DateTime.MinValue ? DateTime.Now.Date.AddDays(-1) : baseTable.NewTableExpirationDate;

                        table.BetBehindAvailable = baseTable.BetBehindAvailable;
                        table.SeatsUnlimited     = baseTable.SeatsUnlimited;
                        table.DealerGender       = baseTable.DealerGender;
                        table.DealerOrigin       = baseTable.DealerOrigin;
                    }
                    table.ShortName       = null;
                    table.Logo            = null;
                    table.BackgroundImage = null;

                    if (!string.IsNullOrWhiteSpace(updatedTable.ExtraParameter1) &&
                        !string.Equals(baseTable.ExtraParameter1, updatedTable.ExtraParameter1))
                    {
                        isModified            = true;
                        table.ExtraParameter1 = updatedTable.ExtraParameter1;
                    }
                    else
                    {
                        table.ExtraParameter1 = null;
                    }

                    if (!string.IsNullOrWhiteSpace(updatedTable.ExtraParameter2) &&
                        !string.Equals(baseTable.ExtraParameter2, updatedTable.ExtraParameter2))
                    {
                        isModified            = true;
                        table.ExtraParameter2 = updatedTable.ExtraParameter2;
                    }
                    else
                    {
                        table.ExtraParameter2 = null;
                    }

                    if (!string.IsNullOrWhiteSpace(updatedTable.ExtraParameter3) &&
                        !string.Equals(baseTable.ExtraParameter3, updatedTable.ExtraParameter3))
                    {
                        isModified            = true;
                        table.ExtraParameter3 = updatedTable.ExtraParameter3;
                    }
                    else
                    {
                        table.ExtraParameter3 = null;
                    }

                    if (!string.IsNullOrWhiteSpace(updatedTable.ExtraParameter4) &&
                        !string.Equals(baseTable.ExtraParameter4, updatedTable.ExtraParameter4))
                    {
                        isModified            = true;
                        table.ExtraParameter4 = updatedTable.ExtraParameter4;
                    }
                    else
                    {
                        table.ExtraParameter4 = null;
                    }

                    if (!string.IsNullOrEmpty(updatedTable.LaunchParams) &&
                        !string.Equals(baseTable.LaunchParams, updatedTable.LaunchParams))
                    {
                        isModified         = true;
                        table.LaunchParams = updatedTable.LaunchParams;
                    }
                    else
                    {
                        table.LaunchParams = null;
                    }

                    if (!string.IsNullOrWhiteSpace(updatedTable.TableName) &&
                        !string.Equals(baseTable.TableName, updatedTable.TableName))
                    {
                        isModified      = true;
                        table.TableName = updatedTable.TableName;
                    }
                    else
                    {
                        table.TableName = null;
                    }

                    if (!string.IsNullOrWhiteSpace(updatedTable.Category) &&
                        !string.Equals(baseTable.Category, updatedTable.Category))
                    {
                        isModified     = true;
                        table.Category = updatedTable.Category;
                    }
                    else
                    {
                        table.Category = null;
                    }

                    if (!string.IsNullOrWhiteSpace(imageFileName) &&
                        !string.Equals(baseTable.Thumbnail, updatedTable.Thumbnail))
                    {
                        isModified      = true;
                        table.Thumbnail = imageFileName;
                    }
                    else
                    {
                        table.Thumbnail = null;
                    }

                    //if (game.VendorID == VendorID.EvolutionGaming)
                    {
                        if (updatedTable.ClientCompatibility != null && !string.Equals(table.ClientCompatibility, updatedTable.ClientCompatibility))
                        {
                            isModified = true;
                            if (!string.Equals(baseTable.ClientCompatibility, updatedTable.ClientCompatibility))
                            {
                                table.ClientCompatibility = updatedTable.ClientCompatibility;
                            }
                            else
                            {
                                table.ClientCompatibility = null;
                            }
                        }
                    }

                    string limitationXml       = table.LimitationXml;
                    LiveCasinoTableLimit limit = table.Limit;
                    table.Limit = ParseLimit();
                    if (table.Limit.Equals(baseTable.Limit))
                    {
                        table.LimitationXml = null;
                    }
                    if (!(string.IsNullOrWhiteSpace(table.LimitationXml) && string.IsNullOrWhiteSpace(limitationXml)))
                    {
                        if (table.LimitationXml == null)
                        {
                            isModified = true;
                        }
                        else if (!table.LimitationXml.Equals(limitationXml, StringComparison.InvariantCultureIgnoreCase))
                        {
                            isModified = true;
                        }
                    }
                    if (table.VIPTable != updatedTable.VIPTable)
                    {
                        table.VIPTable = updatedTable.VIPTable;
                        isModified     = true;
                    }
                    if (table.NewTable != updatedTable.NewTable || table.NewTableExpirationDate.CompareTo(updatedTable.NewTableExpirationDate) != 0)
                    {
                        table.NewTable = updatedTable.NewTable;
                        table.NewTableExpirationDate = updatedTable.NewTable ? updatedTable.NewTableExpirationDate : DateTime.Now.AddDays(-1);
                        isModified = true;
                    }
                    if (table.TurkishTable != updatedTable.TurkishTable)
                    {
                        table.TurkishTable = updatedTable.TurkishTable;
                        isModified         = true;
                    }
                    if (table.ExcludeFromRandomLaunch != updatedTable.ExcludeFromRandomLaunch)
                    {
                        table.ExcludeFromRandomLaunch = updatedTable.ExcludeFromRandomLaunch;
                        isModified = true;
                    }

                    if (table.TableStudioUrl != updatedTable.TableStudioUrl)
                    {
                        table.TableStudioUrl = updatedTable.TableStudioUrl;
                        isModified           = true;
                    }

                    if (isModified)
                    {
                        SqlQuery <ceLiveCasinoTable> query2 = new SqlQuery <ceLiveCasinoTable>();
                        if (isExist)
                        {
                            query2.Update(table);
                        }
                        else
                        {
                            query2.Insert(table);
                        }
                    }
                }

                return(this.Json(new { success = true }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Logger.Exception(ex);
                return(this.Json(new { success = false, error = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult EnableTables(long[] tableIDs, bool enable)
        {
            if (!DomainManager.AllowEdit())
            {
                throw new Exception("Data modified is not allowed");
            }
            try
            {
                if (!CurrentUserSession.IsSystemUser)
                {
                    throw new CeException("You are not allowed to perform this operation.");
                }

                SqlQuery <ceLiveCasinoTableBase> query1 = new SqlQuery <ceLiveCasinoTableBase>();
                SqlQuery <ceLiveCasinoTable>     query2 = new SqlQuery <ceLiveCasinoTable>();
                LiveCasinoTableAccessor          lta    = LiveCasinoTableAccessor.CreateInstance <LiveCasinoTableAccessor>();
                foreach (long tableID in tableIDs)
                {
                    if (CurrentUserSession.IsSystemUser && DomainManager.CurrentDomainID == Constant.SystemDomainID)
                    {
                        ceLiveCasinoTableBase baseTable = query1.SelectByKey(tableID);
                        baseTable.Enabled = enable;
                        query1.Update(baseTable);
                    }
                    else
                    {
                        ceLiveCasinoTable table = lta.GetTable(DomainManager.CurrentDomainID, tableID);
                        if (table == null)
                        {
                            table = new ceLiveCasinoTable()
                            {
                                DomainID = DomainManager.CurrentDomainID, LiveCasinoTableBaseID = tableID
                            };
                            table.Ins           = DateTime.Now;
                            table.SessionUserID = CurrentUserSession.UserID;
                            table.SessionID     = CurrentUserSession.UserSessionID;
                            table.Enabled       = enable;

                            table.ClientCompatibility = null;
                            table.TableName           = null;
                            table.ShortName           = null;
                            table.Category            = null;
                            table.Thumbnail           = null;
                            table.Logo            = null;
                            table.BackgroundImage = null;
                            table.ExtraParameter1 = null;
                            table.ExtraParameter2 = null;
                            table.ExtraParameter3 = null;
                            table.ExtraParameter4 = null;
                            table.LaunchParams    = null;
                            table.LimitationXml   = null;
                            query2.Insert(table);
                        }
                        else
                        {
                            if (string.IsNullOrWhiteSpace(table.ClientCompatibility))
                            {
                                table.ClientCompatibility = null;
                            }
                            if (string.IsNullOrWhiteSpace(table.TableName))
                            {
                                table.TableName = null;
                            }
                            if (string.IsNullOrWhiteSpace(table.ShortName))
                            {
                                table.ShortName = null;
                            }
                            if (string.IsNullOrWhiteSpace(table.Category))
                            {
                                table.Category = null;
                            }
                            if (string.IsNullOrWhiteSpace(table.Thumbnail))
                            {
                                table.Thumbnail = null;
                            }
                            if (string.IsNullOrWhiteSpace(table.Logo))
                            {
                                table.Logo = null;
                            }
                            if (string.IsNullOrWhiteSpace(table.BackgroundImage))
                            {
                                table.BackgroundImage = null;
                            }
                            if (string.IsNullOrWhiteSpace(table.ExtraParameter1))
                            {
                                table.ExtraParameter1 = null;
                            }
                            if (string.IsNullOrWhiteSpace(table.ExtraParameter2))
                            {
                                table.ExtraParameter2 = null;
                            }
                            if (string.IsNullOrWhiteSpace(table.ExtraParameter3))
                            {
                                table.ExtraParameter3 = null;
                            }
                            if (string.IsNullOrWhiteSpace(table.ExtraParameter4))
                            {
                                table.ExtraParameter4 = null;
                            }
                            if (string.IsNullOrWhiteSpace(table.LaunchParams))
                            {
                                table.LaunchParams = null;
                            }
                            if (string.IsNullOrWhiteSpace(table.LimitationXml))
                            {
                                table.LimitationXml = null;
                            }

                            table.Enabled = enable;
                            query2.Update(table);
                        }
                    }
                }
                return(this.Json(new { success = true }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Logger.Exception(ex);
                return(this.Json(new { success = false, error = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }