Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using System.Text;
  5. using ExcercisesDAL;
  6.  
  7. namespace ExercisesViewModels
  8. {
  9. public class GradeViewModel
  10. {
  11. private GradeModel _model;
  12. public int Id { get; set; }
  13. public int StudentId { get; set; }
  14. public int CourseId { get; set; }
  15. public int Mark { get; set; }
  16. public string Comments { get; set; }
  17. public string Timer { get; set; }
  18.  
  19.  
  20.  
  21. //constructor
  22.  
  23. public GradeViewModel()
  24. {
  25. _model = new GradeModel();
  26. }
  27.  
  28.  
  29. //methods
  30. public List<GradeViewModel> GetAll(int id)
  31. {
  32. List<GradeViewModel> allVms = new List<GradeViewModel>();
  33.  
  34. try
  35. {
  36. List<Grades> allGrades = _model.GetAllGrades(id);
  37. foreach (Grades grd in allGrades)
  38. {
  39. GradeViewModel grdVm = new GradeViewModel();
  40. grdVm.Id = grd.Id;
  41. grdVm.Mark = grd.Mark;
  42. grdVm.StudentId = grd.StudentId;
  43. grdVm.CourseId = grd.CourseId;
  44. grdVm.Comments = grd.Comments;
  45. grdVm.Timer = Convert.ToBase64String(grd.Timer);
  46. allVms.Add(grdVm);
  47. }
  48. }
  49. catch (Exception ex)
  50. {
  51. Console.Write("Problem in " + GetType().Name + " " +
  52. MethodBase.GetCurrentMethod().Name + " " + ex.Message);
  53. throw ex;
  54. }
  55. return allVms;
  56. }
  57.  
  58.  
  59. public int Update()
  60. {
  61. UpdateStatus gradesUpdated = UpdateStatus.Failed;
  62. try
  63. {
  64. Grades grd = new Grades();
  65. grd.Id = Id;
  66. grd.StudentId = StudentId;
  67. grd.CourseId = CourseId;
  68. grd.Mark = Mark;
  69. grd.Comments = Comments;
  70. grd.Timer = Convert.FromBase64String(Timer);
  71. gradesUpdated = _model.Update(grd);
  72. }
  73. catch (Exception ex)
  74. {
  75. Console.Write("Problem in " + GetType().Name + " " +
  76. MethodBase.GetCurrentMethod().Name + " " + ex.Message);
  77. throw ex;
  78. }
  79. return Convert.ToInt16(gradesUpdated);
  80. }
  81.  
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement