Skip to content

Commit

Permalink
Closes #17 - Add pride/shame value
Browse files Browse the repository at this point in the history
  • Loading branch information
Wndrr committed Mar 19, 2020
1 parent 0dd5d67 commit 51e3139
Show file tree
Hide file tree
Showing 9 changed files with 449 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Shameilst/WebApp/Data/Entities/TaskEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public TaskEntity(string name)

public int Id { get; set; }
public string Name { get; set; }
public int PrideShameValue { get; set; }

public virtual TaskListEntity ParentList { get; set; }
public DateTime DueDate { get; set; } = DateTime.Now;
Expand All @@ -28,6 +29,7 @@ public void Update(TaskForUserModel model)
Name = model.Name;
DueDate = model.DueDate;
IsClosed = model.IsClosed;
PrideShameValue = model.PrideShameValue;
}
}
}
11 changes: 9 additions & 2 deletions Shameilst/WebApp/Data/Services/Overview/OverviewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,23 @@ public class OverviewModel
public OverviewModel(UserEntity userAndRelatedEntities)
{
var tasks = userAndRelatedEntities.Lists.SelectMany(s => s.Tasks);
TasksDueTodayCount = tasks.Count(t => t.DueDate > DateTime.Today && t.DueDate < DateTime.Today.AddDays(1) && !t.IsClosed);
var taskWithDateInThePast = tasks.Where(t => t.DueDate < DateTime.Today);
var overdueTasks = taskWithDateInThePast.Where(t => !t.IsClosed);
TasksDueTodayCount = overdueTasks.Count();
TasksOverdueCount = tasks.Count(t => t.DueDate < DateTime.Today && !t.IsClosed);
TotalListsCount = userAndRelatedEntities.Lists.Count();
TotalOpenTasksCount = tasks.Count(t => !t.IsClosed);
ListsSharedWithThisUserCount = userAndRelatedEntities.ListsSharedWithThisUser.Count();

// Add 1 to both to ensure we don't divide by zero !
var shameValue = overdueTasks.Sum(t => t.PrideShameValue) + 1;
var prideValue = taskWithDateInThePast.Where(t => !t.IsClosed).Sum(t => t.PrideShameValue) + 1;
PrideShameRatioValue = prideValue / shameValue;
}

public int TasksDueTodayCount { get; set; }
public int TasksOverdueCount { get; set; }
public int ShameRatioValue { get; set; }
public int PrideShameRatioValue { get; set; }
public int Progression { get; set; }
public int TotalListsCount { get; set; }
public int TotalOpenTasksCount { get; set; }
Expand Down
19 changes: 15 additions & 4 deletions Shameilst/WebApp/Data/Services/Task/TaskDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,25 @@ public async System.Threading.Tasks.Task Remove(ClaimsPrincipal claimsPrincipal,
}
}

public async System.Threading.Tasks.Task Update(ClaimsPrincipal claimsPrincipal, int idOfTaskToRemove, TaskForUserModel model)
public async System.Threading.Tasks.Task Update(ClaimsPrincipal claimsPrincipal, int idOfTaskToRemove, TaskForUserModel model, bool isUpdatedBySharee)
{
try
{
var user = await GetUser(claimsPrincipal);
var currentUser = await Context.Users.Include(s => s.Lists).SingleAsync(u => u.Id == user.Id);
var task = currentUser.Lists.SelectMany(l => l.Tasks).Single(l => l.Id == idOfTaskToRemove);
task.Update(model);
if (isUpdatedBySharee)
{
var currentUser = await Context.Users
.Include(s => s.ListsSharedWithThisUser).ThenInclude(l => l.List).ThenInclude(l => l.Tasks)
.SingleAsync(u => u.Id == user.Id);
var task = currentUser.ListsSharedWithThisUser.SelectMany(l => l.List.Tasks).Single(l => l.Id == idOfTaskToRemove);
task.Update(model);
}
else
{
var currentUser = await Context.Users.Include(s => s.Lists).SingleAsync(u => u.Id == user.Id);
var task = currentUser.Lists.SelectMany(l => l.Tasks).Single(l => l.Id == idOfTaskToRemove);
task.Update(model);
}
await Context.SaveChangesAsync();
}
catch (Exception e)
Expand Down
2 changes: 2 additions & 0 deletions Shameilst/WebApp/Data/Services/Task/TaskForUserModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public TaskForUserModel(TaskEntity entity)
IsClosed = entity.IsClosed;
ParentListId = entity.ParentList.Id;
ParentListName = entity.ParentList.Name;
PrideShameValue = entity.PrideShameValue;
}


Expand All @@ -23,6 +24,7 @@ public TaskForUserModel(TaskEntity entity)
public DateTime DueDate { get; set; }
public bool IsClosed { get; set; }
public int ParentListId { get; set; }
public int PrideShameValue { get; set; }
public string ParentListName { get; set; }
}
}
Loading

0 comments on commit 51e3139

Please sign in to comment.