Hi everybody,
I want to check if the dates are not overlap each other, otherwise give a message
I have this method:
<pre lang="xml">public bool IsOverlapping(List <AgendaEventViewModel> viewModel, AgendaEventViewModel newItem)
{
bool isOverlapping = false;
ReservationModel r = new ReservationModel(int.Parse(viewModel.id));
if (r.Begin == r.Begin)
{
}
if (viewModel.Any(m => DateTime.Parse(m.start) < DateTime.Parse( newItem.start) && DateTime.Parse(newItem.start) < DateTime.Parse(m.end) ?? DateTime.MaxValue)));
{
this.ShowMessage(Message.Type.Info, Resources.AgendaEvent.IsOverlapping);
}
return isOverlapping;
}
and this is the model:
public class AgendaEventViewModel
{
public string ReturnUrl { get; set; }
public string id { get; set; }
public int? funeralId { get; set; }
public int? reservationId { get; set; }
public int? roomId { get; set; }
[Display(Name = "Title", ResourceType = typeof(Resources.AgendaEvent))]
public string title { get; set; }
[Display(Name = "Start", ResourceType = typeof(Resources.AgendaEvent))]
public string start { get; set; }
[Display(Name = "End", ResourceType = typeof(Resources.AgendaEvent))]
public string end { get; set; }
public string top { get; set; }
public string left { get; set; }
public List<RoomItemModel> RoomItems { get; set; }
public List<CateringItemModel> CateringItems { get; set; }
[Display(Name = "SeatingCapacity", ResourceType = typeof(Resources.AgendaEvent))]
public int? SeatingCapacity { get; set; }
[Display(Name = "ExpectedSeatingCapacity", ResourceType = typeof(Resources.AgendaEvent))]
public int? ExpectedSeatingCapacity { get; set; }
}
but now I get the error message:
Operator '??' cannot be applied to operands of type 'bool' and 'System.DateTime'
thank you
Oke, I have it now like this:
<pre lang="cs">public bool IsOverlapping(AgendaEventViewModel viewModel, AgendaEventViewModel newEvent)
{
bool isOverlapping = false;
DateTime? begin = DateTime.Parse(viewModel.start);
DateTime? end = DateTime.Parse(viewModel.end);
DateTime? begin2 = DateTime.Parse(newEvent.start);
DateTime? end2 = DateTime.Parse(newEvent.end);
if (begin == begin2)
{
this.ShowMessage(Message.Type.Info, Resources.AgendaEvent.IsOverlapping);
isOverlapping = true;
}
return isOverlapping;
}
But If I now add a second calenderItem then everytime, even on a other day it hits every time:
<pre lang="cs">this.ShowMessage(Message.Type.Info, Resources.AgendaEvent.IsOverlapping);
isOverlapping = true;
Thank you
It seems that begin will become the same as begin2.