예제 #1
0
        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);
        }
예제 #2
0
        static async Task PerformAsync()
        {
            List <DbProfile> parsedData;
            await Task.Run(() =>
            {
                parsedData = ParseJsonResponce(Properties.Settings.Default.Sample);

                Database.SetInitializer(new DropCreateDatabaseAlways <DbprofilDbcontext>());

                using (var context = new DbprofilDbcontext())
                {
                    context.Database.Initialize(true);

                    //radProgressBar1.Text = "Working";
                    using (SqlCeBulkCopy bcp = new SqlCeBulkCopy(context.Database.Connection.ConnectionString))
                    {
                        bcp.DestinationTableName = "DbProfiles";
                        // sw.Restart();
                        bcp.WriteToServer(parsedData);
                        // parsedData = null;
                        //sw.Stop();

                        //Console.WriteLine(
                        //    "Saved {0} entities using SqlCeBulkCopy in {1}", students.Count, sw.Elapsed.ToString());
                    }
                }
            });
        }
예제 #3
0
        static void Main(string[] args)
        {
            Server server = new Server
            {
                Services = { Students.BindService(new Students_Profiles()) },
                Ports    = { new ServerPort("localhost", Convert.ToInt32(Properties.Settings.Default.Port), ServerCredentials.Insecure) }
            };

            server.Start();

            Console.WriteLine("gRPC server listening on port " + Properties.Settings.Default.Port);
            Console.WriteLine("Press any key to stop the server...");
            string path = AppDomain.CurrentDomain.BaseDirectory;

            if (!File.Exists(path + @"\\gRPC_Server.DbprofilDbcontext.sdf"))
            {
                Console.WriteLine(path);
                using (DbprofilDbcontext db = new DbprofilDbcontext())
                {
                    db.profiles.ToList();
                }
                Task PerformInsertAsync = PerformAsync();
            }



            Console.ReadKey();
            server.ShutdownAsync().Wait();
        }
예제 #4
0
        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));
            }
        }
예제 #5
0
        public override Task <Result> AddStudent(StudentsModel request, ServerCallContext context)
        {
            Result output = new Result();

            using (DbprofilDbcontext contxt = new DbprofilDbcontext())
            {
                try
                {
                    var itemCheck = contxt.profiles.SingleOrDefault(x => x.matricNo == request.MatricNo);

                    if (itemCheck == null)
                    {
                        DbProfile dbP = new DbProfile();
                        dbP.name        = request.Name;
                        dbP.matricNo    = request.MatricNo;
                        dbP.programme   = request.Programme;
                        dbP.school      = request.School;
                        dbP.bloodGroup  = request.BloodGroup;
                        dbP.profilePics = Convert.FromBase64String(request.ProfilePicture.ToBase64());
                        dbP.ClientGuid  = Guid.NewGuid();
                        contxt.profiles.Add(dbP);
                        contxt.SaveChanges();
                        output.Prompt = "Success";
                    }
                    else
                    {
                        output.Prompt = "Matric No Already Exist";
                    }
                }
                catch (Exception ex)
                {
                    output.Prompt = ex.Message;
                }
            }
            return(Task.FromResult(output));
        }
예제 #6
0
        public List <DbProfile> GetProfiles()
        {
            DbprofilDbcontext dbPrdbc = new DbprofilDbcontext();

            return(dbPrdbc.profiles.ToList());
        }