コード例 #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 async Task <ActionResult <IEnumerable <StudentEntity> > > Get()
        {
            using (var service = new StudentsService())
            {
                await service.Initialize();

                return(await service.GetStudents());
            }
        }
コード例 #3
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);
            }
        }