search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Different calledar for users

Asked by Peter
4 years ago.

Hi, i'm creating an aplication ASP.Net MVC and in my aplication every user has his own profile and I would like to add calendar to user profile(differend caledar for every user). I've got DB with (ID,Start,End,Text and UserID) and I would like to pass to view only that events for userID. How cand i do that?

Answer posted by Dan Letecky [DayPilot]
4 years ago.

You can access the Controller using "Controller" property from within the Dpc class. Given that the user id is available as User.Identity.Name you can use something like this to filter the events:

protected override void OnFinish()
{
    if (UpdateType == CallBackUpdateType.None)
    {
        return;
    }

    Events = from ev in db.Calendars where ev.UserID == Controller.User.Identity.Name select ev;

    DataIdField = "ID";
    DataTextField = "Text";
    DataStartField = "Start";
    DataEndField = "End";
}

Note that in real-world scenarios you will also want to limit the selected events by the visible range:

protected override void OnFinish()
{
    if (UpdateType == CallBackUpdateType.None)
    {
        return;
    }

    Events = from ev in db.Calendars where ev.UserID == Controller.User.Identity.Name && !((e.End <= VisibleStart) || (e.Start >= VisibleEnd))select ev;

    DataIdField = "ID";
    DataTextField = "Text";
    DataStartField = "Start";
    DataEndField = "End";
}

Note that VisibleStart and VisibleEnd properties are available since version 8.2.5836 (in previous version you can use StartDate and StartDate.AddDays(Days) instead).

See also the latest version of the MVC5 Event Calendar tutorial:
https://code.daypilot.org/59860/asp-net-mvc-5-event-calendar

This question is more than 3 months old and has been closed. Please create a new question if you have anything to add.