Skip to content

Commit

Permalink
Redesign of how documentations are linked to classes and members: now…
Browse files Browse the repository at this point in the history
… through the full name
  • Loading branch information
donker committed Dec 20, 2017
1 parent 1fe8fef commit 2eb7def
Show file tree
Hide file tree
Showing 23 changed files with 131 additions and 88 deletions.
40 changes: 23 additions & 17 deletions Api/DocumentationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public HttpResponseMessage Save(Documentation data)
{
var doc = data.DocumentationId == -1 ? new Documentation()
{
ClassId = data.ClassId,
MemberId = data.MemberId
} : DocumentationRepository.Instance.GetDocumentation(data.DocumentationId);
ModuleId = ApiBrowserModuleContext.ModuleContext.ModuleID,
FullName = data.FullName
} : DocumentationRepository.Instance.GetDocumentation(ActiveModule.ModuleID, data.DocumentationId);
if (doc.DocumentationId != -1 && !ApiBrowserModuleContext.Security.CanModerate)
{
if (doc.CreatedByUserID != UserInfo.UserID || doc.IsCurrentVersion)
Expand All @@ -35,53 +35,59 @@ public HttpResponseMessage Save(Documentation data)
{
DocumentationRepository.Instance.UpdateDocumentation(db, UserInfo.UserID);
}
return Request.CreateResponse(HttpStatusCode.OK, DocumentationRepository.Instance.GetDocumentation(db.DocumentationId));
return Request.CreateResponse(HttpStatusCode.OK, DocumentationRepository.Instance.GetDocumentation(ActiveModule.ModuleID, db.DocumentationId));
}
[HttpPost]
[ApiBrowserAuthorize(SecurityLevel = SecurityAccessLevel.Moderate)]
public HttpResponseMessage SetCurrent(int id)
{
var doc = DocumentationRepository.Instance.GetDocumentation(id);
if (doc.ClassId == -1)
var doc = DocumentationRepository.Instance.GetDocumentation(ActiveModule.ModuleID, id);
var m = MemberRepository.Instance.GetMember(doc.ModuleId, doc.FullName);
if (m != null)
{
var m = MemberRepository.Instance.GetMember(doc.MemberId);
m.DocumentationId = doc.DocumentationId;
MemberRepository.Instance.UpdateMember(m.GetMemberBase());
}
else
{
var c = ApiClassRepository.Instance.GetApiClass(doc.ClassId);
c.DocumentationId = doc.DocumentationId;
ApiClassRepository.Instance.UpdateApiClass(c.GetApiClassBase());
var c = ApiClassRepository.Instance.GetApiClass(doc.ModuleId, doc.FullName);
if (c != null)
{
c.DocumentationId = doc.DocumentationId;
ApiClassRepository.Instance.UpdateApiClass(c.GetApiClassBase());
}
}
return Request.CreateResponse(HttpStatusCode.OK);
}
[HttpPost]
[ApiBrowserAuthorize(SecurityLevel = SecurityAccessLevel.Comment)]
public HttpResponseMessage Delete(int id)
{
var doc = DocumentationRepository.Instance.GetDocumentation(id);
var doc = DocumentationRepository.Instance.GetDocumentation(ActiveModule.ModuleID, id);
if (doc.DocumentationId != -1 && !ApiBrowserModuleContext.Security.CanModerate)
{
if (doc.CreatedByUserID != UserInfo.UserID || doc.IsCurrentVersion)
{
return ServiceError("Not allowed");
}
}
DocumentationRepository.Instance.DeleteDocumentation(id);
DocumentationRepository.Instance.DeleteDocumentation(ActiveModule.ModuleID, id);
if (doc.IsCurrentVersion)
{
if (doc.ClassId == -1)
var m = MemberRepository.Instance.GetMember(doc.ModuleId, doc.FullName);
if (m != null)
{
var m = MemberRepository.Instance.GetMember(doc.MemberId);
m.DocumentationId = -1;
MemberRepository.Instance.UpdateMember(m.GetMemberBase());
}
else
{
var c = ApiClassRepository.Instance.GetApiClass(doc.ClassId);
c.DocumentationId = -1;
ApiClassRepository.Instance.UpdateApiClass(c.GetApiClassBase());
var c = ApiClassRepository.Instance.GetApiClass(doc.ModuleId, doc.FullName);
if (c != null)
{
c.DocumentationId = -1;
ApiClassRepository.Instance.UpdateApiClass(c.GetApiClassBase());
}
}
}
return Request.CreateResponse(HttpStatusCode.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public ApiClass() : base()
[DataMember]
public string FullQualifier { get; set; }
[DataMember]
public int ModuleId { get; set; }
[DataMember]
public string ComponentName { get; set; }
[DataMember]
public string LatestVersion { get; set; }
Expand Down Expand Up @@ -71,6 +73,7 @@ public ApiClass Clone()
res.DocumentationContents = DocumentationContents;
res.NamespaceName = NamespaceName;
res.FullQualifier = FullQualifier;
res.ModuleId = ModuleId;
res.ComponentName = ComponentName;
res.LatestVersion = LatestVersion;
res.MemberCount = MemberCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public override void Fill(IDataReader dr)
DocumentationContents = Convert.ToString(Null.SetNull(dr["DocumentationContents"], DocumentationContents));
NamespaceName = Convert.ToString(Null.SetNull(dr["NamespaceName"], NamespaceName));
FullQualifier = Convert.ToString(Null.SetNull(dr["FullQualifier"], FullQualifier));
ModuleId = Convert.ToInt32(Null.SetNull(dr["ModuleId"], ModuleId));
ComponentName = Convert.ToString(Null.SetNull(dr["ComponentName"], ComponentName));
LatestVersion = Convert.ToString(Null.SetNull(dr["LatestVersion"], LatestVersion));
MemberCount = Convert.ToInt32(Null.SetNull(dr["MemberCount"], MemberCount));
Expand All @@ -40,6 +41,8 @@ public override string GetProperty(string strPropertyName, string strFormat, Sys
return PropertyAccess.FormatString(NamespaceName, strFormat);
case "fullqualifier": // NVarChar
return PropertyAccess.FormatString(FullQualifier, strFormat);
case "moduleid": // Int
return ModuleId.ToString(strFormat, formatProvider);
case "componentname": // NVarChar
return PropertyAccess.FormatString(ComponentName, strFormat);
case "latestversion": // VarChar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Connect.ApiBrowser.Core.Models.Documentations
[TableName("Connect_ApiBrowser_Documentations")]
[PrimaryKey("DocumentationId", AutoIncrement = true)]
[DataContract]
[Scope("ModuleId")]
public partial class DocumentationBase : AuditableEntity
{

Expand All @@ -23,9 +24,9 @@ public DocumentationBase()
[DataMember]
public int DocumentationId { get; set; }
[DataMember]
public int ClassId { get; set; }
public int ModuleId { get; set; }
[DataMember]
public int MemberId { get; set; }
public string FullName { get; set; }
[DataMember]
public string Contents { get; set; }
#endregion
Expand All @@ -36,11 +37,11 @@ public void ReadDocumentationBase(DocumentationBase documentation)
if (documentation.DocumentationId > -1)
DocumentationId = documentation.DocumentationId;

if (documentation.ClassId > -1)
ClassId = documentation.ClassId;
if (documentation.ModuleId > -1)
ModuleId = documentation.ModuleId;

if (documentation.MemberId > -1)
MemberId = documentation.MemberId;
if (!String.IsNullOrEmpty(documentation.FullName))
FullName = documentation.FullName;

if (!String.IsNullOrEmpty(documentation.Contents))
Contents = documentation.Contents;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public virtual void Fill(IDataReader dr)
{
FillAuditFields(dr);
DocumentationId = Convert.ToInt32(Null.SetNull(dr["DocumentationId"], DocumentationId));
ClassId = Convert.ToInt32(Null.SetNull(dr["ClassId"], ClassId));
MemberId = Convert.ToInt32(Null.SetNull(dr["MemberId"], MemberId));
ModuleId = Convert.ToInt32(Null.SetNull(dr["ModuleId"], ModuleId));
FullName = Convert.ToString(Null.SetNull(dr["FullName"], FullName));
Contents = Convert.ToString(Null.SetNull(dr["Contents"], Contents));
}

Expand All @@ -38,10 +38,10 @@ public virtual string GetProperty(string strPropertyName, string strFormat, Syst
{
case "documentationid": // Int
return DocumentationId.ToString(strFormat, formatProvider);
case "classid": // Int
return ClassId.ToString(strFormat, formatProvider);
case "memberid": // Int
return MemberId.ToString(strFormat, formatProvider);
case "moduleid": // Int
return ModuleId.ToString(strFormat, formatProvider);
case "fullname": // NVarChar
return PropertyAccess.FormatString(FullName, strFormat);
case "contents": // NVarCharMax
return PropertyAccess.FormatString(Contents, strFormat);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Connect.ApiBrowser.Core.Models.Documentations
[TableName("vw_Connect_ApiBrowser_Documentations")]
[PrimaryKey("DocumentationId", AutoIncrement = true)]
[DataContract]
[Scope("ModuleId")]
public partial class Documentation : DocumentationBase
{

Expand All @@ -20,8 +21,6 @@ public Documentation() : base()

#region Properties
[DataMember]
public string FullQualifier { get; set; }
[DataMember]
public bool IsCurrentVersion { get; set; }
[DataMember]
public string CreatedByUserDisplayName { get; set; }
Expand All @@ -38,8 +37,8 @@ public DocumentationBase GetDocumentationBase()
{
DocumentationBase res = new DocumentationBase();
res.DocumentationId = DocumentationId;
res.ClassId = ClassId;
res.MemberId = MemberId;
res.ModuleId = ModuleId;
res.FullName = FullName;
res.Contents = Contents;
res.CreatedByUserID = CreatedByUserID;
res.CreatedOnDate = CreatedOnDate;
Expand All @@ -51,10 +50,9 @@ public Documentation Clone()
{
Documentation res = new Documentation();
res.DocumentationId = DocumentationId;
res.ClassId = ClassId;
res.MemberId = MemberId;
res.ModuleId = ModuleId;
res.FullName = FullName;
res.Contents = Contents;
res.FullQualifier = FullQualifier;
res.IsCurrentVersion = IsCurrentVersion;
res.CreatedByUserDisplayName = CreatedByUserDisplayName;
res.CreatedByUserEmail = CreatedByUserEmail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public partial class Documentation
public override void Fill(IDataReader dr)
{
base.Fill(dr);
FullQualifier = Convert.ToString(Null.SetNull(dr["FullQualifier"], FullQualifier));
IsCurrentVersion = Convert.ToBoolean(Null.SetNull(dr["IsCurrentVersion"], IsCurrentVersion));
CreatedByUserDisplayName = Convert.ToString(Null.SetNull(dr["CreatedByUserDisplayName"], CreatedByUserDisplayName));
CreatedByUserEmail = Convert.ToString(Null.SetNull(dr["CreatedByUserEmail"], CreatedByUserEmail));
Expand All @@ -30,12 +29,6 @@ public override void Fill(IDataReader dr)
public override string GetProperty(string strPropertyName, string strFormat, System.Globalization.CultureInfo formatProvider, DotNetNuke.Entities.Users.UserInfo accessingUser, DotNetNuke.Services.Tokens.Scope accessLevel, ref bool propertyNotFound)
{
switch (strPropertyName.ToLower()) {
case "fullqualifier": // NVarChar
if (FullQualifier == null)
{
return "";
};
return PropertyAccess.FormatString(FullQualifier, strFormat);
case "iscurrentversion": // Bit
if (IsCurrentVersion == null)
{
Expand Down
3 changes: 3 additions & 0 deletions Connect.ApiBrowser.Core/Models/Members/Member_Declaration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public Member() : base()
[DataMember]
public string FullQualifier { get; set; }
[DataMember]
public int ModuleId { get; set; }
[DataMember]
public string ComponentName { get; set; }
[DataMember]
public string LatestVersion { get; set; }
Expand Down Expand Up @@ -74,6 +76,7 @@ public Member Clone()
res.ClassName = ClassName;
res.NamespaceName = NamespaceName;
res.FullQualifier = FullQualifier;
res.ModuleId = ModuleId;
res.ComponentName = ComponentName;
res.LatestVersion = LatestVersion;
res.CodeBlockCount = CodeBlockCount;
Expand Down
3 changes: 3 additions & 0 deletions Connect.ApiBrowser.Core/Models/Members/Member_Interfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public override void Fill(IDataReader dr)
ClassName = Convert.ToString(Null.SetNull(dr["ClassName"], ClassName));
NamespaceName = Convert.ToString(Null.SetNull(dr["NamespaceName"], NamespaceName));
FullQualifier = Convert.ToString(Null.SetNull(dr["FullQualifier"], FullQualifier));
ModuleId = Convert.ToInt32(Null.SetNull(dr["ModuleId"], ModuleId));
ComponentName = Convert.ToString(Null.SetNull(dr["ComponentName"], ComponentName));
LatestVersion = Convert.ToString(Null.SetNull(dr["LatestVersion"], LatestVersion));
CodeBlockCount = Convert.ToInt32(Null.SetNull(dr["CodeBlockCount"], CodeBlockCount));
Expand All @@ -43,6 +44,8 @@ public override string GetProperty(string strPropertyName, string strFormat, Sys
return PropertyAccess.FormatString(NamespaceName, strFormat);
case "fullqualifier": // NVarChar
return PropertyAccess.FormatString(FullQualifier, strFormat);
case "moduleid": // Int
return ModuleId.ToString(strFormat, formatProvider);
case "componentname": // NVarChar
return PropertyAccess.FormatString(ComponentName, strFormat);
case "latestversion": // VarChar
Expand Down
13 changes: 10 additions & 3 deletions Connect.ApiBrowser.Core/Repositories/ApiClassRepository.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DotNetNuke.Common;
using DotNetNuke.Data;
using DotNetNuke.Framework;
using Connect.ApiBrowser.Core.Models.ApiClasses;
Expand All @@ -10,9 +7,19 @@ namespace Connect.ApiBrowser.Core.Repositories
{
public partial class ApiClassRepository : ServiceLocator<IApiClassRepository, ApiClassRepository>, IApiClassRepository
{
public ApiClass GetApiClass(int moduleId, string fullName)
{
using (var context = DataContext.Instance())
{
return context.ExecuteQuery<ApiClass>(System.Data.CommandType.Text,
"SELECT * FROM {databaseOwner}{objectQualifier}vw_Connect_ApiBrowser_ApiClasses WHERE ModuleId=@0 AND FullQualifier=@1",
moduleId, fullName).FirstOrDefault();
}
}
}
public partial interface IApiClassRepository
{
ApiClass GetApiClass(int moduleId, string fullName);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ namespace Connect.ApiBrowser.Core.Repositories
{
public partial class DocumentationRepository : ServiceLocator<IDocumentationRepository, DocumentationRepository>, IDocumentationRepository
{
public IEnumerable<Documentation> GetDocumentations(int classId, int memberId)
public IEnumerable<Documentation> GetDocumentations(int moduleId, string fullName)
{
using (var context = DataContext.Instance())
{
var rep = context.GetRepository<Documentation>();
return rep.Find("WHERE ClassId=@0 AND MemberId=@1", classId, memberId);
return rep.Find("WHERE ModuleId=@0 AND FullName=@1", moduleId, fullName);
}
}
}
public partial interface IDocumentationRepository
{
IEnumerable<Documentation> GetDocumentations(int classId, int memberId);
IEnumerable<Documentation> GetDocumentations(int moduleId, string fullName);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@ protected override Func<IDocumentationRepository> GetFactory()
{
return () => new DocumentationRepository();
}
public IEnumerable<Documentation> GetDocumentations()
public IEnumerable<Documentation> GetDocumentations(int moduleId)
{
using (var context = DataContext.Instance())
{
var rep = context.GetRepository<Documentation>();
return rep.Get();
return rep.Get(moduleId);
}
}
public Documentation GetDocumentation(int documentationId)
public Documentation GetDocumentation(int moduleId, int documentationId)
{
using (var context = DataContext.Instance())
{
var rep = context.GetRepository<Documentation>();
return rep.GetById(documentationId);
return rep.GetById(documentationId, moduleId);
}
}
public int AddDocumentation(ref DocumentationBase documentation, int userId)
{
Requires.NotNull(documentation);
Requires.PropertyNotNegative(documentation, "ModuleId");
documentation.CreatedByUserID = userId;
documentation.CreatedOnDate = DateTime.Now;
documentation.LastModifiedByUserID = userId;
Expand All @@ -55,12 +56,12 @@ public void DeleteDocumentation(DocumentationBase documentation)
rep.Delete(documentation);
}
}
public void DeleteDocumentation(int documentationId)
public void DeleteDocumentation(int moduleId, int documentationId)
{
using (var context = DataContext.Instance())
{
var rep = context.GetRepository<DocumentationBase>();
rep.Delete("WHERE DocumentationId = @0", documentationId);
rep.Delete("WHERE ModuleId = @0 AND DocumentationId = @1", moduleId, documentationId);
}
}
public void UpdateDocumentation(DocumentationBase documentation, int userId)
Expand All @@ -78,11 +79,11 @@ public void UpdateDocumentation(DocumentationBase documentation, int userId)
}
public partial interface IDocumentationRepository
{
IEnumerable<Documentation> GetDocumentations();
Documentation GetDocumentation(int documentationId);
IEnumerable<Documentation> GetDocumentations(int moduleId);
Documentation GetDocumentation(int moduleId, int documentationId);
int AddDocumentation(ref DocumentationBase documentation, int userId);
void DeleteDocumentation(DocumentationBase documentation);
void DeleteDocumentation(int documentationId);
void DeleteDocumentation(int moduleId, int documentationId);
void UpdateDocumentation(DocumentationBase documentation, int userId);
}
}
Expand Down
Loading

0 comments on commit 2eb7def

Please sign in to comment.