private List <WActivity> GenerateActivitiesForTask(WActivity latestActivity, WTask task, DateTime date) { var result = new List <WActivity>(); DateTime nextActivityDate = task.StartDate.Date; if (latestActivity != null) { var nextFromActivity = latestActivity.Date.Date.AddDays(task.Frequency); if (DateTime.Compare(nextFromActivity, nextActivityDate) > 0) { nextActivityDate = nextFromActivity; } } while (DateTime.Compare(nextActivityDate, date) <= 0) { result.Add(new WActivity() { Date = nextActivityDate, WTask = task }); nextActivityDate = nextActivityDate.AddDays(task.Frequency); } return(result); }
public void UpdateEntities(IDbSet <WActivity> activities, IEnumerable <ActivityDto> dtos) { if (activities == null || dtos == null) { return; } foreach (var dto in dtos) { var activityModelToUpdate = activities.Where(x => x.Id == dto.Id).SingleOrDefault(); if (activityModelToUpdate == null) { activityModelToUpdate = new WActivity(); activities.Add(activityModelToUpdate); } if (activityModelToUpdate.WTask == null) { activityModelToUpdate.WTask = new WTask(); } if (dto.Task != null) { _conversionService.ConvertFromDto(activityModelToUpdate.WTask, dto.Task); } _conversionService.ConvertFromDto(activityModelToUpdate, dto); } }
public void GetActivityWithNotNullTask() { WTask t1 = new WTask() { Id = 1234, Name = "t1", Frequency = 1, StartDate = new DateTime(2017, 10, 10) }; WActivity a1 = new WActivity() { Id = 5123, WTask = t1, Date = new DateTime(2017, 10, 10) }; using (WContext db = new WContext()) { db.WActivities.Add(a1); db.SaveChanges(); } bool resut = false; using (WContext db = new WContext()) { var dbActivity = db.WActivities.Include(a => a.WTask).Where(x => x.Id == a1.Id).SingleOrDefault(); if (dbActivity != null && dbActivity.WTask != null) { resut = true; } } Assert.IsTrue(resut); }
public void ConvertFromDto(WActivity wActivity, ActivityDto dto, IEnumerable <WTask> tasks) { ConvertFromDto(wActivity, dto); var wtask = tasks.Where(x => x.Id == dto.Id).SingleOrDefault(); if (wtask != null) { wActivity.WTask = wtask; } }
public void ConvertToDto(ActivityDto dto, WActivity wActivity, IEnumerable <TaskDto> tasks) { ConvertToDto(dto, wActivity); var task = tasks.Where(x => x.Id == wActivity.Id).SingleOrDefault(); if (task != null) { dto.Task = task; } }
public List <WActivity> GenerateActivities(IEnumerable <WActivity> activities, IEnumerable <WTask> tasks, DateTime date) { List <WActivity> generatedTodayTasks = new List <WActivity>(); foreach (var task in tasks) { if (!task.Archivized) { WActivity latestActivity = null; var activitiesForTask = activities.Where(x => x.WTask.Id == task.Id); if (activitiesForTask != null && activitiesForTask.FirstOrDefault() != null) { var latestActivityDate = activitiesForTask.Max(x => x.Date); latestActivity = activitiesForTask.First(x => x.Date == latestActivityDate); } generatedTodayTasks.AddRange(GenerateActivitiesForTask(latestActivity, task, date)); } } return(generatedTodayTasks); }
public void ConvertFromDto(WActivity wActivity, ActivityDto dto) { ConvertFromModelDto(wActivity, dto); wActivity.Date = dto.Date; wActivity.IsDone = dto.IsDone; }
public void ConvertToDto(ActivityDto dto, WActivity wActivity) { ConvertToModelDto(dto, wActivity); dto.Date = wActivity.Date; dto.IsDone = wActivity.IsDone; }
protected override void Seed(WContext db) { WGroup g1 = new WGroup() { Name = "Group1", Description = "Animals" }; WGroup g2 = new WGroup() { Name = "Group2", Description = "Plants" }; WTask t1 = new WTask() { Name = "Feed the cat", Description = "Royal Canin", Frequency = 1, StartDate = DateTime.Today }; WTask t2 = new WTask() { Name = "Feed the dog", Frequency = 1, StartDate = new DateTime(2017, 12, 01) }; WTask t3 = new WTask() { Name = "Water plant1", Frequency = 3, StartDate = new DateTime(2017, 12, 02) }; WTask t4 = new WTask() { Name = "water Maciek", Frequency = 1, StartDate = new DateTime(2017, 12, 03) }; WTask t5 = new WTask() { Name = "give insect to Maciek", Frequency = 20, StartDate = new DateTime(2017, 12, 01) }; WActivity a1 = new WActivity() { WTask = t1, Date = DateTime.Today, IsDone = true }; WActivity a2 = new WActivity() { WTask = t1, Date = new DateTime(2017, 12, 03), IsDone = false }; WActivity a3 = new WActivity() { WTask = t1, Date = new DateTime(2017, 12, 03), IsDone = true }; g1.WTasks.Add(t1); g1.WTasks.Add(t2); g1.WTasks.Add(t5); g2.WTasks.Add(t3); g2.WTasks.Add(t4); t1.WGroups.Add(g1); t2.WGroups.Add(g1); t3.WGroups.Add(g2); t4.WGroups.Add(g2); t5.WGroups.Add(g1); t5.WGroups.Add(g2); db.WGroups.Add(g1); db.WGroups.Add(g2); db.WTasks.Add(t1); db.WTasks.Add(t2); db.WTasks.Add(t3); db.WTasks.Add(t5); db.WActivities.Add(a1); db.WActivities.Add(a2); db.WActivities.Add(a3); db.SaveChanges(); }