/* C# initializer helper
             * private BellSchedule _model = new BellSchedule
             *  {
             *      BellScheduleName = "ScheduleName",
             *      BellScheduleMeetingTimes = new[]
             *      {
             *          new BellScheduleMeetingTime
             *          {
             *              ClassPeriodReference = new BellScheduleMeetingTimeToClassPeriodReference
             *              {
             *                  ClassPeriodName = "ABC"
             *              },
             *              StartTime = DateTime.Now.TimeOfDay,
             *              EndTime = new TimeSpan(1, 0, 0),
             *          }
             *      },
             *      CalendarDateReference = new CalendarDateReference
             *      {
             *          Date = DateTime.Now,
             *          EducationOrganizationId = 1,
             *      },
             *      SchoolReference = new SchoolReference
             *      {
             *          SchoolId = 10
             *      },
             *      GradeLevelDescriptor = "A",
             *  };
             */

            protected override void Act()
            {
                const string json = @"
{
    'calendarDateReference' : {
        'Date' : '2000-01-01',
        'schoolId' : 1,
    },
    'schoolReference' : {
        'schoolId' : 10
    },
    'gradeLevelDescriptor' : 'A',
    'name' : 'ScheduleName',
    'classPeriods' : [
        {
            'classPeriodReference' : {
                'classPeriodName' : 'ABC',
                'schoolId' : 10,
            }
        }
    ],
}
";

                _model = JsonConvert.DeserializeObject <BellSchedule>(json);
            }
        /// <summary>
        /// Updates or creates a resource based on the resource identifier. The PUT operation is used to update or create a resource by identifier.  If the resource doesn't exist, the resource will be created using that identifier.  Additionally, natural key values cannot be changed using this operation, and will not be modified in the database.  If the resource &quot;id&quot; is provided in the JSON body, it will be ignored as well.
        /// </summary>
        /// <param name="id">A resource identifier specifying the resource to be updated.</param>
        /// <param name="IfMatch">The ETag header value used to prevent the PUT from updating a resource modified by another consumer.</param>
        /// <param name="body">The JSON representation of the &quot;bellSchedule&quot; resource to be updated.</param>
        /// <returns>A RestSharp <see cref="IRestResponse"/> instance containing the API response details.</returns>
        public IRestResponse PutBellSchedule(string id, string IfMatch, BellSchedule body)
        {
            var request = new RestRequest("/bellSchedules/{id}", Method.PUT);

            request.RequestFormat = DataFormat.Json;

            request.AddUrlSegment("id", id);
            // verify required params are set
            if (id == null || body == null)
            {
                throw new ArgumentException("API method call is missing required parameters");
            }
            request.AddHeader("If-Match", IfMatch);
            request.AddBody(body);
            request.Parameters.First(param => param.Type == ParameterType.RequestBody).Name = "application/json";
            var response = client.Execute(request);

            var location = response.Headers.FirstOrDefault(x => x.Name == "Location");

            if (location != null && !string.IsNullOrWhiteSpace(location.Value.ToString()))
            {
                body.id = location.Value.ToString().Split('/').Last();
            }
            return(response);
        }
示例#3
0
        /// <summary>
        /// Creates or updates resources based on the natural key values of the supplied resource. The POST operation can be used to create or update resources. In database terms, this is often referred to as an &quot;upsert&quot; operation (insert + update).  Clients should NOT include the resource &quot;id&quot; in the JSON body because it will result in an error (you must use a PUT operation to update a resource by &quot;id&quot;). The web service will identify whether the resource already exists based on the natural key values provided, and update or create the resource appropriately.
        /// </summary>
        /// <param name="body">The JSON representation of the &quot;bellSchedule&quot; resource to be created or updated.</param>
        /// <returns>A RestSharp <see cref="IRestResponse"/> instance containing the API response details.</returns>
        public IRestResponse PostBellSchedules(BellSchedule body)
        {
            var request = new RestRequest("/bellSchedules", Method.POST);

            request.RequestFormat = DataFormat.Json;

            // verify required params are set
            if (body == null)
            {
                throw new ArgumentException("API method call is missing required parameters");
            }
            request.AddBody(body);
            var response = client.Execute(request);

            var location = response.Headers.FirstOrDefault(x => x.Name == "Location");

            if (location != null && !string.IsNullOrWhiteSpace(location.Value.ToString()))
            {
                body.id = location.Value.ToString().Split('/').Last();
            }
            return(response);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.BellSchedule);

            Spinner daySpinner = FindViewById <Spinner>(Resource.Id.daySpinner);

            table = FindViewById <TableLayout>(Resource.Id.scheduleTable);

            //Set up spacing and alignment for text in table
            for (int i = 0; i < table.ChildCount; i++)
            {
                TableRow row = (TableRow)table.GetChildAt(i);
                //15 px above and below each row
                row.SetPadding(0, 15, 0, 15);

                //Center everything in the row
                for (int j = 0; j < 3; j++)
                {
                    ((TextView)row.GetChildAt(j)).Gravity = GravityFlags.CenterHorizontal;
                }
            }

            daySpinner.Adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerItem, BellSchedule.days.Keys.ToArray());

            //Set advisory for Wednesday
            if (DateTime.Now.DayOfWeek == DayOfWeek.Wednesday)
            {
                daySpinner.SetSelection(1);
            }
            else
            {
                daySpinner.SetSelection(0);
            }

            daySpinner.ItemSelected += (object sender, Spinner.ItemSelectedEventArgs e) =>
            {
                FindViewById <TextView>(Resource.Id.titleText).Text = "Today is " + MainActivity.aOrAn(daySpinner.SelectedItem.ToString());

                //Get formated list of period start and end times
                List <Period> periods = BellSchedule.getSchedule(daySpinner.SelectedItem.ToString());

                for (int i = 0; i < table.ChildCount - 1; i++)
                {
                    TableRow row = (TableRow)table.GetChildAt(i + 1);

                    //Set text to times, or clear if extra rows are not needed
                    if (i < periods.Count)
                    {
                        ((TextView)row.GetChildAt(0)).Text = periods[i].Name;
                        ((TextView)row.GetChildAt(1)).Text = periods[i].startTime;
                        ((TextView)row.GetChildAt(2)).Text = periods[i].endTime;

                        //Highlight current period
                        if (DateTime.Now > DateTime.Parse(periods[i].startTime) && DateTime.Now < DateTime.Parse(periods[i].endTime))
                        {
                            row.SetBackgroundColor(Color.Navy);
                        }
                        else
                        {
                            row.SetBackgroundColor(Color.Transparent);
                        }
                    }
                    else
                    {
                        for (int j = 0; j < 3; j++)
                        {
                            ((TextView)row.GetChildAt(j)).Text = "";
                        }
                    }
                }
            };
        }