Ejemplo n.º 1
0
        public IActionResult Registration_Student(User model)
        {
            var TblStudent   = _userService.GetBelougaRegistrationStudent(model.Id);
            var studenttoken = _userService.BelougaToken();

            var usernameresult = usernamecheck(studenttoken.Result, TblStudent[0].Username);

            if (usernameresult.Result != "false")
            {
                var userpass = _userService.Registration_Student_Paseto(model.Id, TblStudent[0].FirstName, TblStudent[0].LastName, TblStudent[0].Username, TblStudent[0].Dob.ToString(), TblStudent[0].Class.ToString());
                if (userpass.Result == "ID is not found")
                {
                    return(BadRequest(new { message = "ID is incorrect" }));
                }

                var studentidresult = GetAsyncStudentRegistration(userpass.Result);
                var studentid       = studentidresult.Result.Replace("\"", string.Empty).Trim();

                using (var db = new PrincetonhiveContext())
                {
                    var resultstudent = db.TblStudentRegistration.Where(y => y.StudentRegistrationId == model.Id).SingleOrDefault();
                    if (resultstudent != null)
                    {
                        resultstudent.StudentIdBelouga = studentid;

                        //  resultstudent.ClassIdBelouga = classid;
                        db.SaveChanges();
                    }

                    if (TblStudent[0].Username != null)
                    {
                        var std = new UserLogin()
                        {
                            UserName = TblStudent[0].Username,
                            Password = Encrypt(TblStudent[0].password),
                            UserRole = TblStudent[0].Type
                        };
                        db.UserLogin.Add(std);
                        db.SaveChanges();
                    }
                }

                if (studentidresult.Status.Equals(HttpStatusCode.OK))
                {
                    return(CommonModel.GetResponse("Registration data is valid and submitted successfully!", studentid, HttpStatusCode.OK));
                }
                else
                {
                    return(CommonModel.GetResponse("Student Not Registered", studentid, HttpStatusCode.OK));
                }
            }
            else
            {
                return(CommonModel.GetResponse("Student Username Already Exists", TblStudent[0].Username, HttpStatusCode.OK));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> ChangePasswords([FromBody] User userParam)
        {
            // var sessionList = await _userServic
            var userpass = await _userService.LoginCheck(userParam.Username, userParam.Password);

            if (userpass == "Username is not found")
            {
                return(BadRequest(new { message = "Username is incorrect" }));
            }
            if (userpass == "Password is invalid")
            {
                return(BadRequest(new { message = "Password is invalid" }));
            }

            using (var db = new PrincetonhiveContext())
            {
                var changepass = db.UserLogin.Where(y => y.UserName == userParam.Username).SingleOrDefault();
                if (changepass != null)
                {
                    changepass.Password = Encrypt(userParam.NewPassword);
                    db.SaveChanges();
                }
            }
            return(CommonModel.GetResponse("Password Changed succesfully", userParam, HttpStatusCode.OK));
        }
Ejemplo n.º 3
0
        public IActionResult Registration_Class(int Id)
        {
            var TblClass   = _userService.GetBelougaRegistrationClass(Id);
            var classtoken = _userService.BelougaToken();

            var userpass = _userService.Registration_Class_Paseto(Id, TblClass[0].SchoolIdBelouga, TblClass[0].ClassName, TblClass[0].ClassName, TblClass[0].TeacheId);

            if (userpass.Result == "ID is not found")
            {
                return(BadRequest(new { message = "ID is incorrect" }));
            }

            var classidresult = GetAsyncClassRegistration(userpass.Result);
            var classid       = classidresult.Result.Replace("\"", string.Empty).Trim();

            using (var db = new PrincetonhiveContext())
            {
                var resultclass = db.Tblclassmap.Where(y => y.ClassmapId == Id).SingleOrDefault();
                if (resultclass != null)
                {
                    resultclass.ClassIdBelouga = classid;
                    db.SaveChanges();
                }
            }

            if (classidresult.Status.Equals(HttpStatusCode.OK))
            {
                return(CommonModel.GetResponse("Registration data is valid and submitted successfully!", classid, HttpStatusCode.OK));
            }
            else
            {
                return(CommonModel.GetResponse("Class Not Registered", classtoken.Result, HttpStatusCode.OK));
            }
        }
Ejemplo n.º 4
0
        public IActionResult Registration_Teacher(int ID)
        {
            var princetonhive    = new PrincetonhiveContext();
            var TblTeacher       = _userService.GetBelougaRegistrationTeacher(ID);
            var teacheridbelouga = TblTeacher[0].TeacherIdBelouga;
            var schoolidbelouga  = TblTeacher[0].SchoolIdBelouga;
            var token            = _userService.BelougaToken();

            if ((teacheridbelouga == null || teacheridbelouga == "") && (schoolidbelouga == null || schoolidbelouga == ""))
            {
                var checkemail = emailcheck(token.Result, TblTeacher[0].Teacheremail);

                if (checkemail.Result != "false")
                {
                    var checkusername = usernamecheck(token.Result, TblTeacher[0].Teacherusername);
                    if (checkusername.Result != "false")
                    {
                        var userpass        = _userService.Registration_Teacher_Paseto(ID, TblTeacher);
                        var teacherregister = userpass.Result;
                        if (teacherregister == "ID is not found")
                        {
                            return(BadRequest(new { message = "ID is incorrect" }));
                        }

                        var teacherresult = GetAsyncTeacherRegistration(teacherregister);

                        var teacherid = teacherresult.Result.Replace("\"", string.Empty).Trim();

                        if (teacherid != null || teacherid != "")
                        {
                            var teacherregistrationupdate = princetonhive.TblRegistration.Where(x => x.RegistrationId == ID).SingleOrDefault();
                            if (teacherregistrationupdate != null)
                            {
                                teacherregistrationupdate.TeacherIdBelouga = teacherid;
                                princetonhive.SaveChanges();
                            }
                            return(CommonModel.GetResponse("Registration data is valid and submitted successfully!", teacherresult.Result, HttpStatusCode.OK));
                        }
                        else
                        {
                            return(CommonModel.GetResponse("Teacher Not Registered", teacherresult.Result, HttpStatusCode.BadRequest));
                        }
                    }
                    else
                    {
                        return(CommonModel.GetResponse("Teacher UserName Already Exists", checkusername.Result, HttpStatusCode.OK));
                    }
                }
                else
                {
                    return(CommonModel.GetResponse("Teacher Eamil Already Exists", checkemail.Result, HttpStatusCode.OK));
                }
            }

            else if ((teacheridbelouga == null || teacheridbelouga == "") && (schoolidbelouga != null))
            {
                var checkemail = emailcheck(token.Result, TblTeacher[0].Teacheremail);

                if (checkemail.Result != "false")
                {
                    var checkusername = usernamecheck(token.Result, TblTeacher[0].Teacherusername);
                    if (checkusername.Result != "false")
                    {
                        var userpass        = _userService.Registration_Teacher_Paseto(ID, TblTeacher);
                        var teacherregister = userpass.Result;
                        if (teacherregister == "ID is not found")
                        {
                            return(BadRequest(new { message = "ID is incorrect" }));
                        }

                        var teacherresult = GetAsyncTeacherRegistration(teacherregister);

                        var teacherid = teacherresult.Result.Replace("\"", string.Empty).Trim();

                        if (teacherid != null || teacherid != "")
                        {
                            var teacherregistrationupdate = princetonhive.TblRegistration.Where(x => x.RegistrationId == ID).SingleOrDefault();
                            if (teacherregistrationupdate != null)
                            {
                                teacherregistrationupdate.TeacherIdBelouga = teacherid;
                                princetonhive.SaveChanges();
                            }


                            if (schoolidbelouga != null && teacherid != null)
                            {
                                var classtoken    = _userService.Registration_Class_Paseto(ID, schoolidbelouga, TblTeacher[0].Class, TblTeacher[0].Class, teacheridbelouga);
                                var classidresult = GetAsyncClassRegistration(classtoken.Result);
                                var classid       = classidresult.Result.Replace("\"", string.Empty).Trim();

                                var classupdate = princetonhive.TblRegistration.Where(x => x.RegistrationId == ID).SingleOrDefault();
                                if (classupdate != null)
                                {
                                    classupdate.ClassIdBelouga = classid;
                                    princetonhive.SaveChanges();
                                }

                                if (TblTeacher[0].Teacherusername != null)
                                {
                                    var std = new UserLogin()
                                    {
                                        UserName = TblTeacher[0].Teacherusername,
                                        Password = Encrypt(TblTeacher[0].Teacherpassword),
                                        UserRole = TblTeacher[0].Type
                                    };
                                    princetonhive.UserLogin.Add(std);
                                    princetonhive.SaveChanges();
                                }
                            }
                            return(CommonModel.GetResponse("Registration data is valid and submitted successfully!", teacherresult.Result, HttpStatusCode.OK));
                        }
                        else
                        {
                            return(CommonModel.GetResponse("Teacher Not Registered", teacherresult.Result, HttpStatusCode.BadRequest));
                        }
                    }
                    else
                    {
                        return(CommonModel.GetResponse("Teacher UserName Already Exists", checkusername.Result, HttpStatusCode.OK));
                    }
                }
                else
                {
                    return(CommonModel.GetResponse("Teacher Eamil Already Exists", checkemail.Result, HttpStatusCode.OK));
                }
            }
            else
            {
                var schoolid = _userService.schoolcheck(token.Result, TblTeacher[0].Newuserstate, TblTeacher[0].Newuserpostalcode, TblTeacher[0].Newuserschoolname);
                if (schoolid != null && teacheridbelouga != null)
                {
                    var classtoken    = _userService.Registration_Class_Paseto(ID, schoolid.Result, TblTeacher[0].Class, TblTeacher[0].Class, teacheridbelouga);
                    var classidresult = GetAsyncClassRegistration(classtoken.Result);
                    var classid       = classidresult.Result.Replace("\"", string.Empty).Trim();

                    var teacherregistrationupdate = princetonhive.TblRegistration.Where(x => x.RegistrationId == ID).SingleOrDefault();
                    if (teacherregistrationupdate != null)
                    {
                        teacherregistrationupdate.SchoolIdBelouga = schoolid.Result;
                        teacherregistrationupdate.ClassIdBelouga  = classid;
                        princetonhive.SaveChanges();
                    }

                    if (TblTeacher[0].Teacherusername != null)
                    {
                        var std = new UserLogin()
                        {
                            UserName = TblTeacher[0].Teacherusername,
                            Password = Encrypt(TblTeacher[0].Teacherpassword),
                            UserRole = TblTeacher[0].Type
                        };
                        princetonhive.UserLogin.Add(std);
                        princetonhive.SaveChanges();
                    }
                }

                return(CommonModel.GetResponse("Registration data is valid and submitted successfully!", teacheridbelouga, HttpStatusCode.OK));
            }
        }