コード例 #1
0
        public HttpResponseMessage Get()
        {
            if (!_orchardServices.Authorizer.Authorize(Permissions.ivMemberTab))
                return Request.CreateResponse(HttpStatusCode.Forbidden);

            var availability = new AvailabilityModel();
            tidyCalendar(availability);
            _fixtureServices.AddPlayerAvailabilty(availability);
            return Request.CreateResponse(HttpStatusCode.OK, availability, new MediaTypeHeaderValue("application/json"));
        }
コード例 #2
0
 private void tidyCalendar(AvailabilityModel availability)
 {
     foreach (var month in availability.Months)
     {
         for (var i = 0; i < maxDays(availability); i++)
         {                    
             if (month.Days.Count <= i)
                 month.Days.Add(new AvailabilityModel.Day{Date = string.Empty});
         }
     }
 }
コード例 #3
0
        public void AddPlayerAvailabilty(AvailabilityModel availabilityModel)
        {
            var member = _memberServices.GetMemberByUserId(CurrentUser.Id);
            if (member == null) return;
            var player = _playerServices.GetPlayerByName(member.Lastname, member.Firstname);
            if (player == null) return;

            availabilityModel.PlayerId = player.Id;

            var availabilityList = GetPlayerAvailability(player.Id);
            foreach (var availability in availabilityList)
            {
                foreach (var month in availabilityModel.Months)
                {
                    foreach (var day in month.Days)
                    {
                        if (string.IsNullOrEmpty(day.Date)) continue;

                        var availableDate =
                            new DateTime(DateTime.Now.Year,
                                Array.IndexOf(_months, month.Name) + 1,
                                Convert.ToInt32(day.Date));

                        if (availability.Date == availableDate)
                            day.Available = true;
                    }
                }
            }

        }
コード例 #4
0
 private int maxDays(AvailabilityModel availability)
 {
     return availability.Months.Select(month => month.Days.Count).Concat(new[] {0}).Max();
 }