public bool CheckedPermission(AvailableEditTableProperty property) { if (!CurrentUserSession.IsAuthenticated) { return(false); } switch (property) { case AvailableEditTableProperty.Enabled: case AvailableEditTableProperty.NewTable: case AvailableEditTableProperty.TurkishTable: case AvailableEditTableProperty.VIPTable: { return(true); } case AvailableEditTableProperty.OpVisible: { return(CurrentUserSession.IsSystemUser); } } return(false); }
public JsonResult UpdateProperty(string ids, AvailableEditTableProperty property, object value, PropertyEditType?editType, bool setToDefault = false) { setToDefault = false; if (value != null) { try { value = ((string[])value)[0]; } catch { } } if (string.IsNullOrEmpty(ids) || (value == null && !setToDefault)) { return(this.Json(new { @success = false, @message = "Error, invalid argument!" })); } string[] strIds = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (ids.Length == 0) { return(this.Json(new { @success = false, @message = "Error, invalid argument!" })); } if (!CheckedPermission(property)) { return(this.Json(new { @success = false, @message = string.Format("Error, you are not allowed to change [{0}]!", property.ToString()) })); } bool updated = false; StringBuilder successedIds = new StringBuilder(); bool isCommon = DomainManager.CurrentDomainID == Constant.SystemDomainID; long id = 0; foreach (string strId in strIds) { if (long.TryParse(strId, out id)) { if (InternalUpdateProperty(id, property, value, isCommon, editType.HasValue ? editType.Value : PropertyEditType.Add, setToDefault)) { updated = true; successedIds.AppendFormat(" {0},", id); } } } if (updated) { CacheManager.ClearCache(Constant.GameListCachePrefix); CacheManager.ClearCache(Constant.DomainGamesCachePrefix); CacheManager.ClearCache(Constant.DomainGamesCache2Prefix); CacheManager.ClearCache(Constant.TopWinnersCachePrefix); return(this.Json(new { @success = true, @successedIds = string.Format("[{0}]", successedIds.ToString().TrimEnd(new char[] { ',' })) })); } return(this.Json(new { @success = false, @error = "operation failed!" })); }
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); }