예제 #1
0
        public async Task <IActionResult> Get(int month, int year)
        {
            List <EventModel>  events;
            List <GroupModel>  groups;
            List <DateTime>    scheduledDates = null;
            List <DateTime>    absenceDates   = null;
            CalendarRepository repo           = new CalendarRepository(configModel.ConnectionString);
            //int month;
            //int year;

            var user = await userManager.GetUserAsync(User);

            // If a month was not specified, use the current month
            if (month == 0 || month > 12)
            {
                month = DateTime.Now.Month;
            }
            if (year == 0)
            {
                year = DateTime.Now.Year;
            }

            try
            {
                events = repo.GetEvents(month, year);
                groups = repo.GetGroups(month, year);
                if (user != null && (User.IsInRole(UserHelpers.UserRoles.Volunteer.ToString()) || User.IsInRole(UserHelpers.UserRoles.VolunteerCaptain.ToString())))
                {
                    scheduledDates = repo.GetScheduledDates(user.VolunteerId, month, year);
                }
                if (user != null)
                {
                    absenceDates = repo.GetAbsenceDates(user.VolunteerId, month, year);
                }
            }
            catch (Exception e)
            {
                return(Utilities.ErrorJson(e.Message));
            }

            return(new JsonResult(new {
                Groups = groups,
                Events = events,
                ScheduledDates = scheduledDates,
                AbsenceDates = absenceDates,
                Error = ""
            }));
        }