public void ShouldUpdateStudentWithError() { commandUpdate = new StudentInputUpdate() { CourseId = course.CourseId, Birthdate = DateTime.Now, FirstName = string.Empty, LastName = string.Empty, Email = string.Empty, Phone = string.Empty, Gender = string.Empty, Country = string.Empty, City = string.Empty, Address = string.Empty, StudentId = student.Id }; StandardResult result = (StandardResult)handler.Handle(commandUpdate); Assert.IsFalse(result.IsValid); Assert.IsTrue(result.Notifications.Any(x => x.Key == "Email" && x.Value != null)); Assert.IsTrue(result.Notifications.Any(x => x.Key == "FirstName" && x.Value != null)); Assert.IsTrue(result.Notifications.Any(x => x.Key == "LastName" && x.Value != null)); Assert.IsTrue(result.Notifications.Any(x => x.Key == "Telefone" && x.Value != null)); Assert.IsTrue(result.Notifications.Any(x => x.Key == "City" && x.Value != null)); Assert.IsTrue(result.Notifications.Any(x => x.Key == "Country" && x.Value != null)); }
public ActionResult Edit(EditStudentViewModel student) { var input = new StudentInputUpdate { Address = student.Address, Birthdate = student.Birthdate, City = student.City, Country = student.Country, CourseId = student.SelectedCourse, Email = student.Email, FirstName = student.FirstName, Gender = student.Gender, LastName = student.LastName, Phone = student.Phone, StudentId = student.Id }; var result = _studentCommand.Handle(input); if (!result.IsValid) { foreach (var n in result.Notifications) { ModelState.AddModelError(n.Key, n.Value); } student.Courses = GetComboboxCourse(); return(View(student)); } return(RedirectToAction("Index")); }
public void UpdateStudent([FromBody] StudentInputUpdate model) { var userName = GetUserNameToTokenJWT(); int userId = _userManager.Users.Where(x => x.UserName.ToLower().Equals(userName.ToLower())).Select(x => x.UserId).FirstOrDefault(); _studentcontext.UpdateStudent(model, userId); }
public void Init() { conection = new MSSQLDB(new DBConfiguration()); _SREP = new StudentRepository(conection); _encryptor = new Encryptor(); handler = new StudentCommandHandler(_SREP, _encryptor); var db = conection.GetCon(); // Create Course course = new Course(Guid.NewGuid(), "LTP5"); var sql = "INSERT INTO [Course] ([Id], [Name]) VALUES (@Id, @Name)"; db.Execute(sql, param: new { Id = course.CourseId, Name = course.Name }); var cpf = "964.377.278-02"; string password = cpf.Replace("-", "").Replace(".", ""); password = _encryptor.Encrypt(password, out string salt); student = new Student(course, DateTime.Now, "Abmael", "Araujo", cpf, "*****@*****.**", "(86) 2802-4826", "M", "Brasil", "Araguaina", "Centro", password, salt); _SREP.Create(student); commandRegister = new StudentInputRegister() { CourseId = course.CourseId, Birthdate = DateTime.Now, FirstName = "Ester", LastName = "Emily Oliveira", CPF = "494.035.320-68", Email = "*****@*****.**", Phone = "(45) 2509-8770", Gender = "M", Country = "Brasil", City = "Araguaina", Address = "Centro" }; commandUpdate = new StudentInputUpdate() { CourseId = course.CourseId, Birthdate = DateTime.Now, FirstName = "Iago", LastName = "Bernardo Nunes", Email = "*****@*****.**", Phone = "(65) 3544-9294", Gender = "M", Country = "França", City = "Budapeste", Address = "Norte", StudentId = student.Id }; }
public void UpdateStudent(StudentInputUpdate model, int userId) { var student = _context.Student.Where(x => x.Id == model.Id && x.IsDelete != true).FirstOrDefault(); if (student != null) { student.Name = model.Name; student.gender = model.gender; student.DateOfBirth = model.DateOfBirth; student.address = model.address; student.IsDelete = model.IsDelete; _context.SaveChanges(); } }
public ICommandResult Handle(StudentInputUpdate command) { var course = new Course(command.CourseId); var student = new Student(course, command.Birthdate, command.FirstName, command.LastName, command.Email, command.Phone, command.Gender, command.Country, command.City, command.Address, command.StudentId); var result = new StandardResult(); result.AddRange(student.Notifications); if (student.Notifications.Count == 0) { _SREP.Update(student); result.Notifications.Add("Success", "O Acadêmico foi Editado"); } return(result); }
public void Update([FromBody] StudentInputUpdate model) { _StudentService.Update(model); }