I'm writing a code for my application: you can create a task, and you can choose the moment when you want to send this task (to some kind of user):
- Send now
- Send later
- Repeat
You can select from above options. If you choose send later, you'll be prompted for a date:
And there are variety of options if you choose Repeat:
(they're all on imgur if you're interested)
I use design-driven-development approach, and now I'm working on the view model for ASP.Net MVC application. Now it looks like this:
public class TaskViewModel
{
// ... other properties (title, etc...)
public SendOptions SendOption { get; set; } // when to send: now || later || repeat
public RepeatDetails Repeat { get; set; }
public LaterDetails Later { get; set; }
// ==============================================
// enumerations & classes
// ==============================================
public enum SendOptions { Now = 0, Later = 1, Repeat = 2}
public enum RepeatTypes { Daily = 0, Weekly = 1, Monthly = 2, Yearly = 3 }
public enum WeekDay {
[EnumDescription("working day")]
WorkingDay,
[EnumDescription("weekend")]
WeekEnd,
[EnumDescription("sunday")]
Sunday,
[EnumDescription("monday")]
Monday,
[EnumDescription("tuesday")]
Tuesday,
[EnumDescription("wednesday")]
Wednesday,
[EnumDescription("thursday")]
Thursday,
[EnumDescription("friday")]
Friday,
[EnumDescription("saturday")]
Saturday
}
public enum WeekDayNumber
{
[EnumDescription("1st")]
First,
[EnumDescription("2nd")]
Second,
[EnumDescription("3rd")]
Third,
[EnumDescription("4th")]
Fourth,
[EnumDescription("Last")]
Last
}
public enum Month
{
[EnumDescription("January")]
January,
[EnumDescription("February")]
February,
[EnumDescription("March")]
March,
[EnumDescription("April")]
April,
[EnumDescription("May")]
May,
[EnumDescription("June")]
June,
[EnumDescription("July")]
July,
[EnumDescription("August")]
August,
[EnumDescription("September")]
September,
[EnumDescription("October")]
October,
[EnumDescription("November")]
November,
[EnumDescription("December")]
December
}
// ==============================================
// class for later screen details
// ==============================================
public class LaterDetails
{
public DateTimeOffset LaterUtc { get; set; }
}
// ==============================================
// class for repeat screen details
// ==============================================
public class RepeatDetails
{
public RepeatTypes RepeatType { get; set; }
public string StartAtTime { get; set; }
public RepeatDailyDetails Daily { get; set; }
public RepeatWeeklyDetails Weekly { get; set; }
public RepeatMonthlyDetails Monthly { get; set; }
public RepeatYearlyDetails Yearly { get; set; }
public EndByDetails EndBy { get; set; }
public class RepeatDailyDetails
{
public enum RepeatDailyTypes { EveryDay = 0, EveryWorkingDay = 1 }
public RepeatDailyTypes RepeatDailyType { get; set; }
public int EveryNthDay { get; set; }
}
public class RepeatWeeklyDetails
{
public int EveryNthWeek { get; set; }
public bool IsSunday { get; set; }
public bool IsMonday { get; set; }
public bool IsTuesday { get; set; }
public bool IsWednesday { get; set; }
public bool IsThursday { get; set; }
public bool IsFriday { get; set; }
public bool IsSaturday { get; set; }
}
public class RepeatMonthlyDetails
{
public enum RepeatMonthlyTypes { OnCertainDay = 0, At = 1 }
public RepeatMonthlyTypes RepeatMonthlyType { get; set; }
public int EveryNthMonth { get; set; }
public string OnNthDay { get; set; }
public WeekDayNumber WeekDayNumber { get; set; }
public WeekDay WeekDay { get; set; }
}
public class RepeatYearlyDetails
{
public int EveryNthYear { get; set; }
public Month Month { get; set; }
public enum RepeatYearlyTypes { OnCertainDay = 0, At = 1 }
public RepeatYearlyTypes RepeatYearlyType { get; set; }
public string OnNthDay { get; set; }
public WeekDayNumber WeekDayNumber { get; set; }
public WeekDay WeekDay { get; set; }
}
}
// ==============================================
// class for end by details
// ==============================================
public class EndByDetails
{
public enum EndByTypes { NoEndDate = 0, EndAfter = 1, EndByDate = 2 }
public EndByTypes EndByType { get; set; }
public int Occurrences { get; set; }
}
public TaskViewModel()
{
Later = new LaterDetails();
Repeat = new RepeatDetails()
{
Daily = new RepeatDetails.RepeatDailyDetails(),
Weekly = new RepeatDetails.RepeatWeeklyDetails(),
Monthly = new RepeatDetails.RepeatMonthlyDetails(),
Yearly = new RepeatDetails.RepeatYearlyDetails(),
EndBy = new EndByDetails()
};
}
}
EnumDescription attribute is used to create a dropdown list based on descriptions for enums:
public class EnumDescription : Attribute
{
public string Text
{
get { return _text; }
} private string _text;
public EnumDescription(string text)
{
_text = text;
}
}
I'm not satisfied with a code, and need a fresh look. What would you suggest to improve? Thanks in advance.