Пример #1
0
        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);
            }
        }
Пример #2
0
 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));
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
 public void Post([FromBody] StudentModel value)
 {
     _student.AddStudent(value);
 }