-
-
Save JoshReedSchramm/4320106 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* So I didn't really address the naming piece, but I'd start by going down this route */ | |
public class Task : ActiveRecord | |
{ | |
public string Name { get; set; } | |
public int AssignedTo_UserId { get; set; } | |
public DateTime DueOn { get; set; } | |
private INotifier _notifier; | |
public Task(INotifier notifier) : this() | |
{ | |
_notifier = notifier; | |
} | |
public Task() | |
{ | |
// I feel like i'd just pass in the date in the constructor. | |
// If not required I'd make DueOn nullable | |
DueOn = DateTime.Now.AddDays(1); | |
} | |
override void AfterInsert() | |
{ | |
if (_notifier != null) | |
_notifier.Notify(AssignedTo_UserId); | |
} | |
} | |
public class EmailNotifier : INotifier { | |
public void Notify(int who) { | |
Email.Send(who, "New Task", "You have been assigned a new task"); | |
} | |
} | |
// Not sure I like the coupling of user id to notification | |
// but I'll save that for a later refactor | |
public interface INotifier { | |
void Notify(int who); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How would you suppress the email notification in a case where you're creating a new task, but you don't want a notification?