public ProfileCategoryModel(ProfileCategory category) { Id = category.EntityId; Name = category.Name; Order = category.Order; IsSuspended = category.IsSuspended; }
public ProfileGroup CreateInstance(ProfileCategory profileCategory, Instance instance) { if (!this.HasData) { return(null); } return(new ProfileGroup(this.ProfileGroupID, profileCategory ?? new ProfileCategory(this.ProfileCategoryID), instance ?? new Instance(this.InstanceID), this.Name, this.Description, this.Updated, this.Created)); }
public ActionResult Create(Profile model, string [] selectcategories, HttpPostedFileBase ProfileImage, int?location) { if (ModelState.IsValid) { if (User.Identity.IsAuthenticated) { model.Email = Request.QueryString["username"]; } if (location != null) { model.City = _db.Cities.Find(location); } model.RegDate = DateTime.Now; model.ProfileCategories = new List <ProfileCategory>(); model.LastActivity = DateTime.Now; model.NextDiscardDate = DateTime.Now.AddMonths(6); _db.Profiles.Add(model); _db.SaveChanges(); foreach (var x in selectcategories) { var pc = new ProfileCategory(); pc.Profile = model; pc.Category = _db.Categories.Find(Convert.ToInt32(x)); _db.ProfileCategories.Add(pc); } if (ProfileImage != null) { var id = _db.Entry(model); string pic = "profile" + model.Id + System.IO.Path.GetExtension(ProfileImage.FileName); /*System.IO.Path.GetFileName(ProfileImage.FileName);*/ string path = System.IO.Path.Combine( Server.MapPath("~/Uploads/profile/"), pic); if (!System.IO.Directory.Exists(Server.MapPath("~/Uploads/profile/"))) { System.IO.Directory.CreateDirectory(Server.MapPath("~/Uploads/profile/")); } model.ProfilePicture = pic; // file is uploaded ProfileImage.SaveAs(path); } _db.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(View(model)); }
private Profile GetProfileFromReader(MySqlDataReader reader) { Profile result = null; reader.Read(); int id = int.Parse(reader["id"].ToString()); int idProfile = int.Parse(reader["idProfile"].ToString()); string Password = reader["Password"].ToString(); string Name = reader["Name"].ToString(); string Surname = reader["Surname"].ToString(); string Telephone = reader["Telephone"].ToString(); string Address = reader["Address"].ToString(); int profileCategoryId = int.Parse(reader["ProfileCategory"].ToString()); int profileStatusId = int.Parse(reader["ProfileStatus"].ToString()); ProfileStatus profileStatus = DAO.GetProfileStatusTable().GetElement(profileStatusId); ProfileCategory profileCategory = DAO.GetProfileCategoryTable().GetElement(profileCategoryId); result = new Profile(id, idProfile, Password, Name, Surname, Telephone, Address, profileStatus, profileCategory); return(result); }
public ProfileGroup 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} " + ProfileGroupTable.GetColumnNames("[pg]") + (this.Depth > 0 ? "," + ProfileCategoryTable.GetColumnNames("[pg_pc]") : string.Empty) + (this.Depth > 0 ? "," + InstanceTable.GetColumnNames("[pg_i]") : string.Empty) + " FROM [web].[ProfileGroup] AS [pg] "; if (this.Depth > 0) { sqlCmdText += "INNER JOIN [web].[ProfileCategory] AS [pg_pc] ON [pg].[ProfileCategoryID] = [pg_pc].[ProfileCategoryID] "; } if (this.Depth > 0) { sqlCmdText += "INNER JOIN [core].[Instance] AS [pg_i] ON [pg].[InstanceID] = [pg_i].[InstanceID] "; } 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("pg", "customload", "notfound"), "ProfileGroup 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); ProfileGroupTable pgTable = new ProfileGroupTable(query); ProfileCategoryTable pg_pcTable = (this.Depth > 0) ? new ProfileCategoryTable(query) : null; InstanceTable pg_iTable = (this.Depth > 0) ? new InstanceTable(query) : null; ProfileCategory pg_pcObject = (this.Depth > 0) ? pg_pcTable.CreateInstance() : null; Instance pg_iObject = (this.Depth > 0) ? pg_iTable.CreateInstance() : null; ProfileGroup pgObject = pgTable.CreateInstance(pg_pcObject, pg_iObject); sqlReader.Close(); return(pgObject); } catch (Exception ex) { database.HandleException(ex); IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("pg", "customload", "exception"), "ProfileGroup 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, "ProfileGroup", "Exception while loading (custom/single) ProfileGroup object from database. See inner exception for details.", ex); } }
protected override ProfileGroup 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 " + ProfileGroupTable.GetColumnNames("[pg]") + (this.Depth > 0 ? "," + ProfileCategoryTable.GetColumnNames("[pg_pc]") : string.Empty) + (this.Depth > 0 ? "," + InstanceTable.GetColumnNames("[pg_i]") : string.Empty) + " FROM [web].[ProfileGroup] AS [pg] "; if (this.Depth > 0) { sqlCmdText += "INNER JOIN [web].[ProfileCategory] AS [pg_pc] ON [pg].[ProfileCategoryID] = [pg_pc].[ProfileCategoryID] "; } if (this.Depth > 0) { sqlCmdText += "INNER JOIN [core].[Instance] AS [pg_i] ON [pg].[InstanceID] = [pg_i].[InstanceID] "; } sqlCmdText += "WHERE [pg].[ProfileGroupID] = @ProfileGroupID;"; SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand; sqlCmd.Parameters.AddWithValue("@ProfileGroupID", id); SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader; if (!sqlReader.HasRows || !sqlReader.Read()) { IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("pg", "loadinternal", "notfound"), "ProfileGroup 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); ProfileGroupTable pgTable = new ProfileGroupTable(query); ProfileCategoryTable pg_pcTable = (this.Depth > 0) ? new ProfileCategoryTable(query) : null; InstanceTable pg_iTable = (this.Depth > 0) ? new InstanceTable(query) : null; ProfileCategory pg_pcObject = (this.Depth > 0) ? pg_pcTable.CreateInstance() : null; Instance pg_iObject = (this.Depth > 0) ? pg_iTable.CreateInstance() : null; ProfileGroup pgObject = pgTable.CreateInstance(pg_pcObject, pg_iObject); sqlReader.Close(); return(pgObject); } catch (Exception ex) { database.HandleException(ex); IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("pg", "loadinternal", "exception"), "ProfileGroup 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, "ProfileGroup", "Exception while loading ProfileGroup object from database. See inner exception for details.", ex); } }
public List <ServiceProfileGroupMap> LoadMany(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} " + ServiceProfileGroupMapTable.GetColumnNames("[spgm]") + (this.Depth > 0 ? "," + ProfileGroupTable.GetColumnNames("[spgm_pg]") : string.Empty) + (this.Depth > 1 ? "," + ProfileCategoryTable.GetColumnNames("[spgm_pg_pc]") : string.Empty) + " FROM [web].[ServiceProfileGroupMap] AS [spgm] "; if (this.Depth > 0) { sqlCmdText += "INNER JOIN [web].[ProfileGroup] AS [spgm_pg] ON [spgm].[ProfileGroupID] = [spgm_pg].[ProfileGroupID] "; } if (this.Depth > 1) { sqlCmdText += "INNER JOIN [web].[ProfileCategory] AS [spgm_pg_pc] ON [spgm_pg].[ProfileCategoryID] = [spgm_pg_pc].[ProfileCategoryID] "; } 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("spgm", "customloadmany", "notfound"), "ServiceProfileGroupMap list could not be loaded using custom logic as no items were found.", sqlCmdText, this, connection, parameters); if (this.Logger.IsDebugEnabled) { this.Logger.Debug(builder.ToString()); } sqlReader.Close(); return(new List <ServiceProfileGroupMap>()); } SqlQuery query = new SqlQuery(sqlReader); ServiceProfileGroupMapTable spgmTable = new ServiceProfileGroupMapTable(query); ProfileGroupTable spgm_pgTable = (this.Depth > 0) ? new ProfileGroupTable(query) : null; ProfileCategoryTable spgm_pg_pcTable = (this.Depth > 1) ? new ProfileCategoryTable(query) : null; List <ServiceProfileGroupMap> result = new List <ServiceProfileGroupMap>(); do { ProfileCategory spgm_pg_pcObject = (this.Depth > 1) ? spgm_pg_pcTable.CreateInstance() : null; ProfileGroup spgm_pgObject = (this.Depth > 0) ? spgm_pgTable.CreateInstance(spgm_pg_pcObject) : null; ServiceProfileGroupMap spgmObject = (this.Depth > -1) ? spgmTable.CreateInstance(spgm_pgObject) : null; result.Add(spgmObject); } while (sqlReader.Read()); sqlReader.Close(); return(result); } catch (Exception ex) { database.HandleException(ex); IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("spgm", "customloadmany", "exception"), "ServiceProfileGroupMap list 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, "ServiceProfileGroupMap", "Exception while loading (custom/many) ServiceProfileGroupMap object from database. See inner exception for details.", ex); } }