public static object AjaxHandler() { JavaScriptSerializer serializer = new JavaScriptSerializer(); using (var client = new StudentTrackerService.StudentsManagerClient()) { var output = serializer.Serialize(client.GetStudents()); return output; } }
protected void ApplyColours(object sender, EventArgs e) { if (System.Web.HttpContext.Current.User != null) { var currentUserId = User.Identity.GetUserId(); string bgColour = bgColorTxt.Text; string hdColour = hdColorTxt.Text; using (var client = new StudentTrackerService.StudentsManagerClient()) { client.SetUiColours(currentUserId, bgColour, hdColour); } Response.Redirect("~/UiConfiguration.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { if (System.Web.HttpContext.Current.User == null || !System.Web.HttpContext.Current.User.Identity.IsAuthenticated) { Response.Redirect("~/Account/Register"); } if (!IsPostBack) { string bgColour = "#ffffff"; string hdColour = "#101010"; if (System.Web.HttpContext.Current.User != null) { var currentUserId = User.Identity.GetUserId(); using (var client = new StudentTrackerService.StudentsManagerClient()) { var settings = client.GetUiColours(currentUserId); bgColour = settings.BackgroundColour; hdColour = settings.HeaderColour; } } bgColorTxt.Text = bgColour; hdColorTxt.Text = hdColour; } }
protected void LoadFile(object sender, EventArgs e) { RawStudentInfo[] rawStudents = new RawStudentInfo[] { }; RawStudentInfo[] validStudents = new RawStudentInfo[] { }; StudentTrackerService.InvalidRecord[] invalidRecords = new StudentTrackerService.InvalidRecord[] { }; string path = String.Empty; if (FileUploadControl.HasFile && (Path.GetExtension(FileUploadControl.FileName) == ".xlsx" || Path.GetExtension(FileUploadControl.FileName) == ".xls")) { try { ExcelFileParser parser = new ExcelFileParser(FileUploadControl.PostedFile.InputStream); List<RawStudentInfo> rawStudentsInforamtion = new List<RawStudentInfo>(); foreach (var record in parser.StudentsRowInformation) { rawStudentsInforamtion.Add(new RawStudentInfo { FirstName = record.FirstName, LastName = record.LastName, Age = record.Age, Sex = record.Sex }); } rawStudents = rawStudentsInforamtion.ToArray(); using (var client = new StudentsManagerClient()) { ExcelDocumentImportResult result = client.GetRecords(rawStudents, System.Threading.Thread.CurrentThread.CurrentCulture.Name); validStudents = result.ValidRecords; invalidRecords = result.InvalidRecords; } StatusLabel.Text = LocalizedText.UploadStatusSuccess; } catch (Exception) { StatusLabel.Text = LocalizedText.UploadedStatusFailed; } finally { UploadedStudents.DataSource = validStudents; UploadedStudents.DataBind(); if (invalidRecords.Any()) { InvalidRecords.DataSource = invalidRecords; InvalidRecords.DataBind(); InvalidGridPannel.Visible = true; } else { InvalidRecords.DataSource = null; InvalidRecords.DataBind(); InvalidGridPannel.Visible = false; } GridPannel.Visible = true; if (validStudents.Any()) { using (StudentTrackerService.StudentsManagerClient client = new StudentTrackerService.StudentsManagerClient()) { client.SaveStudents(validStudents); } } } } else { StatusLabel.Text = LocalizedText.UploadStatusWrongFormat; } StatusLabel.Visible = true; }