Skip to content

Commit

Permalink
#382: Optimize object participants functionality and UI
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolagsiderov committed Jun 30, 2021
1 parent 87e7302 commit 2e3c31c
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 162 deletions.
1 change: 0 additions & 1 deletion APPartment.API/Meta/Controllers/CommentsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public ActionResult Post(CommentPostViewModel comment)
try
{
comment = BaseCRUDService.Save(comment);
BaseCRUDService.AddUserAsParticipantToObject(comment.TargetObjectID, (long)CurrentUserID, comment.ObjectTypeID);
var result = new CommentsRenderer(CurrentUserID, CurrentHomeID).BuildPostComment(comment);

return Ok(result);
Expand Down
1 change: 0 additions & 1 deletion APPartment.API/Meta/Controllers/EventsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public ActionResult Post(EventPostViewModel @event)
var participants = @event.ParticipantUserIDs;

@event = BaseCRUDService.Save(@event);
BaseCRUDService.AddUserAsParticipantToObject(@event.TargetObjectID, (long)CurrentUserID, @event.ObjectTypeID);

foreach (var userID in participants)
{
Expand Down
1 change: 0 additions & 1 deletion APPartment.API/Meta/Controllers/ObjectLinksController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public ActionResult Post(ObjectLinkPostViewModel link)
try
{
link = BaseCRUDService.Save(link);
BaseCRUDService.AddUserAsParticipantToObject(link.TargetObjectID, (long)CurrentUserID, link.ObjectTypeID);

link.ObjectBName = BaseCRUDService.GetEntity(link.ObjectBID).Name;

Expand Down
34 changes: 27 additions & 7 deletions APPartment.Data/Server/Base/BaseFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,34 +113,36 @@ public List<T> GetLookupObjects<T>(Expression<Func<T, bool>> filter)
}

public T Create<T>(T businessObject, long userID, long? homeID)
where T : class, IBaseObject
where T : class, IBaseObject, new()
{
var objectID = dao.SaveCreateBaseObject(businessObject, userID, homeID);
AddUserAsParticipantToObjectIfNecessary<T>(objectID);
return dao.SaveCreateBusinessObject(businessObject, objectID);
}

public T Update<T>(T businessObject, long userID, long homeID)
where T : class, IBaseObject
where T : class, IBaseObject, new()
{
dao.SaveUpdateBaseObject(businessObject, userID, homeID);
AddUserAsParticipantToObjectIfNecessary<T>(businessObject.ObjectID);
return dao.SaveUpdateBusinessObject(businessObject);
}

public void Delete<T>(T businessObject)
where T : class, IBaseObject
where T : class, IBaseObject, new()
{
dao.DeleteBusinessObjectAndAllItsBaseReferences(businessObject);
}

public bool Any<T>()
where T : class, IBaseObject
where T : class, IBaseObject, new()
{
var result = false;
return dao.AnyBusinessObjects<T>(result);
}

public bool Any<T>(Expression<Func<T, bool>> filter)
where T : class, IBaseObject
where T : class, IBaseObject, new()
{
var result = false;

Expand All @@ -153,14 +155,14 @@ public bool Any<T>(Expression<Func<T, bool>> filter)
}

public int Count<T>()
where T : class, IBaseObject
where T : class, IBaseObject, new()
{
var result = 0;
return dao.CountBusinessObjects<T>(result);
}

public int Count<T>(Expression<Func<T, bool>> filter)
where T : class, IBaseObject
where T : class, IBaseObject, new()
{
var result = 0;

Expand All @@ -177,5 +179,23 @@ public string GetObjectTypeName(long objectTypeID)
var objectType = (ObjectTypes)objectTypeID;
return objectType.ToString();
}

public void AddUserAsParticipantToObjectIfNecessary<T>(long targetObjectID)
where T : class, IBaseObject, new()
{
var theObject = GetObject<T>(x => x.ObjectID == targetObjectID);

if (theObject.ModifiedByID != null && theObject.ModifiedByID > 0)
{
if (theObject.ObjectTypeID != (long)ObjectTypes.ObjectParticipant && theObject.ObjectTypeID != (long)ObjectTypes.Message)
{
if (!Any<ObjectParticipant>(x => x.TargetObjectID == targetObjectID && x.UserID == theObject.ModifiedByID))
{
var participant = new ObjectParticipant() { TargetObjectID = targetObjectID, UserID = (long)theObject.ModifiedByID };
Create(participant, (long)theObject.ModifiedByID, theObject.HomeID);
}
}
}
}
}
}
31 changes: 6 additions & 25 deletions APPartment.Infrastructure/Services/Base/BaseCRUDService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,6 @@ public T Save<T>(T model)

var result = (T)toViewModelFunc.Invoke(this, new object[] { serverModel });

AddUserAsParticipantToObject(result.ObjectID, (long)result.ModifiedByID, result.ObjectTypeID);

return result;
}
else
Expand Down Expand Up @@ -287,8 +285,6 @@ public T Save<T>(T model)

var result = (T)toViewModelFunc.Invoke(this, new object[] { serverModel });

AddUserAsParticipantToObject(result.ObjectID, (long)result.ModifiedByID, result.ObjectTypeID);

return result;
}
}
Expand Down Expand Up @@ -349,7 +345,7 @@ public T GetLookupEntity<T>(Expression<Func<T, bool>> filter)
}

// TODO: Complete function
public List<T> GetLookupObjects<T>()
public List<T> GetLookupCollection<T>()
where T : class, ILookupObject, new()
{
// TODO: Implement mapping from server to view model
Expand All @@ -365,7 +361,7 @@ public List<T> GetLookupObjects<T>()
}

// TODO: Complete function
public List<T> GetLookupObjects<T>(Expression<Func<T, bool>> filter)
public List<T> GetLookupCollection<T>(Expression<Func<T, bool>> filter)
where T : class, ILookupObject, new()
{
// TODO: Implement mapping from server to view model
Expand All @@ -385,7 +381,7 @@ public bool Any<T>()
{
var anyFunc = typeof(BaseFacade)
.GetMethods(BindingFlags.Public | BindingFlags.Instance)
.Where(x => x.Name.Equals(nameof(BaseFacade.Any)))
.Where(x => x.Name.Equals(nameof(this.Any)))
.FirstOrDefault()
.MakeGenericMethod(GetServerModelType<T>());

Expand All @@ -400,7 +396,7 @@ public bool Any<T>(Expression<Func<T, bool>> filter)

var anyFilteredFunc = typeof(BaseFacade)
.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)
.Where(x => x.Name.Equals(nameof(BaseFacade.Any)))
.Where(x => x.Name.Equals(nameof(this.Any)))
.Last()
.MakeGenericMethod(serverModelType);

Expand All @@ -421,7 +417,7 @@ public int Count<T>()
{
var countFunc = typeof(BaseFacade)
.GetMethods(BindingFlags.Public | BindingFlags.Instance)
.Where(x => x.Name.Equals(nameof(BaseFacade.Count)))
.Where(x => x.Name.Equals(nameof(this.Count)))
.FirstOrDefault()
.MakeGenericMethod(GetServerModelType<T>());

Expand All @@ -436,7 +432,7 @@ public int Count<T>(Expression<Func<T, bool>> filter)

var countFilteredFunc = typeof(BaseFacade)
.GetMethods(BindingFlags.Public | BindingFlags.Instance)
.Where(x => x.Name.Equals(nameof(BaseFacade.Count)))
.Where(x => x.Name.Equals(nameof(this.Count)))
.Last()
.MakeGenericMethod(serverModelType);

Expand All @@ -452,21 +448,6 @@ public int Count<T>(Expression<Func<T, bool>> filter)
.Invoke(BaseFacade, new object[] { convertedFilter });
}

public void AddUserAsParticipantToObject(long targetObjectID, long userID, long objectTypeID)
{
if (userID != 0)
{
if (objectTypeID != (long)ObjectTypes.ObjectParticipant && objectTypeID != (long)ObjectTypes.Message)
{
if (!Any<ObjectParticipantPostViewModel>(x => x.TargetObjectID == targetObjectID && x.UserID == userID))
{
var participant = new ObjectParticipantPostViewModel() { TargetObjectID = targetObjectID, UserID = userID };
Save(participant);
}
}
}
}

public string GetObjectTypeName(long objectTypeID)
{
return BaseFacade.GetObjectTypeName(objectTypeID);
Expand Down
68 changes: 68 additions & 0 deletions APPartment.Web/Views/Shared/_Console.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
@model APPartment.Infrastructure.UI.Common.ViewModels.Base.PostViewModel

@{
var consoleHeader = "Console [Create]";

if (Model.ID > 0)
{
consoleHeader = $"Console [ID: {Model.ID}, Name: {Model.Name}]";
}
}

<div class="col-md-3">
<div class="card">
<div class="card-header">
@consoleHeader
</div>
<div class="card-body">
@if (Model.ID > 0)
{
<div id="object-additional-info-for-@Model.ID" style="font-family: monospace;">
Created by ID: @Model.CreatedByID
<br />
Created date: @Model.CreatedDate.ToString("dd'/'MM'/'yyyy HH:mm:ss")
<br />
Modified by ID: @Model.ModifiedByID
<br />
Modified date: @Model.ModifiedDate.Value.ToString("dd'/'MM'/'yyyy HH:mm:ss")
</div>
<hr />
<div id="object-actions-for-@Model.ID">
@{
var actionsHtml = string.Join(" &nbsp;", Model.ActionsHtml);
}
@Html.Raw(actionsHtml)
</div>
<hr />
<div id="object-participants-for-@Model.ID">
<strong><i class="fas fa-user-friends"></i> Participants:</strong>
<div id="objectg-participants">
@if (Model.Participants.Any())
{
@foreach (var participant in Model.Participants)
{
<div class="object-participant">
@participant.Username
</div>
}
}
else
{
<div>
None
</div>
}
</div>
</div>
}
else
{
<div style="font-family: monospace;">
Created by ID: Probably you
<br />
Created date: Probably now
</div>
}
</div>
</div>
</div>
26 changes: 1 addition & 25 deletions APPartment.Web/Views/Shared/_Details.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,5 @@
</div>
</div>
</div>
<div class="col-md-3">
<div class="card">
<div class="card-header">
Console [ID: @Model.ID, Name: @Model.Name]
</div>
<div class="card-body">
<div id="object-additional-info-for-@Model.ID" style="font-family: monospace;">
Created by ID: @Model.CreatedByID
<br />
Created date: @Model.CreatedDate.ToString("dd'/'MM'/'yyyy HH:mm:ss")
<br />
Modified by ID: @Model.ModifiedByID
<br />
Modified date: @Model.ModifiedDate.Value.ToString("dd'/'MM'/'yyyy HH:mm:ss")
</div>
<hr />
<div id="object-actions-for-@Model.ID">
@{
var actionsHtml = string.Join(" &nbsp;", Model.ActionsHtml);
}
@Html.Raw(actionsHtml)
</div>
</div>
</div>
</div>
@await Html.PartialAsync("_Console", Model)
</div>
Loading

0 comments on commit 2e3c31c

Please sign in to comment.