public override async Task DeleteAStudent(StudentsLookupModel request, IServerStreamWriter <StudentsModel> responseStream, ServerCallContext context) { StudentsModel output = new StudentsModel(); using (DbprofilDbcontext contxt = new DbprofilDbcontext()) { var row = contxt.profiles.FirstOrDefault(r => r.matricNo == request.MatricNo); var itemToRemove = contxt.profiles.SingleOrDefault(x => x.matricNo == request.MatricNo); if (itemToRemove != null) { contxt.profiles.Remove(itemToRemove); contxt.SaveChanges(); } else { } } Dbrepository dbRptObj = new Dbrepository(); var studentsList = dbRptObj.GetProfiles(); foreach (var studentsData in studentsList) { output.MatricNo = studentsData.matricNo; output.Name = studentsData.name; output.ProfilePicture = Google.Protobuf.ByteString.FromBase64(Convert.ToBase64String(studentsData.profilePics)); output.BloodGroup = studentsData.bloodGroup; output.Programme = studentsData.programme; output.School = studentsData.school; await responseStream.WriteAsync(output); } // return base.DeleteAStudent(request, responseStream, context); }
public override Task <StudentsModel> GetStudentsInfo(StudentsLookupModel request, ServerCallContext context) { StudentsModel output = new StudentsModel(); using (DbprofilDbcontext contxt = new DbprofilDbcontext()) { var row = contxt.profiles.FirstOrDefault(r => r.matricNo == request.MatricNo); if (row != null) { output.MatricNo = row.matricNo; output.Name = row.name; output.ProfilePicture = Google.Protobuf.ByteString.FromBase64(Convert.ToBase64String(row.profilePics)); output.BloodGroup = row.bloodGroup; output.Programme = row.programme; output.School = row.school; } else { } return(Task.FromResult(output)); } }