public void Controller_Student_Update_Post_Id_Is_Null_Or_Empty_Should_Send_Back_For_Edit() { // Arrange StudentController controller = new StudentController(); StudentDisplayViewModel dataNull = new StudentDisplayViewModel(); StudentDisplayViewModel dataEmpty = new StudentDisplayViewModel(); // Make data.Id = null dataNull.Id = null; // Make data.Id empty dataEmpty.Id = ""; var context = CreateMoqSetupForCookie(); controller.ControllerContext = new ControllerContext(context, new RouteData(), controller); // Act var resultNull = (ViewResult)controller.Update(dataNull); var resultEmpty = (ViewResult)controller.Update(dataEmpty); // Assert Assert.IsNotNull(resultNull, TestContext.TestName); Assert.IsNotNull(resultEmpty, TestContext.TestName); }
public ActionResult Delete([Bind(Include = "Id," + "Name," + "LastName," + "Email," + "PictureId," + "Uri," + "")] StudentDisplayViewModel data) { if (!ModelState.IsValid) { // Send back for edit return(View(data)); } if (data == null) { // Send to Error page return(RedirectToAction("Error", new { route = "Home", action = "Error" })); } if (string.IsNullOrEmpty(data.Id)) { // Send back for Edit return(View(data)); } StudentBackend.Delete(data.Id); return(RedirectToAction("Students")); }
public ActionResult Update([Bind(Include = "Id," + "Name," + "Description," + "Uri," + "AvatarId," + "AvatarLevel," + "Tokens," + "Status," + "")] StudentDisplayViewModel data) { if (!ModelState.IsValid) { // Send back for edit return(View(data)); } if (data == null) { // Send to Error Page return(RedirectToAction("Error", new { route = "Home", action = "Error" })); } if (string.IsNullOrEmpty(data.Id)) { // Send back for edit return(View(data)); } var myDataStudent = new StudentModel(data); StudentBackend.Update(myDataStudent); return(RedirectToAction("Index")); }
public ActionResult Delete([Bind(Include = "Id," + "Name," + "Description," + "AvatarId," + "Uri," + "Status," + "Tokens," + "ExperiencePoints," + "AvatarLevel," + "")] StudentDisplayViewModel data) { if (!ModelState.IsValid) { // Send back for edit return(View(data)); } if (data == null) { // Send to Error page return(RedirectToAction("Error", new { route = "Home", action = "Error" })); } if (string.IsNullOrEmpty(data.Id)) { // Send back for Edit return(View(data)); } StudentBackend.Delete(data.Id); return(RedirectToAction("Index")); }
/// <summary> /// My Settings /// </summary> /// <param name="id">Student Id</param> /// <returns>Student Record as a Student View Model</returns> // GET: Portal public ActionResult Settings(string id = null) { // Temp hold the Student Id for the Nav, until the Nav can call for Identity. //ViewBag.StudentId = id; var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext); // Todo: Remove when identity is fully hooked up // Hack, to keep the current system working, while the identity system is slowly hooked up everywhere. If the user is not logged in, then the passed in user will work, if the user is logged in, then the passed in user is ignored. if (string.IsNullOrEmpty(CurrentId)) { CurrentId = id; } ViewBag.StudentId = CurrentId; //TODO: Remove this when identity is fully hooked up if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.StudentUser)) { return(RedirectToAction("Roster", "Portal")); } var myStudent = DataSourceBackend.Instance.StudentBackend.Read(CurrentId); if (myStudent == null) { return(RedirectToAction("Error", "Home")); } var myReturn = new StudentDisplayViewModel(myStudent); return(View(myReturn)); }
/// <summary> /// Read information on a single Student /// </summary> /// <param name="id"></param> /// <returns></returns> // GET: Student/Details/5 public ActionResult Read(string id = null) { var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext); if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.TeacherUser)) { return(RedirectToAction("Login", "Admin")); } var myDataStudent = DataSourceBackend.Instance.StudentBackend.Read(id); if (myDataStudent == null) { return(RedirectToAction("Error", "Home")); } var myData = new StudentDisplayViewModel(myDataStudent); // null not possible //if (myData == null) //{ // return RedirectToAction("Error", "Home"); //} return(View(myData)); }
public ActionResult Delete([Bind(Include = "Id," + "Name," + "Description," + "AvatarId," + "Uri," + "")] StudentDisplayViewModel data) { try { if (ModelState.IsValid) { if (data == null) { return(RedirectToAction("Error", new { route = "Home", action = "Error" })); } if (string.IsNullOrEmpty(data.Id)) { return(View(data)); } StudentBackend.Delete(data.Id); return(RedirectToAction("Index")); } // Send back for edit return(View(data)); } catch { return(RedirectToAction("Error", new { route = "Home", action = "Error" })); } }
public void Models_StudentDisplayViewModel_Default_Instantiate_Should_Pass() { // Act var result = new StudentDisplayViewModel(); // Assert Assert.IsNotNull(result, TestContext.TestName); }
public ActionResult Login([Bind(Include = "Id," + "Name," + "Description," + "Uri," + "AvatarLevel," + "Tokens," + "Status," + "Password," + "ExperiencePoints," + "Password," + "")] StudentDisplayViewModel data) { // Any password is accepted for now. does not really login... if (!ModelState.IsValid) { // Send back for edit, with Error Message return(View(data)); } if (data == null) { // Send to Error Page return(RedirectToAction("Error", "Home")); } if (string.IsNullOrEmpty(data.Id)) { // Send back for Edit return(RedirectToAction("Error", "Home")); } var myStudent = DataSourceBackend.Instance.StudentBackend.Read(data.Id); if (myStudent == null) { // Send to Error Page //return RedirectToAction("Error", "Home"); return(RedirectToAction("Roster", "Portal")); } // When not in testing mode try the password if (!DataSourceBackend.GetTestingMode()) { if (!DataSourceBackend.Instance.IdentityBackend.LogUserIn(myStudent.Name, data.Password, _5051.Models.UserRoleEnum.StudentUser, HttpContext)) { ModelState.AddModelError("", "Invalid password"); var myReturn = new StudentDisplayViewModel(myStudent); return(View(myReturn)); } } // all is OK, so redirect to the student index page and pass in the student ID for now. return(RedirectToAction("Index", "Portal", new { id = data.Id })); }
public void Models_StudentDisplayViewModel_Default_Instantiate_With_Invalid_Data_Null_Should_Fail() { // Arrange // Act var result = new StudentDisplayViewModel(null); // Assert Assert.IsNotNull(result, TestContext.TestName); }
public void Models_StudentDisplayViewModel_Default_Instantiate_Get_Valid_Data_Should_Pass() { // Arrange var result = new StudentDisplayViewModel(); //act var expectLastDateTime = result.LastDateTime; // Assert Assert.AreEqual(expectLastDateTime, result.LastDateTime, TestContext.TestName); }
public void Models_StudentDisplayViewModel_Default_Instantiate_Set_LastDateTime_Should_Pass() { // Arrange var result = new StudentDisplayViewModel(); var expectLastDateTime = DateTime.UtcNow; //act result.LastDateTime = expectLastDateTime; // Assert Assert.AreEqual(expectLastDateTime, result.LastDateTime, TestContext.TestName); }
public void Models_StudentDisplayViewModel_Default_Instantiate_Set_EmotionImgeUri_Should_Pass() { // Arrange var result = new StudentDisplayViewModel(); var expect = "uri"; //act result.EmotionUri = expect; // Assert Assert.AreEqual(expect, result.EmotionUri, TestContext.TestName); }
public ActionResult Update([Bind(Include = "Id," + "Name," + "Tokens," + "Status," + "ExperiencePoints," + "Truck," + "")] StudentDisplayViewModel data) { var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext); if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.TeacherUser)) { return(RedirectToAction("Login", "Admin")); } if (!ModelState.IsValid) { // Send back for edit return(View(data)); } if (data == null) { // Send to Error Page return(RedirectToAction("Error", "Home")); } if (string.IsNullOrEmpty(data.Id)) { // Send back for edit return(View(data)); } var myDataStudent = DataSourceBackend.Instance.StudentBackend.Read(data.Id); myDataStudent.EmotionCurrent = data.EmotionCurrent; //myDataStudent.Name = data.Name; myDataStudent.Tokens = data.Tokens; myDataStudent.Status = data.Status; myDataStudent.ExperiencePoints = data.ExperiencePoints; myDataStudent.Truck.TruckName = data.Truck.TruckName; DataSourceBackend.Instance.StudentBackend.Update(myDataStudent); if (myDataStudent.Name != data.Name) { DataSourceBackend.Instance.IdentityBackend.ChangeUserName(data.Id, data.Name); } return(RedirectToAction("Index")); }
public ActionResult Settings([Bind(Include = "Id," + "Name," + "Description," + "Uri," + "AvatarLevel," + "Tokens," + "Status," + "AvatarUri," + "ExperiencePoints," + "Password," + "")] StudentDisplayViewModel data) { // If data passed up is not valid, go back to the Index page so the user can try again if (!ModelState.IsValid) { // Send back for edit, with Error Message return(View(data)); } // If the Student Id is blank, error out if (string.IsNullOrEmpty(data.Id)) { return(RedirectToAction("Error", "Home")); } // Lookup the student id, will just replace the Avatar Id on it if it is valid var myStudent = DataSourceBackend.Instance.StudentBackend.Read(data.Id); if (myStudent == null) { return(RedirectToAction("Error", "Home")); } ////if the student name already exists in db, if does, return for edits //var idFindResult = IdentityBackend.Instance.FindUserByUserName(data.Name); //if(idFindResult != null) //{ // ModelState.AddModelError("", "User name already taken"); // return View(data); //} // Set the Avatar ID on the Student and update in data store //myStudent.Name = data.Name; //DataSourceBackend.Instance.StudentBackend.Update(myStudent); DataSourceBackend.Instance.IdentityBackend.ChangeUserName(myStudent.Id, data.Name); // Editing is done, so go back to the Student Portal and pass the Student Id return(RedirectToAction("Index", "Portal", new { Id = myStudent.Id })); }
/// <summary> /// The Roster in page for the Portal, shows all the Students /// </summary> /// <returns></returns> // GET: Portal public ActionResult Login(string id = null) { var myStudent = DataSourceBackend.Instance.StudentBackend.Read(id); if (myStudent == null) { return(RedirectToAction("Roster", "Portal")); } var myReturn = new StudentDisplayViewModel(myStudent); return(View(myReturn)); }
/// <summary> /// Index Page /// </summary> /// <param name="id">Student Id</param> /// <returns>Student Record as a Student View Model</returns> // GET: Portal public ActionResult Index(string id = null) { var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext); // Todo: Remove when identity is fully hooked up // Hack, to keep the current system working, while the identity system is slowly hooked up everywhere. If the user is not logged in, then the passed in user will work, if the user is logged in, then the passed in user is ignored. if (string.IsNullOrEmpty(CurrentId)) { CurrentId = id; } ViewBag.StudentId = CurrentId; //TODO: Remove this when identity is fully hooked up if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.StudentUser)) { return(RedirectToAction("Roster", "Portal")); } var myStudent = DataSourceBackend.Instance.StudentBackend.Read(CurrentId); if (myStudent == null) { return(RedirectToAction("Roster", "Portal")); } var myReturn = new StudentDisplayViewModel(myStudent); //Set the last log in time and emotion status img uri if (myReturn.Attendance.Any()) { myReturn.LastLogIn = UTCConversionsBackend.UtcToKioskTime(myReturn.Attendance.OrderByDescending(m => m.In).FirstOrDefault().In); } var myWeeklyReport = new WeeklyReportViewModel() { StudentId = CurrentId, SelectedWeekId = 1 }; var myMonthlyReport = new MonthlyReportViewModel() { StudentId = CurrentId, SelectedMonthId = 1 }; myReturn.WeeklyAttendanceScore = ReportBackend.Instance.GenerateWeeklyReport(myWeeklyReport).Stats.PercAttendedHours; myReturn.MonthlyAttendanceScore = ReportBackend.Instance.GenerateMonthlyReport(myMonthlyReport).Stats.PercAttendedHours; return(View(myReturn)); }
public ActionResult ResetPassword([Bind(Include = "Id," + "Name," + "Description," + "Uri," + "Status," + "Tokens," + "ExperiencePoints," + "AvatarLevel," + "")] StudentDisplayViewModel data) { var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext); if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.TeacherUser)) { return(RedirectToAction("Login", "Admin")); } if (!ModelState.IsValid) { // Send back for edit return(View(data)); } if (data == null) { // Send to Error page return(RedirectToAction("Error", "Home")); } if (string.IsNullOrEmpty(data.Id)) { // Send back for Edit return(View(data)); } var findResult = DataSourceBackend.Instance.IdentityBackend.FindUserByID(data.Id); var student = DataSourceBackend.Instance.StudentBackend.Read(data.Id); var changeResult = DataSourceBackend.Instance.IdentityBackend.ChangeUserPassword(student.Name, "abc", student.Password, _5051.Models.UserRoleEnum.StudentUser); if (!changeResult) { ModelState.AddModelError("", "Password Reset resulted in error."); return(View(data)); } return(RedirectToAction("Index")); }
public ActionResult Settings([Bind(Include = "Id," + "Name," + "Description," + "Uri," + "AvatarId," + "AvatarLevel," + "Tokens," + "Status," + "AvatarUri," + "ExperiencePoints," + "Password," + "")] StudentDisplayViewModel data) { // If data passed up is not valid, go back to the Index page so the user can try again if (!ModelState.IsValid) { // Send back for edit, with Error Message return(View(data)); } // If the Avatar Id is blank, error out if (string.IsNullOrEmpty(data.AvatarId)) { return(RedirectToAction("Error", "Home")); } // If the Student Id is black, error out if (string.IsNullOrEmpty(data.Id)) { return(RedirectToAction("Error", "Home")); } // Lookup the student id, will just replace the Avatar Id on it if it is valid var myStudent = Backend.StudentBackend.Instance.Read(data.Id); if (myStudent == null) { return(RedirectToAction("Error", "Home")); } // Set the Avatar ID on the Student and update in data store myStudent.Name = data.Name; Backend.StudentBackend.Instance.Update(myStudent); // Editing is done, so go back to the Student Portal and pass the Student Id return(RedirectToAction("Index", "Portal", new { Id = myStudent.Id })); }
/// <summary> /// Shows the login confirmation screen /// </summary> /// <param name="id">Student ID</param> /// <returns></returns> public ActionResult ConfirmLogout(string id) { if (string.IsNullOrEmpty(id)) { return(RedirectToAction("Error", "Home")); } var myDataList = StudentBackend.Read(id); var StudentViewModel = new StudentDisplayViewModel(myDataList); //Todo, replace with actual transition time StudentViewModel.LastDateTime = DateTime.Now; return(View(StudentViewModel)); }
public void Models_StudentModel_Instantiate_Valid_Model_Data_Should_Pass() { // Arrange var expect = "test"; var data = new StudentDisplayViewModel { Name = expect }; // Act var result = new StudentModel(data); // Assert Assert.AreEqual(expect, result.Name, TestContext.TestName); }
/// <summary> /// Shows the login confirmation screen /// </summary> /// <param name="id">Student ID</param> /// <returns></returns> public ActionResult ConfirmLogin(string id) { if (string.IsNullOrEmpty(id)) { return(RedirectToAction("Error", "Home")); } var myDataList = DataSourceBackend.Instance.StudentBackend.Read(id); var StudentViewModel = new StudentDisplayViewModel(myDataList) { LastDateTime = UTCConversionsBackend.UtcToKioskTime(DateTimeHelper.Instance.GetDateTimeNowUTC()) }; return(View(StudentViewModel)); }
public void Models_StudentDisplayViewModel_Default_Instantiate_With_Data_Should_Pass() { // Arrange var data = new StudentModel { Id = "hi" }; var expect = "hi"; // Act var returned = new StudentDisplayViewModel(data); var result = returned.Id; // Assert Assert.AreEqual(expect, result, TestContext.TestName); }
/// <summary> /// This will show the details of the Student to update /// </summary> /// <param name="id"></param> /// <returns></returns> // GET: Student/Edit/5 public ActionResult Update(string id = null) { var myDataStudent = StudentBackend.Read(id); if (myDataStudent == null) { return(RedirectToAction("Error", "Home")); } var myData = new StudentDisplayViewModel(myDataStudent); if (myData == null) { return(RedirectToAction("Error", "Home")); } return(View(myData)); }
public void Models_StudentDisplayViewModel_Get_Set_WeeklyAttendanceScore_Should_Pass() { // Arrange var expect = 123; var data = new StudentDisplayViewModel { WeeklyAttendanceScore = expect }; // Act var result = data.WeeklyAttendanceScore; // Reset // Assert Assert.AreEqual(expect, result, TestContext.TestName); }
public void Controller_Student_Update_Post_Default_Should_Return_Index_Page() { // Arrange StudentController controller = new StudentController(); StudentDisplayViewModel data = new StudentDisplayViewModel(DataSourceBackend.Instance.StudentBackend.GetDefault()); var context = CreateMoqSetupForCookie(); controller.ControllerContext = new ControllerContext(context, new RouteData(), controller); // Act RedirectToRouteResult result = controller.Update(data) as RedirectToRouteResult; // Assert Assert.AreEqual("Index", result.RouteValues["action"], TestContext.TestName); }
// GET: Attendance/Read/. Read the attendance history of the student public ActionResult Read(string id) { var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext); if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.TeacherUser)) { return(RedirectToAction("Login", "Admin")); } var myStudent = DataSourceBackend.Instance.StudentBackend.Read(id); if (myStudent == null) { return(RedirectToAction("Error", "Home")); } var myReturn = new StudentDisplayViewModel(myStudent); var attendanceListOrdered = myReturn.Attendance.OrderByDescending(m => m.In); //Deep copy Attendance list and convert time zone var myAttendanceModels = new List <AttendanceModel>(); foreach (var item in attendanceListOrdered) { var myAttendance = new AttendanceModel() { //deep copy the AttendanceModel and convert time zone In = UTCConversionsBackend.UtcToKioskTime(item.In), Out = UTCConversionsBackend.UtcToKioskTime(item.Out), Id = item.Id, StudentId = myStudent.Id, Emotion = item.Emotion, EmotionUri = Emotion.GetEmotionURI(item.Emotion) }; myAttendance.Id = item.Id; myAttendanceModels.Add(myAttendance); } myReturn.Attendance = myAttendanceModels; return(View(myReturn)); }
public ActionResult Login([Bind(Include = "Id," + "Name," + "Description," + "Uri," + "AvatarId," + "AvatarLevel," + "Tokens," + "Status," + "Password," + "ExperiencePoints," + "Password," + "")] StudentDisplayViewModel data) { // Any password is accepted for now. does not really login... if (!ModelState.IsValid) { // Send back for edit, with Error Message return(View(data)); } if (data == null) { // Send to Error Page return(RedirectToAction("Error", "Home")); } if (string.IsNullOrEmpty(data.Id)) { // Send back for Edit return(View(data)); } var myStudent = DataSourceBackend.Instance.StudentBackend.Read(data.Id); if (myStudent == null) { // Send to Error Page return(RedirectToAction("Error", "Home")); } // all is OK, so redirect to the student index page and pass in the student ID for now. return(RedirectToAction("Index", "Portal", new { id = data.Id })); }
/// <summary> /// My Settings /// </summary> /// <param name="id">Student Id</param> /// <returns>Student Record as a Student View Model</returns> // GET: Portal public ActionResult Settings(string id = null) { var myStudent = Backend.StudentBackend.Instance.Read(id); if (myStudent == null) { return(RedirectToAction("Error", "Home")); } var myReturn = new StudentDisplayViewModel(myStudent); if (myReturn == null) { return(RedirectToAction("Error", "Home")); } return(View(myReturn)); }
/// <summary> /// Read information on a single Student /// </summary> /// <param name="id"></param> /// <returns></returns> // GET: Admin/Read/ public ActionResult Read(string id = null) { var myDataStudent = StudentBackend.Read(id); if (myDataStudent == null) { RedirectToAction("Error", "Home", "Invalid Record"); } var myData = new StudentDisplayViewModel(myDataStudent); if (myData == null) { RedirectToAction("Error", "Home", "Invalid Record"); } return(View(myData)); }