public ProfileDetailsViewModel(MobiContext context, ProfileCache profile) : base(context) { this._profile = profile; this._additionalImages = ProfileThumbnail.CreateManager().Load(this.Profile, MobiChat.Data.ThumbnailIdentifier.NotDefault); this._descriptionValues = ProfileDetailValue.Generate(this.ProfileDetails); }
public List <ProfileThumbnailData> Load(ISqlConnectionInfo connection, ProfileThumbnail profileThumbnail) { SqlQueryParameters parameters = new SqlQueryParameters(); parameters.Where = "[ptd].ProfileThumbnailID = @ProfileThumbnailID"; parameters.Arguments.Add("ProfileThumbnailID", profileThumbnail.ID); return(this.LoadMany(connection, parameters)); }
public ProfileThumbnailData CreateInstance(ProfileThumbnail profileThumbnail) { if (!this.HasData) { return(null); } return(new ProfileThumbnailData(this.ProfileThumbnailDataID, profileThumbnail ?? new ProfileThumbnail(this.ProfileThumbnailID), this.Data, this.IsOriginal, this.Updated, this.Created)); }
public List <ProfileThumbnailData> Load(IConnectionInfo connection, ProfileThumbnail profileThumbnail) { ISqlConnectionInfo sqlConnection = connection as ISqlConnectionInfo; if (sqlConnection != null) { return(this.Load(sqlConnection, profileThumbnail)); } using (sqlConnection = new SqlConnectionInfo(connection, this.Type)) return(this.Load(sqlConnection, profileThumbnail)); }
public ActionResult Get(int profileThumbnailID) { ProfileThumbnail pt = ProfileThumbnail.CreateManager().Load(profileThumbnailID); if (pt == null) { Log.Error("Profile thumbnail does not exist."); return(this.InternalError()); } ProfileThumbnailData ptd = ProfileThumbnailData.LoadByProfileThumbnail(pt).FirstOrDefault(); if (ptd == null) { Log.Error("COULD NOT LOAD THUMBNAIL. ProfileThumbnailData is null for ProfileThumbnailID=" + profileThumbnailID); return(this.InternalError()); } return(File(ptd.Data, "image/jpg", string.Format("{0}{1}", profileThumbnailID, ".jpg"))); }
public ProfileCache(Profile profile) : base(profile) { lock (CacheLockObject) { // SUMMARY: Adding ProfileThumbnail ProfileThumbnail profileThumbnail = ProfileThumbnail.CreateManager().Load(profile, ThumbnailIdentifier.Default).FirstOrDefault(); if (profileThumbnail != null) { ProfileThumbnailData thumbnailData = ProfileThumbnailData.LoadByProfileThumbnail(profileThumbnail, null).FirstOrDefault(); this._defaultThumbnail = thumbnailData.Data; this._thumbnailUrl = string.Format("/thumbnails/default/{0}", profile.ID); } this._id = profile.ID; this._url = string.Format("/profile/{0}", profile.ID); this._details = new Dictionary <string, ProfileDetail>(); List <ProfileDetail> profileDetails = ProfileDetail.CreateManager().Load(profile); if (profileDetails == null || profileDetails.Count == 0) { this._hasError = true; Log.Error("web.Profile:" + this._id + " does not have any ProfileDetail"); return; } foreach (ProfileDetail pd in profileDetails) { if (this._details.ContainsKey(pd.Language.TwoLetterIsoCode)) { continue; } this._details.Add(pd.Language.TwoLetterIsoCode, pd); } } }
public List <ProfileThumbnailData> Load(ProfileThumbnail profileThumbnail) { using (SqlConnectionInfo connection = new SqlConnectionInfo(this.Type)) return(this.Load(connection, profileThumbnail)); }
public ProfileThumbnailData Load(ISqlConnectionInfo connection, SqlQueryParameters parameters) { IDatabase database = connection.Database; if (database == null) { throw new ArgumentNullException("database", "Error initializing database connection."); } if (parameters == null) { throw new ArgumentNullException("parameters"); } string sqlCmdText = string.Empty; try { sqlCmdText = "SELECT {0} " + ProfileThumbnailDataTable.GetColumnNames("[ptd]") + (this.Depth > 0 ? "," + ProfileThumbnailTable.GetColumnNames("[ptd_pt]") : string.Empty) + (this.Depth > 1 ? "," + ProfileTable.GetColumnNames("[ptd_pt_p]") : string.Empty) + " FROM [web].[ProfileThumbnailData] AS [ptd] "; if (this.Depth > 0) { sqlCmdText += "INNER JOIN [web].[ProfileThumbnail] AS [ptd_pt] ON [ptd].[ProfileThumbnailID] = [ptd_pt].[ProfileThumbnailID] "; } if (this.Depth > 1) { sqlCmdText += "INNER JOIN [web].[Profile] AS [ptd_pt_p] ON [ptd_pt].[ProfileID] = [ptd_pt_p].[ProfileID] "; } parameters.Top = 1; sqlCmdText = parameters.BuildQuery(sqlCmdText); SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand; foreach (KeyValuePair <string, object> argument in parameters.Arguments) { sqlCmd.Parameters.AddWithValue("@" + argument.Key, argument.Value); } SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader; if (!sqlReader.HasRows || !sqlReader.Read()) { IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("ptd", "customload", "notfound"), "ProfileThumbnailData could not be loaded using custom logic as it was not found.", sqlCmdText, this, connection, parameters); if (this.Logger.IsDebugEnabled) { this.Logger.Debug(builder.ToString()); } sqlReader.Close(); return(null); } SqlQuery query = new SqlQuery(sqlReader); ProfileThumbnailDataTable ptdTable = new ProfileThumbnailDataTable(query); ProfileThumbnailTable ptd_ptTable = (this.Depth > 0) ? new ProfileThumbnailTable(query) : null; ProfileTable ptd_pt_pTable = (this.Depth > 1) ? new ProfileTable(query) : null; Profile ptd_pt_pObject = (this.Depth > 1) ? ptd_pt_pTable.CreateInstance() : null; ProfileThumbnail ptd_ptObject = (this.Depth > 0) ? ptd_ptTable.CreateInstance(ptd_pt_pObject) : null; ProfileThumbnailData ptdObject = ptdTable.CreateInstance(ptd_ptObject); sqlReader.Close(); return(ptdObject); } catch (Exception ex) { database.HandleException(ex); IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("ptd", "customload", "exception"), "ProfileThumbnailData could not be loaded using custom logic. See exception for details.", sqlCmdText, ex, this, connection, parameters); if (this.Logger.IsErrorEnabled) { this.Logger.Error(builder.ToString(), ex); } throw new DataOperationException(DataOperation.Load, "ProfileThumbnailData", "Exception while loading (custom/single) ProfileThumbnailData object from database. See inner exception for details.", ex); } }
protected override ProfileThumbnailData LoadInternal(ISqlConnectionInfo connection, int id) { IDatabase database = connection.Database; if (database == null) { throw new ArgumentNullException("database", "Error initializing database connection."); } string sqlCmdText = string.Empty; try { sqlCmdText = "SELECT " + ProfileThumbnailDataTable.GetColumnNames("[ptd]") + (this.Depth > 0 ? "," + ProfileThumbnailTable.GetColumnNames("[ptd_pt]") : string.Empty) + (this.Depth > 1 ? "," + ProfileTable.GetColumnNames("[ptd_pt_p]") : string.Empty) + " FROM [web].[ProfileThumbnailData] AS [ptd] "; if (this.Depth > 0) { sqlCmdText += "INNER JOIN [web].[ProfileThumbnail] AS [ptd_pt] ON [ptd].[ProfileThumbnailID] = [ptd_pt].[ProfileThumbnailID] "; } if (this.Depth > 1) { sqlCmdText += "INNER JOIN [web].[Profile] AS [ptd_pt_p] ON [ptd_pt].[ProfileID] = [ptd_pt_p].[ProfileID] "; } sqlCmdText += "WHERE [ptd].[ProfileThumbnailDataID] = @ProfileThumbnailDataID;"; SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand; sqlCmd.Parameters.AddWithValue("@ProfileThumbnailDataID", id); SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader; if (!sqlReader.HasRows || !sqlReader.Read()) { IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("ptd", "loadinternal", "notfound"), "ProfileThumbnailData could not be loaded by id as it was not found.", sqlCmdText, this, connection, id); if (this.Logger.IsWarnEnabled) { this.Logger.Warn(builder.ToString()); } sqlReader.Close(); return(null); } SqlQuery query = new SqlQuery(sqlReader); ProfileThumbnailDataTable ptdTable = new ProfileThumbnailDataTable(query); ProfileThumbnailTable ptd_ptTable = (this.Depth > 0) ? new ProfileThumbnailTable(query) : null; ProfileTable ptd_pt_pTable = (this.Depth > 1) ? new ProfileTable(query) : null; Profile ptd_pt_pObject = (this.Depth > 1) ? ptd_pt_pTable.CreateInstance() : null; ProfileThumbnail ptd_ptObject = (this.Depth > 0) ? ptd_ptTable.CreateInstance(ptd_pt_pObject) : null; ProfileThumbnailData ptdObject = ptdTable.CreateInstance(ptd_ptObject); sqlReader.Close(); return(ptdObject); } catch (Exception ex) { database.HandleException(ex); IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("ptd", "loadinternal", "exception"), "ProfileThumbnailData could not be loaded by id. See exception for details.", sqlCmdText, ex, this, connection, id); if (this.Logger.IsErrorEnabled) { this.Logger.Error(builder.ToString(), ex); } throw new DataOperationException(DataOperation.Load, "ProfileThumbnailData", "Exception while loading ProfileThumbnailData object from database. See inner exception for details.", ex); } }