public override async Task <NewProfessorResponse> AddProfessor(NewProfessorRequest request, ServerCallContext context)
        {
            _logger.Log(LogLevel.Debug, "Request Received for CollegeGrpcService::AddProfessor");

            var newProfessor = new NewProfessorResponse
            {
                Message = "success"
            };

            var professor = new Professor
            {
                Name    = request.Name,
                Doj     = request.Doj.ToDateTime(),
                Teaches = request.Teaches,
                Salary  = Convert.ToDecimal(request.Salary),
                IsPhd   = request.IsPhd
            };

            var results = await _professorsSqlBll.AddProfessor(professor).ConfigureAwait(false);

            newProfessor.ProfessorId = results.ProfessorId.ToString();

            var results1 = await _professorsCosmosBll.AddProfessor(professor).ConfigureAwait(false);

            Console.WriteLine($"Professor Id (Cosmos Db): {results1.ProfessorId}");

            _logger.Log(LogLevel.Debug, "Returning the results from CollegeGrpcService::AddProfessor");

            return(newProfessor);
        }
Example #2
0
        static async Task Main(string[] args)
        {
            string response = "Y";

            _config = new ConfigurationBuilder()
                      .SetBasePath(Directory.GetCurrentDirectory())
                      .AddJsonFile("appsettings.json").Build();

            WriteLine("\n\nCreating New Professor ...");
            while (response == "Y")
            {
                // Add New Professor
                NewProfessorRequest professorNew = GenerateNewProfessor();

                var newlyAddedProfessor = await Client.AddProfessorAsync(professorNew);

                WriteLine($"\n\nNew Professor Added with Professor Id: {newlyAddedProfessor.ProfessorId}");

                WriteLine("\n\nDo you want to create New Professor: {Y/N}");
                response = ReadKey().KeyChar.ToString().ToUpper();
            }

            WriteLine("\n\nThank You for using the application. \n\nPress any key ...");
            ReadKey();
        }
Example #3
0
        static async Task Main(string[] args)
        {
            string response = "Y";

            _config = new ConfigurationBuilder()
                      .SetBasePath(Directory.GetCurrentDirectory())
                      .AddJsonFile("appsettings.json").Build();

            AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

            WriteLine("\n\nCreating New Professor ...");
            while (response == "Y")
            {
                // Add New Professor
                NewProfessorRequest professorNew = GenerateNewProfessor();

                var newlyAddedProfessor = await Client.AddProfessorAsync(professorNew);

                WriteLine($"\n\nNew Professor Added with Professor Id: {newlyAddedProfessor.ProfessorId}");

                WriteLine("\n\nDo you want to create New Professor: {Y/N}");
                response = ReadKey().KeyChar.ToString().ToUpper();
            }

            Console.WriteLine("\n\nThank You for using the application. \n\nPress any key ...");
            Console.ReadKey();
        }
        public override async Task <NewProfessorResponse> AddProfessor(NewProfessorRequest request, ServerCallContext context)
        {
            var newProfessor = new NewProfessorResponse
            {
                Message = "success"
            };

            var professor = new Professor
            {
                Name    = request.Name,
                Doj     = request.Doj.ToDateTime(),
                Teaches = request.Teaches,
                Salary  = Convert.ToDecimal(request.Salary),
                IsPhd   = request.IsPhd
            };

            var results = await _professorsSQLBll.AddProfessor(professor).ConfigureAwait(false);

            newProfessor.ProfessorId = results.ProfessorId.ToString();

            var results1 = await _professorsCosmosBll.AddProfessor(professor).ConfigureAwait(false);

            Console.WriteLine($"Professor Id (Cosmos Db): {results1.ProfessorId}");

            return(newProfessor);
        }
        public override Task <NewProfessorResponse> AddProfessor(NewProfessorRequest request, ServerCallContext context)
        {
            _logger.Log(LogLevel.Debug, "Request Received for CollegeGrpcService::AddProfessor");

            var newProfessor = new NewProfessorResponse
            {
                Message = "success"
            };

            var professor = new Professor
            {
                Name    = request.Name,
                Doj     = request.Doj.ToDateTime(),
                Teaches = request.Teaches,
                Salary  = Convert.ToDecimal(request.Salary),
                IsPhd   = request.IsPhd
            };

            var results = _professorsBll.AddProfessor(professor);

            newProfessor.ProfessorId = results.ProfessorId.ToString();

            _logger.Log(LogLevel.Debug, "Returning the results from CollegeGrpcService::AddProfessor");

            return(Task.FromResult(newProfessor));
        }
        static async Task Main(string[] args)
        {
            using var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client = new CollegeService.CollegeServiceClient(channel);

            // Add New Professor
            NewProfessorRequest professorNew = new NewProfessorRequest()
            {
                Name    = "Shiva",
                Doj     = Timestamp.FromDateTime(DateTime.Now.AddYears(-5).ToUniversalTime()),
                Teaches = "CSharp, Java",
                Salary  = 1234.56,
                IsPhd   = true
            };
            var professorGenerated = await client.AddProfessorAsync(professorNew);

            // Retrieve Single Row
            var professorRequest = new GetProfessorRequest {
                ProfessorId = "5ec797ec-da0a-43df-b3a3-3f9a04163656"
            };
            var professor = await client.GetProfessorByIdAsync(professorRequest);

            DisplayProfessorDetails(professor);

            // Retrieve Multiple Rows
            var professors = await client.GetAllProfessorsAsync(new Empty());

            foreach (var prof in professors.Professors)
            {
                DisplayProfessorDetails(prof);
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Example #7
0
        public async Task <ActionResult <NewProfessorResponse> > AddProfessor([FromBody] NewProfessorRequest professor)
        {
            _logger.Log(LogLevel.Debug, "Request Received for ProfessorsController::AddProfessor");

            var results = await _collegeServiceClient.AddProfessorAsync(professor);

            _logger.Log(LogLevel.Debug, "Sending Response from ProfessorsController::AddProfessor");

            return(Created(string.Empty, results));
        }
        public override async Task <NewProfessorResponse> AddProfessor(NewProfessorRequest request, ServerCallContext context)
        {
            _logger.Log(LogLevel.Debug, "Request Received for CollegeGrpcService::AddProfessor");

            var newProfessor = new NewProfessorResponse
            {
                Message = "success"
            };

            var professor = _mapper.Map <Professor>(request);

            var results = await _professorsBll.AddProfessor(professor);

            newProfessor.ProfessorId = results.ProfessorId.ToString();

            _logger.Log(LogLevel.Debug, "Returning the results from CollegeGrpcService::AddProfessor");

            return(newProfessor);
        }
Example #9
0
        static async Task Main(string[] args)
        {
            using var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client = new CollegeService.CollegeServiceClient(channel);

            // Add New Professor
            NewProfessorRequest professorNew = new NewProfessorRequest()
            {
                Name    = "Shiva",
                Doj     = Timestamp.FromDateTime(DateTime.Now.AddYears(-5).ToUniversalTime()),
                Teaches = "CSharp, Java",
                Salary  = 1234.56,
                IsPhd   = true
            };
            var newlyAddedProfessor = await client.AddProfessorAsync(professorNew);

            WriteLine($"New Professor Added with Professor Id: {newlyAddedProfessor.ProfessorId}");

            WriteLine("Press any key to exit...");
            ReadKey();
        }
        public override async Task <NewProfessorResponse> AddProfessor(NewProfessorRequest request, ServerCallContext context)
        {
            var newProfessor = new NewProfessorResponse
            {
                Message = "success"
            };

            var professor = new Professor
            {
                Name    = request.Name,
                Doj     = request.Doj.ToDateTime(),
                Teaches = request.Teaches,
                Salary  = Convert.ToDecimal(request.Salary),
                IsPhd   = request.IsPhd
            };

            var results = _collegeDbContext.Professors.Add(professor);
            await _collegeDbContext.SaveChangesAsync();

            newProfessor.ProfessorId = results.Entity.ProfessorId.ToString();
            return(newProfessor);
        }
        public override Task <NewProfessorResponse> AddProfessor(NewProfessorRequest request, ServerCallContext context)
        {
            var newProfessor = new NewProfessorResponse
            {
                Message = "success"
            };

            var professor = new Professor
            {
                Name    = request.Name,
                Doj     = request.Doj.ToDateTime(),
                Teaches = request.Teaches,
                Salary  = Convert.ToDecimal(request.Salary),
                IsPhd   = request.IsPhd
            };

            var results = _professorsBll.AddProfessor(professor);

            newProfessor.ProfessorId = results.ProfessorId.ToString();

            return(Task.FromResult(newProfessor));
        }