Exemplo n.º 1
0
        private bool confirm(MdlStudent student)
        {
            student.Confirmed = true;
            DbStudent dbStudentObj = new DbStudent();

            return(dbStudentObj.UpdateProfile(student));
        }
        public async Task <ActionResult <DbStudent> > PostDbStudent(DbStudent dbStudent)
        {
            _context.DbStudents.Add(dbStudent);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetDbStudent", new { id = dbStudent.Id }, dbStudent));
        }
Exemplo n.º 3
0
        protected override void OnStart()
        {
            DbStudent dbStudent = new DbStudent();
            Student   student   = dbStudent.GetStudent();

            // Comment out the 4 lines under to deactive the GoToLogin at
            if (student == null || student.accessToken == null)
            {
                Authenticater.Authorized = false;
            }

            NavPage = new NavigationPage(new MainPage());
            //NavPage = new NavigationPage(new LoginPage());
            MainPage = NavPage;

            //NavPage.BarBackgroundColor = Color.FromHex("ec7a08");
            //NavPage.BarTextColor = Color.White;

            if (student != null)
            {
                DeleteOutdatedData();
                UpdateAllFilters();
                DbDevice dbDevice = new DbDevice();
                if (dbDevice.GetDevice() != null && !dbDevice.GetDevice().tokenSent)
                {
                    DevicesController dc = new DevicesController();
                    dc.UpdateServersDb();
                }
            }
        }
        public async Task ShouldUpdateStudent()
        {
            //Given
            var updateStudentRequest = _fixture.Build <UpdateStudentRequest>()
                                       .With(p => p.Gender, Gender.Male)
                                       .Create();

            var dbStudent = new DbStudent();

            _unitOfWorkMock
            .Setup(r => r.StudentRepository.UpdateAsync(It.IsAny <DbStudent>()))
            .Callback((DbStudent s) =>
            {
                dbStudent = s;
            })
            .Returns(Task.CompletedTask).Verifiable();

            var sut = CreateSut();

            //When
            await sut.UpdateStudentAsync(updateStudentRequest);

            //Then
            _unitOfWorkMock.VerifyAll();

            dbStudent.Gender.Should().Be((int)updateStudentRequest.Gender);
            dbStudent.FirstName.Should().Be((updateStudentRequest.FirstName));
            dbStudent.LastName.Should().Be(updateStudentRequest.LastName);
            dbStudent.Patronymic.Should().Be(updateStudentRequest.Patronymic);
            dbStudent.UId.Should().Be(updateStudentRequest.UId);
        }
Exemplo n.º 5
0
        public bool checkCodeExist(string code)
        {
            //DB find, student update confirmed
            MdlStudent studentObj = new MdlStudent();

            studentObj.ConfirmationCode = code;
            DbStudent dbStudent = new DbStudent();

            using (TransactionScope scope = new TransactionScope())
            {
                //get student by confirmation code
                studentObj = dbStudent.GetStudentData(studentObj.ConfirmationCode, "code");

                scope.Complete();
            }

            if (studentObj != null)
            {
                return(confirm(studentObj));
            }
            else
            {
                return(false);
            }
        }
 private static void VoegStudentToeMetVakken(DbSchool dbSchool, DbStudent dbStudent, params DbVak[] vakken)
 {
     using (SchoolDbContext db = new SchoolDbContext())
     {
         using (IDbContextTransaction transaction = db.Database.BeginTransaction())
         {
             try {
                 dbStudent.Vakken = new List <DbVak>();
                 foreach (DbVak dbVak in vakken)
                 {
                     dbStudent.Vakken.Add(dbVak);
                 }
                 db.DbStudenten.Add(dbStudent);
                 dbSchool.Studenten = new List <DbStudent>();
                 dbSchool.Studenten.Add(dbStudent);
                 db.DbScholen.Update(dbSchool);
                 db.SaveChanges();
                 transaction.Commit();
             }catch (Exception e) {
                 Console.WriteLine("Kon student niet toevoegen:" + e.Message);
                 transaction.Rollback();
             }
         }
     }
 }
Exemplo n.º 7
0
        public ViewResult Edit(string StudentName)
        {
            context = new DbStudent();
            IEnumerable <Student> s = context.Student;
            Student currentstudent  = s.FirstOrDefault(p => p.StudentName == StudentName);

            return(View("Index", currentstudent));
        }
Exemplo n.º 8
0
        public ViewResult Display()
        {
            // Display
            context = new DbStudent();
            IEnumerable <Student> s = context.Student;

            return(View(s));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets the Students StudyGroups used for push notifications from the server.
        /// </summary>
        /// <returns></returns>
        public async Task <List <StudyGroup> > GetStudentsStudyGroupFromServer()
        {
            DbStudent db      = new DbStudent();
            Student   student = db.GetStudent();

            if (student == null)
            {
                Authenticater.Authorized = false;
                return(null);
            }

            string encodedUsername = Hasher.Base64Encode(student.username);
            Uri    url             = new Uri(Adress + "/" + encodedUsername);

            System.Diagnostics.Debug.WriteLine("StudentsController - UpdateStudyGroupStudent uri: " + url.ToString());
            string accessToken = db.GetStudentAccessToken();

            if (accessToken == null)
            {
                Authenticater.Authorized = false;
                return(null);
            }

            var client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
            string jsonString = null;

            try
            {
                var response = await client.GetAsync(url).ConfigureAwait(false);

                if (response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    System.Diagnostics.Debug.WriteLine("StudentsController - UpdateStudyGroupStudent failed due to lack of Authorization");
                    Authenticater.Authorized = false;
                    return(null);
                }
                System.Diagnostics.Debug.WriteLine("UpdateStudyGroupStudent response " + response.StatusCode.ToString());
                jsonString = await response.Content.ReadAsStringAsync();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("StudentsController - UpdateStudyGroupStudent: await client.GetAsync(\"url\") Failed");
                System.Diagnostics.Debug.WriteLine("StudentsController - UpdateStudyGroupStudent: Exception msg: " + e.Message);
                System.Diagnostics.Debug.WriteLine("StudentsController - UpdateStudyGroupStudent: Stack Trace: \n" + e.StackTrace);
                System.Diagnostics.Debug.WriteLine("StudentsController - UpdateStudyGroupStudent: End Of Stack Trace");
                return(null);
            }

            if (jsonString != null)
            {
                return(ExtractStudyGroupsFromJson(jsonString));
                //DeleteAllStudyGroupStudent();
                //CreateStudyGroupStudents(student.username, studyGroupIds);
            }
            return(null);
        }
Exemplo n.º 10
0
        public bool UpdateProfile(string email, int numberOfChildren, bool pet, int numberOfCohabitors, bool disabled,
                                  string name, string surname, string address, string postCode, string city, string country, string phone)
        {
            DbStudent  dbStudentObj  = new DbStudent();
            MdlStudent mdlStudentObj = GetStudent(email, numberOfChildren, pet, numberOfCohabitors,
                                                  disabled, name, surname, address, postCode, city, country, phone);

            mdlStudentObj = CalculateProfileScore(mdlStudentObj);
            return(dbStudentObj.UpdateProfile(mdlStudentObj));
        }
 private static DbStudent ZoekStudent(string voornaam, string familienaam, DateTime geboorteDatum)
 {
     using (SchoolDbContext db = new SchoolDbContext())
     {
         DbStudent dbStudent = db.DbStudenten.Include(s => s.Vakken).Where(s => s.Voornaam.ToLower() == voornaam.ToLower() &&
                                                                           s.Familienaam.ToLower() == familienaam.ToLower() &&
                                                                           s.GeboorteDatum == geboorteDatum).FirstOrDefault();
         return(dbStudent);
     }
 }
        static void Main(string[] args)
        {
            //VoegSchoolToe("Syntra-West");
            DbSchool dbSchool = ZoekSchoolOpNaam("Syntra-West");

            if (dbSchool == null)
            {
                Console.WriteLine("School 'Syntra-West' niet gevonden");
                return;
            }
            DbVak vak1 = ZoekVakOpNaam("C#");

            if (vak1 == null)
            {
                vak1 = new DbVak()
                {
                    Naam = "C#", AantalLesuren = 100
                };
            }
            else
            {
                Console.WriteLine($"Vak {vak1.Naam} gevonden met Id= {vak1.VakId} Aantal ingeschreven studenten: {vak1.Studenten.Count}");
            }
            DbVak vak2 = ZoekVakOpNaam("DataBase");

            if (vak2 == null)
            {
                vak2 = new DbVak()
                {
                    Naam = "DataBase", AantalLesuren = 80
                }
            }
            ;
            else
            {
                Console.WriteLine($"Vak {vak2.Naam} gevonden met Id= {vak2.VakId} Aantal ingeschreven studenten: {vak2.Studenten.Count}");
            }
            DbStudent dbStudent = ZoekStudent("Jan", "Jansens", new DateTime(1990, 1, 1));

            if (dbStudent == null)
            {
                dbStudent = new DbStudent()
                {
                    Voornaam      = "Jan",
                    Familienaam   = "Jansens",
                    GeboorteDatum = new DateTime(1990, 1, 1)
                };
            }
            else
            {
                Console.WriteLine($"Student {dbStudent.Voornaam} {dbStudent.Familienaam} gevonden, aantal vakken: {dbStudent.Vakken.Count}");
            }
            //VoegStudentToeMetVakken(dbSchool, dbStudent,vak1,vak2);
            Console.ReadKey();
        }
        /// <summary>
        /// Updates the students notification preferances.
        /// </summary>
        /// <param name="receiveNotifications"></param>
        /// <param name="receiveProjectNotifications"></param>
        /// <param name="receiveJobNotifications"></param>
        public void UpdateStudentsNotificationsPref(bool receiveNotifications,
                                                    bool receiveProjectNotifications, bool receiveJobNotifications)
        {
            DbStudent db      = new DbStudent();
            Student   student = db.GetStudent();

            student.receiveNotifications        = receiveNotifications;
            student.receiveProjectNotifications = receiveProjectNotifications;
            student.receiveJobNotifications     = receiveJobNotifications;
            db.UpdateStudent(student);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Active to logout.
        /// </summary>
        async void Logout(object sender, EventArgs e)
        {
            var logout = await DisplayAlert("Logg ut", "Ønsker du å logge ut?", "Ja", "Nei");

            if (logout == true)
            {
                DbStudent dbStudent = new DbStudent();
                dbStudent.DeleteAllStudents();
                GoToLogin();
            }
        }
Exemplo n.º 15
0
        public ViewResult Index(Student student)
        {
            context = new DbStudent();
            context.Student.Add(student);
            context.SaveChanges();

            // Display
            context = new DbStudent();
            IEnumerable <Student> s = context.Student;

            return(View("Display", s));
        }
Exemplo n.º 16
0
        /// <summary>
        /// Inserts or update the device with the given fields.
        /// </summary>
        /// <param name="gcmToken"></param>
        /// <param name="deviceId"></param>
        /// <param name="deviceType"></param>
        /// <returns></returns>
        public async Task InsertOrUpdateDevice(string gcmToken, string deviceId, string deviceType)
        {
            DbDevice  db        = new DbDevice();
            DbStudent dbStudent = new DbStudent();
            Student   student   = dbStudent.GetStudent();
            Device    device    = db.GetDevice();

            if (device == null)
            {
                device            = new Device();
                device.id         = deviceId;
                device.token      = gcmToken;
                device.tokenSent  = false;
                device.deviceType = deviceType;

                if (student != null)
                {
                    device.username = student.username;
                }
                db.InsertDevice(device);
                if (student != null)
                {
                    UpdateServersDb();
                }
                return;
            }

            if (device.token != gcmToken)
            {
                device.token     = gcmToken;
                device.tokenSent = false;
                if (student != null)
                {
                    device.username = student.username;
                }
                db.UpdateDevice(device);
                if (student != null)
                {
                    UpdateServersDb();
                }
                return;
            }

            if (!device.tokenSent && student != null)
            {
                if (device.username != student.username)
                {
                    device.username = student.username;
                    db.UpdateDevice(device);
                }
                UpdateServersDb();
            }
        }
Exemplo n.º 17
0
        public ActionResult Delete(string StudentName)
        {
            context = new DbStudent();
            IEnumerable <Student> s = context.Student;
            Student currentstudent  = s.FirstOrDefault(p => p.StudentName == StudentName);

            context.Student.Remove(currentstudent);
            context.SaveChanges();

            //IEnumerable<Student> ss = context.Student;
            return(RedirectToAction("Display"));
        }
Exemplo n.º 18
0
        public void SetNavPageToNotificationList()
        {
            DbStudent dbStudent = new DbStudent();
            Student   student   = dbStudent.GetStudent();

            if (student == null || student.accessToken == null)
            {
                Authenticater.Authorized = false;
            }
            UpdateAllFilters();
            NavPage = new NavigationPage(new CarouselVarsler());
        }
Exemplo n.º 19
0
        /// <summary>
        /// Gets all StudyGroups from the servers REST Api.
        /// </summary>
        public async Task UpdateStudyGroupsFromServer()
        {
            DbStudyGroup db = new DbStudyGroup();

            System.Diagnostics.Debug.WriteLine("StudyGroupsController - GetStudyGroupsFromServer: initiated");
            DbStudent dbStudent   = new DbStudent();
            string    accessToken = dbStudent.GetStudentAccessToken();

            if (accessToken == null)
            {
                Authenticater.Authorized = false;
                return;
            }

            Uri url = new Uri(Adress);

            System.Diagnostics.Debug.WriteLine("StudyGroupsController - url " + url.ToString());
            var client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
            try
            {
                var response = await client.GetAsync(url);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    System.Diagnostics.Debug.WriteLine("GetStudyGroupsFromServer response " + response.StatusCode.ToString());
                    var results = await response.Content.ReadAsAsync <IEnumerable <StudyGroup> >();

                    db.DeleteAllStudyGroups();

                    foreach (var studygroup in results)
                    {
                        // ugly gui filter hack
                        studygroup.filterChecked = false;
                        db.InsertStudyGroup(studygroup);
                    }
                }
                if (response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    Authenticater.Authorized = false;
                }
            }

            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("StudyGroupsController - GetStudyGroupsFromServer: await client.GetAsync(\"url\") Failed");
                System.Diagnostics.Debug.WriteLine("StudyGroupsController - GetStudyGroupsFromServer: Exception msg: " + e.Message);
                System.Diagnostics.Debug.WriteLine("StudyGroupsController - GetStudyGroupsFromServer: Stack Trace: \n" + e.StackTrace);
                System.Diagnostics.Debug.WriteLine("StudyGroupsController - GetStudyGroupsFromServer: End Of Stack Trace");
            }
        }
Exemplo n.º 20
0
        public override DbBase GetDbModel()
        {
            DbStudent stud = new DbStudent()
            {
                id          = this.id,
                favTeachers = this.favTeachers,
                facebookId  = this.facebookId,
                name        = this.name,
                email       = this.email
            };

            return(stud);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Gets all Courses from the servers REST Api.
        /// </summary>
        public async Task UpdateCoursesFromServer()
        {
            DbCourse db = new DbCourse();

            System.Diagnostics.Debug.WriteLine("CoursesController - UpdateCoursesFromServer: initiated");
            DbStudent dbStudent = new DbStudent();

            string accessToken = dbStudent.GetStudentAccessToken();

            if (accessToken == null)
            {
                Authenticater.Authorized = false;
                return;
            }

            Uri url = new Uri(Adress);

            System.Diagnostics.Debug.WriteLine("CoursesController - url " + url.ToString());
            var client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
            try
            {
                var response = await client.GetAsync(url);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    System.Diagnostics.Debug.WriteLine("UpdateCoursesFromServer response " + response.StatusCode.ToString());
                    var newCourses = await response.Content.ReadAsAsync <IEnumerable <Course> >();

                    db.DeleteAllCourses();
                    db.InsertCourses(newCourses);
                }
                if (response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    Authenticater.Authorized = false;
                }
            }

            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("CoursesController - UpdateCoursesFromServer: await client.GetAsync(\"url\") Failed");
                System.Diagnostics.Debug.WriteLine("CoursesController - UpdateCoursesFromServer: Exception msg: " + e.Message);
                System.Diagnostics.Debug.WriteLine("CoursesController - UpdateCoursesFromServer: Stack Trace: \n" + e.StackTrace);
                System.Diagnostics.Debug.WriteLine("CoursesController - UpdateCoursesFromServer: End Of Stack Trace");
            }
        }
        /// <summary>
        /// Receives a Message from GCM. The method exctracts a message from the Bundle data,
        /// and calls SendNotification.
        ///
        /// If the students have enabled receiveNotifications, but
        /// disabled receiveProjectNotifications and receiveJobNotifications
        /// The student can still receive more general messages sent as push notifications
        /// however these notifications will only be displayed once and won't be displayed in the
        /// notification list.
        /// </summary>
        public override async void OnMessageReceived(string from, Bundle data)
        {
            DbStudent dbStudent = new DbStudent();
            var       message   = data.GetString("message");

            Log.Debug("MyGcmListenerService", "From:    " + from);
            Log.Debug("MyGcmListenerService", "Message: " + message);
            var     type    = data.GetString("type");
            var     uuid    = data.GetString("uuid");
            Student student = dbStudent.GetStudent();

            if (student != null && student.receiveNotifications)
            {
                DbNotification dbNotification = new DbNotification();
                if (type == "project")
                {
                    if (student.receiveProjectNotifications)
                    {
                        SendNotification(message);
                        Log.Debug("MyGcmListenerService", "type: " + type);
                        Log.Debug("MyGcmListenerService", "uuid: " + uuid);
                        // type = job or project

                        Log.Debug("MyGcmListenerService", "After New NotificationController, but before use of method.");
                        dbNotification.InsertNotification(type, uuid);
                    }
                }
                else if (type == "job")
                {
                    if (student.receiveJobNotifications)
                    {
                        SendNotification(message);
                        Log.Debug("MyGcmListenerService", "type: " + type);
                        Log.Debug("MyGcmListenerService", "uuid: " + uuid);
                        // type = job or project

                        Log.Debug("MyGcmListenerService", "After New NotificationController, but before use of method.");
                        dbNotification.InsertNotification(type, uuid);
                    }
                }
                else
                {
                    SendNotification(message);
                }
            }
        }
        public async Task CompareServerHash()
        {
            DbStudent dbStudent   = new DbStudent();
            string    accessToken = dbStudent.GetStudentAccessToken();

            if (accessToken == null)
            {
                Authenticater.Authorized = false;
                return;
            }

            Uri url = new Uri(Adress + "/hash");

            System.Diagnostics.Debug.WriteLine("JobTypesController - url " + url.ToString());
            var client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
            try
            {
                var response = await client.GetAsync(url);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    System.Diagnostics.Debug.WriteLine("CompareServerHash response " + response.StatusCode.ToString());
                    string json = await response.Content.ReadAsStringAsync();

                    string hash      = ExtractServersHash(json);
                    string localHash = CreateLocalHash();
                    if (hash != localHash)
                    {
                        await UpdateJobTypesFromServer();
                    }
                }
                if (response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    Authenticater.Authorized = false;
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("JobTypesController - CompareServerHash: await client.GetAsync(\"url\") Failed");
                System.Diagnostics.Debug.WriteLine("JobTypesController - CompareServerHash: Exception msg: " + e.Message);
                System.Diagnostics.Debug.WriteLine("JobTypesController - CompareServerHash: Stack Trace: \n" + e.StackTrace);
                System.Diagnostics.Debug.WriteLine("JobTypesController - CompareServerHash: End Of Stack Trace");
            }
        }
        void GetStudentNotificationsPref()
        {
            DbStudent dbStudent = new DbStudent();
            Student   student   = dbStudent.GetStudent();

            if (student != null)
            {
                oppgaveSwitch.IsToggled  = student.receiveProjectNotifications;
                stillingSwitch.IsToggled = student.receiveJobNotifications;
                varselSwitch.IsToggled   = student.receiveNotifications;
            }
            else
            {
                oppgaveSwitch.IsToggled  = false;
                stillingSwitch.IsToggled = false;
                varselSwitch.IsToggled   = false;
            }
        }
        /// <summary>
        /// Updates the Job from the servers REST Api.
        ///
        /// This implementation also get the minimum data from the related
        /// Companies to build a proper notification list.
        /// </summary>
        /// <param name="uuid"></param>
        public async Task UpdateJobFromServer(string uuid)
        {
            System.Diagnostics.Debug.WriteLine("JobController - UpdateJobFromServer(string uuid): initiated");
            string adress = Adress + "/" + uuid;

            System.Diagnostics.Debug.WriteLine("UpdateJobFromServer: var url = " + adress);

            Uri url    = new Uri(adress);
            var client = new HttpClient();

            System.Diagnostics.Debug.WriteLine("JobController - UpdateJobFromServer: HttpClient created");
            DbStudent dbStudent = new DbStudent();

            string accessToken = dbStudent.GetStudentAccessToken();

            if (string.IsNullOrWhiteSpace(accessToken))
            {
                Authenticater.Authorized = false;
                return;
            }
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
            string jsonString = null;

            try
            {
                var response = await client.GetAsync(url);

                System.Diagnostics.Debug.WriteLine("UpdateJobFromServer response " + response.StatusCode.ToString());
                //results = await response.Content.ReadAsAsync<IEnumerable<Job>>();
                jsonString = await response.Content.ReadAsStringAsync();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(
                    "JobController - UpdateJobFromServer: await client.GetAsync(\"url\") Failed");
                System.Diagnostics.Debug.WriteLine("JobController - UpdateJobFromServer: Exception msg: " + e.Message);
                System.Diagnostics.Debug.WriteLine("JobController - UpdateJobFromServer: Stack Trace: \n" + e.StackTrace);
                System.Diagnostics.Debug.WriteLine("JobController - UpdateJobFromServer: End Of Stack Trace");
                return;
            }
            Deserialize(jsonString);
        }
Exemplo n.º 26
0
        public string AddStudent(MdlStudent mdlStudentObj)
        {
            DbStudent dbStudentObj = new DbStudent();
            CtrEmail  ctrEmailObj  = new CtrEmail();

            mdlStudentObj.Salt     = CreateSalt(10);
            mdlStudentObj.Password = CreateHash(mdlStudentObj.Password, mdlStudentObj.Salt);

            //mdlStudentObj.ConfirmationCode = ctrEmailObj.getCode();
            mdlStudentObj.ConfirmationCode = "none";
            string Feedback = dbStudentObj.AddStudent(mdlStudentObj);

            if (Feedback == "Error")
            {
                return(Feedback);
            }

            //ctrEmailObj.send();
            return(Feedback);
        }
Exemplo n.º 27
0
        public static Student Convert(this DbStudent student, DbUser user = null)
        {
            var res = new Student()
            {
                Id         = student.StudentId,
                EntryYear  = student.EnteringYear,
                Name       = student.Name,
                Surname    = student.Surname,
                Middlename = student.Middlename,
            };

            if (user != null)
            {
                res.Login            = user.Login;
                res.UserId           = user.UserId;
                res.Password         = user.Password;
                res.LastActivityDate = user.LastActivityDate ?? DateTime.Now;
                res.RegistredDate    = user.RegDate;
            }
            return(res);
        }
Exemplo n.º 28
0
 private void StudentFetched(DbStudent loggedIn)
 {
     if (loggedIn == null)
     {
         MessagePopupManager.Instance.
         SetUpperText(Strings.GetString(Strings.Account.student_doesnt_exist)).
         SetLeftButtonText(Strings.GetString(Strings.UI.OK)).
         OnlyRightButton(true).EnablePopup();
         MessagePopupManager.Instance.StopLoader();
     }
     else
     {
         UserPreferences.CurrentUserId = loggedIn.id;
         LoadMainMenu();
         if ((string.IsNullOrEmpty(loggedIn.messagingToken) && !string.IsNullOrEmpty(UserPreferences.MessagingToken)) ||
             loggedIn.messagingToken != UserPreferences.MessagingToken)
         {
             loggedIn.messagingToken = UserPreferences.MessagingToken;
             FirebaseManager.Instance.PushToCloud <DbStudent>(loggedIn);
         }
     }
 }
Exemplo n.º 29
0
        public int AddStudent(string login, string password, string fname, string lname, string mname, int entryYear)
        {
            if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
            {
                return(-1);
            }

            if (Context.Users.Any(x => x.Login == login))
            {
                return(-1);
            }

            var newUser = new DbUser();

            newUser.RegDate  = DateTime.Now;
            newUser.Login    = login;
            newUser.Password = password;
            Context.Users.Add(newUser);

            var student = new DbStudent();

            student.UserId       = newUser.UserId;
            student.Name         = fname;
            student.Surname      = lname;
            student.Middlename   = mname;
            student.EnteringYear = entryYear;
            Context.Students.Add(student);

            try
            {
                Context.SaveChanges();
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Exception:{ex.Message}");
                return(-1);
            }
            return(student.StudentId);
        }
        public async Task <IActionResult> PutDbStudent(int id, DbStudent dbStudent)
        {
            dbStudent.Id = id;

            _context.Entry(dbStudent).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DbStudentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }