public Guid Create(Course course) { IRestRequest request = new RestRequest("/api/course", Method.POST); request.AddParameter("application/json; charset=utf-8", JsonConvert.SerializeObject(course), ParameterType.RequestBody); request.RequestFormat = DataFormat.Json; IRestResponse response = Client.Post(request); Guid guid = Guid.Empty; if (response.StatusCode == System.Net.HttpStatusCode.OK) { Guid.TryParse(Newtonsoft.Json.JsonConvert.DeserializeObject<ApiObjectId>(response.Content).Id, out guid); } else { this.setError(response); } return guid; }
static void UpdateCourse(Guid courseGuid) { ServiceFactory factory = new ServiceFactory(); ICourseService cService = factory.CreateCourseService(); var course = new Course() { CourseGuid = courseGuid, Name = "Test Course Modified " + DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss") }; bool success = cService.Update(course); if (!success) { printError(cService.LastError); } else { Console.WriteLine(string.Format("Name of course {0} was updated to {1}.", courseGuid, course.Name)); } }
static Guid CreateCourse(Guid masterCourseGuid) { ServiceFactory factory = new ServiceFactory(); ICourseService cService = factory.CreateCourseService(); var course = new Course() { Name = "Test Course", Description = "Test course description", CourseDefaultView = AlmsSdk.Domain.Enums.CourseViewType.Card, CourseAllowSelfEnrollment = false, Abbreviation = "TTC", MasterCourseGuid = masterCourseGuid }; Guid courseGuid = cService.Create(course); if (courseGuid == Guid.Empty) { printError(cService.LastError); } else { Console.WriteLine(string.Format("Course {0} was created.", courseGuid)); } return courseGuid; }
public bool Update(Course Course) { IRestRequest request = new RestRequest("/api/course", Method.PUT); request.AddParameter("application/json; charset=utf-8", JsonConvert.SerializeObject(Course), ParameterType.RequestBody); request.RequestFormat = DataFormat.Json; IRestResponse response = Client.Execute(request); if (response.StatusCode == System.Net.HttpStatusCode.OK) return true; else { this.setError(response); return false; } }