public GradesViewModel DemoPost(GradesViewModel vm) { try { ProjectTokenHelper.CheckValidAccessToken(vm.spHostURL, vm.accessToken); using (ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(vm.spHostURL, vm.accessToken)) { //vm.Grade.CourseTitle = "API Response: " + vm.Grade.CourseTitle; //vm.Grade.Passed = "API Response: " + vm.Grade.Passed; // The SharePoint web site contains a list called "Student Gradebook" - grab and store it in a List variable. // Linking to the list, like finding a table in a database List studentGradebook = clientContext.Web.Lists.GetByTitle("Student Gradebook"); // Create the list item, and set the property value. ListItemCreationInformation itemCreationInfo = new ListItemCreationInformation(); ListItem newItem = studentGradebook.AddItem(itemCreationInfo); newItem["Title"] = vm.Grade.CourseTitle; newItem["Result"] = vm.Grade.Passed; newItem.Update(); clientContext.ExecuteQuery(); } } catch (Exception) { } return(vm); }
public IHttpActionResult DemoPost(GradesViewModel vm) { SampleBL sampleBL = new SampleBL(); vm = sampleBL.DemoPost(vm); return(Ok(vm)); }
[HttpPost] // ... and change this to [HttpGet] public GradesViewModel SampleGetMyLogin(GradesViewModel vm) { SampleBL sampleBL = new SampleBL(); vm = sampleBL.GetMyLogin(vm); return(vm); }
public ActionResult ShowSecondSemesterGrades(int class_id, int?subject_id) { var grades = GradesRepository.GetGrades(this.CurrentUser.Class_id, subject_id); foreach (var grade in grades) { grade.Grades = new string[7]; grade.Grades[0] = String.Join(",", grade.GradesArray.Where(g => g.Month == 2).Select(g => g.Grade).ToArray()); grade.Grades[1] = String.Join(",", grade.GradesArray.Where(g => g.Month == 3).Select(g => g.Grade).ToArray()); grade.Grades[2] = String.Join(",", grade.GradesArray.Where(g => g.Month == 4).Select(g => g.Grade).ToArray()); grade.Grades[3] = String.Join(",", grade.GradesArray.Where(g => g.Month == 5).Select(g => g.Grade).ToArray()); grade.Grades[4] = String.Join(",", grade.GradesArray.Where(g => g.Month == 6).Select(g => g.Grade).ToArray()); grade.Grades[5] = String.Join(",", grade.GradesArray.Where(g => g.Month == 22).Select(g => g.Grade).ToArray()); grade.Grades[6] = String.Join(",", grade.GradesArray.Where(g => g.Month == 23).Select(g => g.Grade).ToArray()); } var vm = new GradesViewModel() { Students = grades, Subject_id = subject_id, Semester = 2 }; return(View("SecondSemesterGrades", vm)); }
public ActionResult Show(int?semester, int?id) { if (semester == null) { var subjects = ScheduleRepository.GetAllSchedule(this.CurrentUser.Class_id); var s1 = SubjectsRepository.GetSubjectsByClassAndSemester(this.CurrentUser.Class_id, 1); var s2 = SubjectsRepository.GetSubjectsByClassAndSemester(this.CurrentUser.Class_id, 2); var allSubjects = SubjectsRepository.GetAllSubjects(); var vm = new GradesViewModel() { Semester1 = s1, Semester2 = s2, AllSubjects = allSubjects }; return(View(vm)); } else if (semester == 1) { return(ShowFirstSemesterGrades(1, id)); } else { return(ShowSecondSemesterGrades(2, id)); } return(View()); }
public ActionResult ChangeGrades(GradesViewModel vm) { if (Request.Form["btnSave"] != null) { var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext); SampleProcess sampleProcess = new SampleProcess(); vm.spHostURL = spContext.SPHostUrl.AbsoluteUri; vm.accessToken = spContext.UserAccessTokenForSPHost; sampleProcess.SamplePost(vm); return(View(sampleProcess.GetSampleGetMyLogin(vm))); } else { var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext); TokenModel tokenModel = new TokenModel(); vm.spHostURL = spContext.SPHostUrl.AbsoluteUri; vm.accessToken = spContext.UserAccessTokenForSPHost; SampleProcess sampleProcess = new SampleProcess(); /*string name = */ //sampleProcess.GetSampleGetMyLogin(vm); //iewBag.Name = name; //return View(vm); return(View(sampleProcess.GetSampleGetMyLogin(vm))); } }
public ActionResult SaveGrades(GradesViewModel vm) { try { GradesRepository.AddGradesToDB(vm.Students, vm.Semester, vm.Subject_id.Value); TempData["success"] = "1"; } catch (Exception ex) { TempData["success"] = "0"; } return(RedirectToAction("Show", new { semester = vm.Semester, id = vm.Subject_id })); }
/// <summary> /// Gets the view model for a grade. /// </summary> /// <param name="grade">The grade.</param> /// <returns></returns> /// <exception cref="CustomException"></exception> public GradesViewModel GetViewModel(Grades grade) { try { GradesViewModel gvm = new GradesViewModel(); gvm.Gradedatetime = grade.Gradedatetime; gvm.GradeId = grade.GradeId; gvm.GradeValue = grade.GradeValue; return(gvm); } catch (Exception ex) { throw new CustomException(ex.Message); } }
public ActionResult Index(GradesViewModel vm) { var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext); SampleProcess sampleProcess = new SampleProcess(); vm.Grade.CourseTitle = "GGG6666 Good Games Galore"; vm.Grade.Passed = "Fail"; vm.spHostURL = spContext.SPHostUrl.AbsoluteUri; vm.accessToken = spContext.UserAccessTokenForSPHost; vm = sampleProcess.SamplePost(vm); return(View(vm)); }
public GradesViewModel SamplePost(GradesViewModel vm) { var client = new RestClient(ConstantHelper.AppSetting.APIUrl); // client.Authenticator = new HttpBasicAuthenticator(username, password); RestRequest request = new RestRequest(ConstantHelper.APIRoute.Sample_DemoPost, Method.POST); request.RequestFormat = DataFormat.Json; request.AddBody(vm); IRestResponse <GradesViewModel> response = client.Execute <GradesViewModel>(request); vm = response.Data; return(vm); }
public GradesViewModel GetSampleGetMyLogin(GradesViewModel vm) { var client = new RestClient(ConstantHelper.AppSetting.APIUrl); // Here a large amount of data is obtained i.e. list, so Method.POST is used. // With a smaller amount of data being fetched, use Method.GET, and remove request.AddBody(vm) // as it is not permitted. // Next, move to the API corresponding method in the ApiController... RestRequest request = new RestRequest(ConstantHelper.APIRoute.Sample_GetMyLogin, Method.POST); request.RequestFormat = DataFormat.Json; request.AddBody(vm); IRestResponse <GradesViewModel> response = client.Execute <GradesViewModel>(request); vm = response.Data; return(vm); }
public ActionResult ChangeGrades(GradesViewModel vm) { User spUser = null; var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext); using (var clientContext = spContext.CreateUserClientContextForSPHost()) { if (clientContext != null) { spUser = clientContext.Web.CurrentUser; clientContext.Load(spUser, user => user.Title); clientContext.ExecuteQuery(); ViewBag.UserName = spUser.Title; } // The SharePoint web site contains a list called "Student Gradebook" - grab and store it in a List variable. // Linking to the list, like finding a table in a database List studentGradebook = clientContext.Web.Lists.GetByTitle("Student Gradebook"); if (Request.Form["btnSave"] != null) { if (ModelState.IsValid) { // Create the list item, and set the property value. ListItemCreationInformation itemCreationInfo = new ListItemCreationInformation(); ListItem newItem = studentGradebook.AddItem(itemCreationInfo); newItem["Title"] = vm.Grade.CourseTitle; newItem["Result"] = vm.Grade.Passed; newItem.Update(); clientContext.ExecuteQuery(); return(RedirectToAction("ChangeGrades", "Grades", new { SPHostUrl = "https://agtivconsulting1.sharepoint.com/sites/trainingsite/SzunK/TrainingDay4/" })); } } } return(View(vm)); }
/// <summary> /// コンストラクタ /// </summary> public GradesPage() { InitializeComponent(); BindingContext = _viewModel = new GradesViewModel(); }
public ActionResult ChangeGrades() { // The following code does not work - use the default code that comes with HomeController. There // seems to be an issue with the ClientContext object. //// Start with ClientContext - the constructor requires a URL to the server running SharePoint. //// This opens Context to the web, in a similar way to opening a connection to a database. //// Copy the URL of the website the Add-In is linked to. //ClientContext context = new ClientContext("https://agtivcaonsulting1.sharepoint.com/sites/trainingsite/SzunK/TrainingDay4/"); User spUser = null; var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext); GradesViewModel vm = new GradesViewModel(); using (var clientContext = spContext.CreateUserClientContextForSPHost()) { if (clientContext != null) { spUser = clientContext.Web.CurrentUser; clientContext.Load(spUser, user => user.Title); clientContext.ExecuteQuery(); ViewBag.UserName = spUser.Title; } // The SharePoint web site contains a list called "Student Gradebook" - grab and store it in a List variable. // Linking to the list, like finding a table in a database List studentGradebook = clientContext.Web.Lists.GetByTitle("Student Gradebook"); // CAML = Collaborative Application Markup Language // Query allows you to query for specific items from a list, using the ViewXml property. // Using CamlQuery.CreateAllItemsQuery() creates a query that retrieves all list items. CamlQuery query = CamlQuery.CreateAllItemsQuery(); // This line grabs items from the studentGradebook List object based on the specified query, and // stores them all in a ListItemCollection object. ListItemCollection studentGradebookCollection = studentGradebook.GetItems(query); // This line ties the ListItemCollection to the ClientContext object, providing a line of communication // between the program and the SharePoint server. Without this line, the items queried for will // not be retrieved from SharePoint. clientContext.Load(studentGradebookCollection); // Call ExecuteQuery() to perform the query, loading the specified items from SharePoint. clientContext.ExecuteQuery(); foreach (ListItem grade in studentGradebookCollection) { string courseTitle = (string)grade["Title"]; string passed = (string)grade["Result"]; vm.GradeBook.Add(new Grade(courseTitle, passed)); } // Call ExecuteQuery to commit changes made to the list. clientContext.ExecuteQuery(); } // Changing display ResultColour of Grade Passed string // This is done in the controller because it has direct access to the GradeBook List of Grade objects. foreach (Grade grade in vm.GradeBook) { grade.ResultColor = grade.Passed.ToLower() == "pass" ? "color:Green" : "color:Red"; } // Logic done here // Check for click of Save button, and execute whatever is required (aka copy from slides and notebook) // You might need to make [HttpGet] and [HttpPost] attributed methods // Upon obtaining the list, remember to update the colour of the text // Might also need to populate a local list based on data obtained from controller // Need to have both read and write functionality. // Pass the View Model object into the View. Why must this be done? return(View(vm)); }
public GradesViewModel GetMyLogin(GradesViewModel vm) { //TokenModel result = new TokenModel(); try { ProjectTokenHelper.CheckValidAccessToken(vm.spHostURL, vm.accessToken); using (ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(vm.spHostURL, vm.accessToken)) { User spUser = clientContext.Web.CurrentUser; clientContext.Load(spUser, user => user.Title); clientContext.ExecuteQuery(); //result.Name = spUser.Title; // The SharePoint web site contains a list called "Student Gradebook" - grab and store it in a List variable. // Linking to the list, like finding a table in a database List studentGradebook = clientContext.Web.Lists.GetByTitle("Student Gradebook"); // CAML = Collaborative Application Markup Language // Query allows you to query for specific items from a list, using the ViewXml property. // Using CamlQuery.CreateAllItemsQuery() creates a query that retrieves all list items. CamlQuery query = CamlQuery.CreateAllItemsQuery(); // This line grabs items from the studentGradebook List object based on the specified query, and // stores them all in a ListItemCollection object. ListItemCollection studentGradebookCollection = studentGradebook.GetItems(query); // This line ties the ListItemCollection to the ClientContext object, providing a line of communication // between the program and the SharePoint server. Without this line, the items queried for will // not be retrieved from SharePoint. clientContext.Load(studentGradebookCollection); // Call ExecuteQuery() to perform the query, loading the specified items from SharePoint. clientContext.ExecuteQuery(); //GradesViewModel gradesViewModel = new GradesViewModel(); foreach (ListItem grade in studentGradebookCollection) { string courseTitle = (string)grade["Title"]; string passed = (string)grade["Result"]; vm.GradeBook.Add(new Grade(courseTitle, passed)); } // Call ExecuteQuery to commit changes made to the list. clientContext.ExecuteQuery(); // Changing display ResultColour of Grade Passed string // This is done in the controller because it has direct access to the GradeBook List of Grade objects. foreach (Grade grade in vm.GradeBook) { grade.ResultColor = grade.Passed.ToLower() == "pass" ? "color:Green" : "color:Red"; } } } catch (Exception) { } return(vm); }