public async Task Post([FromBody] StudentModel student) { if (string.IsNullOrEmpty(student.University) || string.IsNullOrEmpty(student.CNP)) { throw new Exception("The student does not have university or CNP set!"); } var studentEntity = new StudentEntity(student.University, student.CNP) { Email = student.Email, Faculty = student.Faculty, FirstName = student.FirstName, LastName = student.LastName, PhoneNumber = student.PhoneNumber, Year = student.Year }; // queueClient = new QueueClient(ServiceBusConnectionString, QueueName); // string json = JsonConvert.SerializeObject(student); // var message = new Message(Encoding.UTF8.GetBytes(json)); // Console.WriteLine($"Sending message: {json}"); // // Send the message to the queue. // await queueClient.SendAsync(message); using (var service = new StudentsService()) { await service.Initialize(); await service.AddStudent(studentEntity); } }
public int AddStudent(Students students) { try { return(ss.AddStudent(students)); } catch (Exception ex) { throw ex; } }
public void AddMail_Exception() { StudentsService service = new StudentsService(); StudentModel expected = new StudentModel() { Id = 4, St_Last_Name = "ddad", St_First_Name = "sasd", Phone = "8 999 222-11-11", Email = "23233.ru", GroupNumberId = 2 }; Assert.Throws <InvalidMailExeption>(() => service.AddStudent(expected)); }
public void AddName_Exception() { StudentsService service = new StudentsService(); StudentModel expected = new StudentModel() { Id = 4, St_Last_Name = "131231", St_First_Name = "s41s", Phone = "8 999 222-11-11", Email = "*****@*****.**", GroupNumberId = 2 }; Assert.Throws <InvalidNameException>(() => service.AddStudent(expected)); }
public void AddPhone_Exception() { StudentsService service = new StudentsService(); StudentModel expected = new StudentModel() { Id = 4, St_Last_Name = "ddds", St_First_Name = "ssad", Phone = "42s4d323", Email = "*****@*****.**", GroupNumberId = 2 }; Assert.Throws <InvalidPhoneException>(() => service.AddStudent(expected)); }
public async Task Post([FromBody] StudentModel student) { if (string.IsNullOrEmpty(student.University) || string.IsNullOrEmpty(student.CNP)) { throw new Exception("The student does not have university or CNP set!"); } var studentEntity = new StudentEntity(student.University, student.CNP) { Email = student.Email, Faculty = student.Faculty, FirstName = student.FirstName, LastName = student.LastName, PhoneNumber = student.PhoneNumber, Year = student.Year }; using (var service = new StudentsService()) { await service.Initialize(); await service.AddStudent(studentEntity); } }
public void Post([FromBody] StudentModel value) { _student.AddStudent(value); }