public override async Task <GetProfessorResponse> GetProfessorById(GetProfessorRequest request, ServerCallContext context) { Stopwatch stopwatch = new Stopwatch(); GetProfessorResponse getProfessorResponse = new GetProfessorResponse(); Professor professor; string professorId = $"{Constants.RedisCacheStore.SingleProfessorsKey}{request.ProfessorId}"; stopwatch.Start(); var professorFromCache = _cache.GetString(professorId); if (!string.IsNullOrEmpty(professorFromCache)) { //if they are there, deserialize them professor = JsonConvert.DeserializeObject <Professor>(professorFromCache); } else { // Going to Data Store SQL Server professor = _professorsBll.GetProfessorById(Guid.Parse(request.ProfessorId)); //and then, put them in cache _cache.SetString(professorId, JsonConvert.SerializeObject(professor), GetDistributedCacheEntryOptions()); } stopwatch.Stop(); _logger.Log(LogLevel.Warning, $"Time Taken to Retireve a Record: {stopwatch.ElapsedMilliseconds} ms"); getProfessorResponse = GetProfessorObject(professor); return(await Task.FromResult(getProfessorResponse)); }
private static void DisplayProfessorDetails(GetProfessorResponse professor) { DisplayHeader(); WriteLine($"Name: {professor.Name} \nSalary: {professor.Salary} \nTeaches: {professor.Teaches} \nDOJ: {professor.Doj}"); DisplayFooter(); }
private Professor GetProfessor(GetProfessorResponse prof) { return(new Professor { ProfessorId = Guid.Parse(prof.ProfessorId), Name = prof.Name, Doj = prof.Doj.ToDateTime(), Teaches = prof.Teaches, Salary = Convert.ToDecimal(prof.Salary), IsPhd = prof.IsPhd }); }
public override async Task <GetProfessorResponse> GetProfessorById(GetProfessorRequest request, ServerCallContext context) { _logger.Log(LogLevel.Debug, "Request Received for CollegeGrpcService::GetProfessorById"); Professor professor = await _professorsBll.GetProfessorById(Guid.Parse(request.ProfessorId)); GetProfessorResponse getProfessorResponse = _mapper.Map <GetProfessorResponse>(professor); _logger.Log(LogLevel.Debug, "Returning the results from CollegeGrpcService::GetProfessorById"); return(getProfessorResponse); }
//====================== Private Methods ====================== private static Professor GetProfessorObject(GetProfessorResponse professor) { return(new Professor() { ProfessorId = Guid.Parse(professor.ProfessorId), Name = professor.Name, Teaches = professor.Teaches, IsPhd = professor.IsPhd, Salary = Convert.ToDecimal(professor.Salary), Doj = professor.Doj.ToDateTime() }); }
public override async Task <GetProfessorResponse> GetProfessorById(GetProfessorRequest request, ServerCallContext context) { _logger.Log(LogLevel.Debug, "Request Received for CollegeGrpcService::GetProfessorById"); GetProfessorResponse getProfessorResponse = new GetProfessorResponse(); Professor professor; // Going to Data Store SQL Server professor = _professorsBll.GetProfessorById(Guid.Parse(request.ProfessorId)); getProfessorResponse = GetProfessorObject(professor); _logger.Log(LogLevel.Debug, "Returing the response from CollegeGrpcService::GetProfessorById"); return(await Task.FromResult(getProfessorResponse)); }
public override async Task <GetProfessorResponse> GetProfessorById(GetProfessorRequest request, ServerCallContext context) { _logger.Log(LogLevel.Debug, "Request Received for CollegeGrpcService::GetProfessorById"); //Professor professor = await _professorsSqlBll.GetProfessorById(Guid.Parse(request.ProfessorId)) // .ConfigureAwait(false); Professor professor = await _professorsCosmosBll.GetProfessorById(Guid.Parse(request.ProfessorId)) .ConfigureAwait(false); GetProfessorResponse getProfessorResponse = GetProfessorObject(professor); _logger.Log(LogLevel.Debug, "Returning the results from CollegeGrpcService::GetProfessorById"); return(getProfessorResponse); }
public override async Task <GetProfessorResponse> GetProfessorById(GetProfessorRequest request, ServerCallContext context) { GetProfessorResponse getProfessorResponse = new GetProfessorResponse(); if (!_collegeDbContext.Professors.Any(record => record.ProfessorId == Guid.Parse(request.ProfessorId))) { getProfessorResponse = null; } var professor = await _collegeDbContext.Professors .Where(record => record.ProfessorId == Guid.Parse(request.ProfessorId)) .Include(student => student.Students) .FirstOrDefaultAsync(); getProfessorResponse = GetProfessorObject(professor); return(getProfessorResponse); }
public override async Task <GetProfessorResponse> GetProfessorById(GetProfessorRequest request, ServerCallContext context) { Stopwatch stopwatch = new Stopwatch(); Professor professor; stopwatch.Start(); // Going to Data Store SQL Server professor = _professorsBll.GetProfessorById(Guid.Parse(request.ProfessorId)); stopwatch.Stop(); _logger.Log(LogLevel.Warning, $"Time Taken to Retireve a Record: {stopwatch.ElapsedMilliseconds} ms"); GetProfessorResponse getProfessorResponse = new GetProfessorResponse(); getProfessorResponse = GetProfessorObject(professor); return(await Task.FromResult(getProfessorResponse)); }
private static void DisplayProfessorDetails(GetProfessorResponse professor) { Console.WriteLine($"{professor.Name} {professor.Salary} {professor.Teaches} {professor.Doj}"); }