Skip to content
This repository was archived by the owner on Oct 3, 2022. It is now read-only.

Commit 05b48b5

Browse files
authored
Merge pull request #42 from BinderDyn/Create-entries-without-subtasks
Changed the way entries are calculated as well as creating entries wi…
2 parents 745924f + c4bf2d4 commit 05b48b5

File tree

9 files changed

+56
-13
lines changed

9 files changed

+56
-13
lines changed
0 Bytes
Binary file not shown.

.vs/TakeMyTime.NETCore/v16/.suo

1.5 KB
Binary file not shown.

TakeMyTime.BLL.Tests/ProjectLogicTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ private void CreateProjectWithEntries()
105105
}),
106106
};
107107

108+
foreach (var entry in entries)
109+
{
110+
entry.CalculateDuration();
111+
}
112+
108113
this.uow.Entries.AddRange(entries);
109114
this.uow.Complete();
110115
}

TakeMyTime.DAL/TakeMyTime.DAL.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<Compile Remove="Migrations\20200115124254_subtasks.Designer.cs" />
1515
<Compile Remove="Migrations\20200318201416_assignment_id.cs" />
1616
<Compile Remove="Migrations\20200318201416_assignment_id.Designer.cs" />
17+
<Compile Remove="Migrations\20200319194258_project_id_constraint.cs" />
18+
<Compile Remove="Migrations\20200319194258_project_id_constraint.Designer.cs" />
1719
</ItemGroup>
1820

1921
<ItemGroup>

TakeMyTime.DAL/TakeMyTimeDbContext.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ public TakeMyTimeDbContext() : base()
1717
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
1818
{
1919
// var connectionString = ConfigurationManager.ConnectionStrings["TakeMyTimeDebug"];
20-
optionsBuilder.UseSqlite(ConfigurationManager.ConnectionStrings["TakeMyTimeDebug"].ConnectionString);
21-
// optionsBuilder.UseSqlite("Data Source=TakeMyTimeDebug.db;");
20+
if (ConfigurationManager.ConnectionStrings["TakeMyTimeDebug"] != null)
21+
{
22+
optionsBuilder.UseSqlite(ConfigurationManager.ConnectionStrings["TakeMyTimeDebug"].ConnectionString);
23+
}
24+
else
25+
{
26+
optionsBuilder.UseSqlite("Data Source=TakeMyTimeTestContext.db;");
27+
}
2228

2329
optionsBuilder.EnableSensitiveDataLogging(true);
2430
}

TakeMyTime.Models.Tests/AssignmentTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void Create_Test()
3232
var assignment = Assignment.Create(createParam);
3333

3434
// ASSERT
35-
Assert.AreEqual(AssignmentStatus.InProgress, assignment.AssignmentStatus);
35+
Assert.AreEqual(AssignmentStatus.Future, assignment.AssignmentStatus);
3636
}
3737

3838
[TestMethod]

TakeMyTime.Models.Tests/EntryTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public void IsDurationCorrect()
3838
{
3939
// ARRANGE & ACT
4040
var entry = Entry.Create(createParam);
41+
entry.CalculateDuration();
4142

4243
// ASSERT
4344
Assert.AreEqual(new TimeSpan(0, 10, 0).Minutes, new TimeSpan(entry.DurationAsTicks.Value).Minutes);

TakeMyTime.Models/Models/Entry.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ public interface ICreateParam : IUpdateParam
6161
DateTime? Ended { get; set; }
6262
}
6363

64-
//private void CalculateDuration()
65-
//{
66-
// bool canCalculateDuration = this.Started.HasValue && this.Ended.HasValue;
67-
// if (canCalculateDuration)
68-
// {
69-
// TimeSpan duration = this.Ended.Value - this.Started.Value;
70-
// this.DurationAsTicks = duration.Ticks;
71-
// }
72-
//}
64+
public void CalculateDuration()
65+
{
66+
bool canCalculateDuration = this.Started.HasValue && this.Ended.HasValue;
67+
if (canCalculateDuration)
68+
{
69+
TimeSpan duration = this.Ended.Value - this.Started.Value;
70+
this.DurationAsTicks = duration.Ticks;
71+
}
72+
}
7373

7474
[ForeignKey("Project")]
7575
public int? Project_Id { get; set; }

TakeMyTime.WPF/Assignments/AssignmentOverview.xaml.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,42 @@ private void btn_EditAssignment_Click(object sender, RoutedEventArgs e)
138138

139139
private void lv_Assignments_MouseDoubleClick(object sender, MouseButtonEventArgs e)
140140
{
141-
if (this.SelectedAssignment != null && this.SelectedAssignment.HasSubtasks)
141+
if (this.SelectedAssignment != null)
142142
{
143+
CheckForSubtasksForAssignmentAndCreateIfNecessary(this.SelectedAssignment.Id);
143144
var addEntryDialog = new AddEntry(this.SelectedAssignment.ProjectId, this.SelectedAssignment.Id);
144145
addEntryDialog.ShowDialog();
145146
}
146147
}
147148

149+
private void CheckForSubtasksForAssignmentAndCreateIfNecessary(int assignment_id)
150+
{
151+
try
152+
{
153+
var subtaskLogic = new SubtaskLogic();
154+
var existingSubtasks = subtaskLogic.GetByAssignmentId(assignment_id);
155+
if (existingSubtasks == null || existingSubtasks.Count() == 0)
156+
{
157+
var assignmentLogic = new AssignmentLogic();
158+
var assignment = assignmentLogic.GetAssignmentById(assignment_id);
159+
var defaultSubtask = new SubtaskCreateViewModel
160+
{
161+
Name = assignment.Name,
162+
Description = assignment.Description,
163+
Priority = EnumDefinition.SubtaskPriority.Medium
164+
};
165+
assignmentLogic.AddSubtask(assignment_id, defaultSubtask);
166+
assignmentLogic.Dispose();
167+
}
168+
subtaskLogic.Dispose();
169+
}
170+
catch (Exception e)
171+
{
172+
Logger.LogException(e);
173+
MessageBox.Show(e.Message);
174+
}
175+
}
176+
148177
private void btn_SetDone_Click(object sender, RoutedEventArgs e)
149178
{
150179
Logger.Log(string.Format("{0}.btn_SetDone_Click", GetType().FullName));

0 commit comments

Comments
 (0)