198 lines
6.6 KiB
C#
198 lines
6.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using EnVisage.Code;
|
|
using System.Linq;
|
|
|
|
namespace EnVisage.Models
|
|
{
|
|
public class WorkWeekModel : IBaseModel<WorkWeek>
|
|
{
|
|
public Guid Id { get; set; }
|
|
|
|
[Required]
|
|
[MaxLength(100)]
|
|
[Display(Name = "Name")]
|
|
public string Name { get; set; }
|
|
|
|
[Display(Name = "Days Of Week")]
|
|
public string DaysOfWeek { get; set; }
|
|
|
|
public bool Monday { get; set; }
|
|
public bool Tuesday { get; set; }
|
|
public bool Wednesday { get; set; }
|
|
public bool Thursday { get; set; }
|
|
public bool Friday { get; set; }
|
|
public bool Saturday { get; set; }
|
|
public bool Sunday { get; set; }
|
|
|
|
[Display(Name = "Make Default Work Week")]
|
|
public bool IsDefault { get; set; }
|
|
|
|
public bool IsSystem { get; set; }
|
|
public bool CanBeDeleted { get; set; }
|
|
/// <summary>
|
|
/// Casts a <see cref="Type"/> obect to the object of type <see cref="TypeModel"/>.
|
|
/// </summary>
|
|
/// <param name="obj">A <see cref="Type"/> object.</param>
|
|
/// <returns>A <see cref="TypeModel"/> object filled with data from db.</returns>
|
|
public static explicit operator WorkWeekModel(WorkWeek obj)
|
|
{
|
|
if (obj == null)
|
|
return null;
|
|
var model = new WorkWeekModel
|
|
{
|
|
Id = obj.Id,
|
|
Name = obj.Name,
|
|
Monday = obj.Monday,
|
|
Tuesday = obj.Tuesday,
|
|
Wednesday = obj.Wednesday,
|
|
Thursday = obj.Thursday,
|
|
Friday = obj.Friday,
|
|
Saturday = obj.Saturday,
|
|
Sunday = obj.Sunday,
|
|
IsDefault = obj.IsDefault,
|
|
IsSystem = obj.IsSystem
|
|
};
|
|
model.DaysOfWeek = getDaysOfWeek(model, "Monday", false);
|
|
model.TrimStringProperties();
|
|
return model;
|
|
}
|
|
|
|
public static string getDaysOfWeek(WorkWeekModel obj, string day, bool interval)
|
|
{
|
|
var result = string.Empty;
|
|
switch (day)
|
|
{
|
|
case "Tuesday":
|
|
if (obj.Tuesday)
|
|
{
|
|
if (!obj.Wednesday)
|
|
{
|
|
result = "Tuesday, ";
|
|
interval = false;
|
|
}
|
|
else {
|
|
if (!interval)
|
|
result = "Tuesday - ";
|
|
interval = true;
|
|
}
|
|
}
|
|
result += getDaysOfWeek(obj, "Wednesday", interval);
|
|
break;
|
|
|
|
case "Wednesday":
|
|
if (obj.Wednesday)
|
|
{
|
|
if (!obj.Thursday)
|
|
{
|
|
result = "Wednesday, ";
|
|
interval = false;
|
|
}
|
|
else {
|
|
if (!interval)
|
|
result = "Wednesday - ";
|
|
interval = true;
|
|
}
|
|
}
|
|
result += getDaysOfWeek(obj, "Thursday", interval);
|
|
break;
|
|
|
|
case "Thursday":
|
|
if (obj.Thursday)
|
|
{
|
|
if (!obj.Friday)
|
|
{
|
|
result = "Thursday, ";
|
|
interval = false;
|
|
}
|
|
else {
|
|
if (!interval)
|
|
result = "Thursday - ";
|
|
interval = true;
|
|
}
|
|
}
|
|
result += getDaysOfWeek(obj, "Friday", interval);
|
|
break;
|
|
|
|
case "Friday":
|
|
if (obj.Friday)
|
|
{
|
|
if (!obj.Saturday)
|
|
{
|
|
result = "Friday, ";
|
|
interval = false;
|
|
}
|
|
else {
|
|
if (!interval)
|
|
result = "Friday - ";
|
|
interval = true;
|
|
}
|
|
}
|
|
result += getDaysOfWeek(obj, "Saturday", interval);
|
|
break;
|
|
|
|
case "Saturday":
|
|
if (obj.Saturday)
|
|
{
|
|
if (!obj.Sunday)
|
|
{
|
|
result = "Saturday";
|
|
interval = false;
|
|
}
|
|
else {
|
|
if (!interval)
|
|
result = "Saturday - Sunday";
|
|
else
|
|
result = "Sunday";
|
|
}
|
|
}
|
|
else {
|
|
if (obj.Sunday)
|
|
{
|
|
result = "Sunday";
|
|
}
|
|
}
|
|
break;
|
|
|
|
default: // case "Monday":
|
|
if (obj.Monday)
|
|
{
|
|
if (!obj.Tuesday)
|
|
{
|
|
result = "Monday, ";
|
|
interval = false;
|
|
}
|
|
else {
|
|
result = "Monday - ";
|
|
interval = true;
|
|
}
|
|
}
|
|
result += getDaysOfWeek(obj, "Tuesday", interval);
|
|
break;
|
|
|
|
}
|
|
|
|
return (string.IsNullOrEmpty( day) ? result.TrimEnd(new char[] {' ',','}) : result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Copies data from model to DAL object.
|
|
/// </summary>
|
|
/// <param name="dbObj">A target DAL object.</param>
|
|
public void CopyTo(WorkWeek dbObj)
|
|
{
|
|
if (dbObj == null)
|
|
throw new ArgumentNullException();
|
|
dbObj.Name = Name;
|
|
dbObj.Monday = Monday;
|
|
dbObj.Tuesday = Tuesday;
|
|
dbObj.Wednesday = Wednesday;
|
|
dbObj.Thursday = Thursday;
|
|
dbObj.Friday = Friday;
|
|
dbObj.Saturday = Saturday;
|
|
dbObj.Sunday = Sunday;
|
|
dbObj.IsSystem = IsSystem;
|
|
}
|
|
}
|
|
} |