public StudentDetails(User user, StudentFormModel model) { UserId = user.Id; Discipline = model.Discipline; CurrentDegree = model.CurrentDegree; CurrentSemester = model.CurrentSemester; }
public void PutStudentTest400() { var model = new StudentFormModel(); _tester.TestControllerWithMockData() .Calling(c => c.PutStudent(model, _tester.Student.Email)) .ShouldReturn() .BadRequest(); }
public IActionResult PutStudent([FromRoute] int id, [FromBody] StudentFormModel model) { if (!_userPermissions.IsAllowedToAdminister(User.Identity.GetUserId())) { return(Forbidden()); } return(PutStudentDetials(id, model)); }
public UserControllerStudentsTest() { _tester = new ControllerTester <UserController>(); StudentFormModel = new StudentFormModel { Discipline = "ABC", CurrentDegree = "XYZ", CurrentSemester = 1 }; }
public void CreateNewStudent(StudentFormModel studentFormModel) { var student = new Student { FirstName = studentFormModel.FirstName, LastName = studentFormModel.LastName, Email = studentFormModel.Email, DOB = studentFormModel.DOB, Password = studentFormModel.Password, Address = studentFormModel.Address }; _studentRepository.RegisterNewStudent(student); }
public void PutStudentDetials(User student, StudentFormModel model) { if (student.StudentDetails == null) { student.StudentDetails = new StudentDetails(student, model); } else { student.StudentDetails.Discipline = model.Discipline; student.StudentDetails.CurrentDegree = model.CurrentDegree; student.StudentDetails.CurrentSemester = model.CurrentSemester; } DbContext.SaveChanges(); }
private IActionResult PutStudentDetials(int id, StudentFormModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var student = _userManager.GeStudentById(id); _userManager.PutStudentDetials(student, model); Logger.LogInformation(42, "Studet with ID: " + id + " updated."); return(Ok()); } catch (InvalidOperationException) { return(NotFound()); } }
public JsonResult Get(long id) { // тут достаём студента var student = this.StudentsService.GetStudentInfoById(id); // отдельно достаём все проекты, // потому что на форме добавления\редактирования нам нужны все проекты\группы var projects = this.ProjectsService.GetAllProjects(); var groups = this.GroupsService.GetAllGroups(); // тут как раз пример того, что в БД инфа лежит в одном виде // но вывести на фронт её нам нужно в другом // в БД лежит таблица с проектами и есть ссылки из таблицы студентов на таблицу с проектами // на фронте же нам нужен список всех проектов, помеченных флагом, есть ли связь между студентом и проектом // кстати, для разных страниц мы можем создавать разные классы для одних и тех же сущностей var studentProjects = projects .Select(project => this.GetStudentProjectModel(project, student)) .ToList(); // аналогично проектам var studentGroups = groups .Select(group => this.GetStudentGroupModel(group, student)) .ToList(); // создаём сущность для отправки на фронт var data = new StudentFormModel { Id = student.Id, LastName = student.LastName, Name = student.Name, Groups = studentGroups, Projects = studentProjects }; // возращаем данные return(this.Json(new { data }, JsonRequestBehavior.AllowGet)); }
public IActionResult SubmitStudentAccount(IFormCollection form) { string firstName = form["firstNameInputUser"]; string lastName = form["lastNameInputUser"]; string gender = form["genderInputUser"]; string dateOfBirth = form["dateOfBirthInputUser"]; string email = form["emailInputUser"]; string address1 = form["address1InputUser"]; string city = form["cityInputUser"]; string country = form["countryInputUser"]; string postCode = form["postCodeInputUser"]; string fullAddress = address1 + " , " + city + " , " + country + " , " + postCode; MockDatabase mockDatabase = new MockDatabase(); mockDatabase.InsertStudentIntoTheDatabase(fullAddress); //var randomPassword = _studentService.CreateRandomPassword(6, true); // Create a default password by hashing the first name var defaultPassword = _loginService.SHA512ComputeHash(firstName); // Service logic var newStudent = new StudentFormModel { FirstName = firstName, LastName = lastName, Email = email, Password = defaultPassword, // gender ??? DOB = Convert.ToDateTime(dateOfBirth), Address = fullAddress }; // Create a new student _studentService.CreateNewStudent(newStudent); return(RedirectToAction("Index", "Home")); }
public IActionResult PutStudent([FromBody] StudentFormModel model, [FromQuery] string identity) { if (identity != null && !_userPermissions.IsAllowedToAdminister(User.Identity)) { return(Forbidden()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var student = _userManager.GetStudentById(identity ?? User.Identity.GetUserIdentity()); _userManager.PutStudentDetials(student, model); Logger.LogInformation(42, "Studet with identity: " + identity + " updated."); return(Ok()); } catch (InvalidOperationException) { return(NotFound()); } }
public bool PutStudentDetials(User student, StudentFormModel model) { try { if (student.StudentDetails == null) { student.StudentDetails = new Models.Entity.StudentDetails(student, model); } else { student.StudentDetails.Discipline = model.Discipline; student.StudentDetails.CurrentDegree = model.CurrentDegree; student.StudentDetails.CurrentSemester = model.CurrentSemester; } DbContext.SaveChanges(); return(true); } catch (Exception e) { Console.Error.Write(e); } return(false); }
public IActionResult PutStudent([FromBody] StudentFormModel model) { return(PutStudentDetials(User.Identity.GetUserId(), model)); }