/// <summary> /// Takes all properties on <see cref="Rel"/> and fills them on in the RelViewModel /// </summary> public RelViewModel(Relationship rel) { if (id == null) throw new ArgumentNullException("rel"); id = rel.id; userName = rel.username; orgID = rel.orgID; pageID = rel.pageId; relTypeID = rel.relTypeId; reltext = rel.relText; reldatetime = rel.relDateTime; reltypetext = GetRelType(relTypeID); orgtext = GetOrg(rel.orgID); usertext = GetUser(rel.username); }
/// <summary> /// Adds the page to the database. /// </summary> /// <param name="model">The summary details for the page.</param> /// <returns>A <see cref="PageViewModel"/> for the newly added page.</returns> /// <exception cref="DatabaseException">An databaseerror occurred while saving.</exception> /// <exception cref="SearchException">An error occurred adding the page to the search index.</exception> public RelViewModel AddRel(RelViewModel model) { try { string currentUser = _context.CurrentUsername; Relationship rel = new Relationship(); rel.id = model.id; rel.username = currentUser; rel.orgID = Repository.GetOrgByUser(currentUser).Id; rel.pageId = model.pageID; rel.relTypeId = model.relTypeID; rel.relText = model.reltext; Relationship newrel = Repository.AddNewRel(rel, rel.relTypeId, currentUser, rel.orgID, rel.pageId, rel.relText); return model; } catch (DatabaseException e) { throw new DatabaseException(e, "An error occurred while adding relationship '{0}' to the database", model.id); } }