Example #1
0
        public ActionResult <ApiResponse> Get(Helper.ObjectType objectType, string code, int randomNumber)
        {
            var    smsRepository = new SmsRepository();
            string mobile;

            switch (objectType)
            {
            case Helper.ObjectType.Student:
                var studentRepository = new StudentRepository();
                mobile = studentRepository.Select(code).Mobile;

                return(new ApiResponse
                {
                    ErrorId = mobile == null || mobile.Trim() == ""
                        ? (int)Helper.ApiOutputError.NotExists
                        : (int)Helper.ApiOutputError.NoError,

                    ErrorTitle = mobile == null || mobile.Trim() == ""
                        ? ((Helper.ApiOutputError)Helper.ApiOutputError.NotExists).ToString()
                        : ((Helper.ApiOutputError)Helper.ApiOutputError.NoError).ToString(),

                    Result = $"{mobile}-{smsRepository.SendRandomNumber(mobile, randomNumber.ToString(), _config)}"
                });

            case Helper.ObjectType.Professor:

                var professorRepository = new ProfessorRepository();
                mobile = professorRepository.Select(code).Mobile;

                return(new ApiResponse
                {
                    ErrorId = mobile == null || mobile.Trim() == ""
                            ? (int)Helper.ApiOutputError.NotExists
                            : (int)Helper.ApiOutputError.NoError,

                    ErrorTitle = mobile == null || mobile.Trim() == ""
                            ? ((Helper.ApiOutputError)Helper.ApiOutputError.NotExists).ToString()
                            : ((Helper.ApiOutputError)Helper.ApiOutputError.NoError).ToString(),

                    Result = $"{mobile}-{smsRepository.SendRandomNumber(mobile, randomNumber.ToString(), _config)}"
                });

            default:
                return(new ApiResponse());
            }
        }
        public ActionResult <ApiResponse> Get(Helper.ObjectType objectType, string code)
        {
            switch (objectType)
            {
            case Helper.ObjectType.Student:
                var studentRepo = new StudentRepository();
                var student     = studentRepo.Select(code);
                if (student.StudentCode != null)
                {
                    var smsRepository = new SmsRepository();
                    var randomNumber  = smsRepository.GetRandomNumber(student.Mobile);
                    return(new ApiResponse
                    {
                        ErrorId = student.Mobile == null || student.Mobile.Trim() == ""
                                ? (int)Helper.ApiOutputError.NotExists
                                : (int)Helper.ApiOutputError.NoError,

                        ErrorTitle = student.Mobile == null || student.Mobile.Trim() == ""
                                ? ((Helper.ApiOutputError)Helper.ApiOutputError.NotExists).ToString()
                                : ((Helper.ApiOutputError)Helper.ApiOutputError.NoError).ToString(),

                        Result = $"{student.Mobile}-{ smsRepository.SendRandomNumber(student.Mobile, randomNumber, _config)}"
                    });
                }
                else
                {
                    return(new ApiResponse
                    {
                        ErrorId = (int)Helper.ApiOutputError.NotExists,
                        ErrorTitle = ((Helper.ApiOutputError)Helper.ApiOutputError.NotExists).ToString(),
                    });
                }

            case Helper.ObjectType.Professor:
                var professorRepository = new ProfessorRepository();
                var professor           = professorRepository.Select(code);
                if (professor.ProfessorCode != null)
                {
                    var smsRepository = new SmsRepository();
                    var randomNumber  = smsRepository.GetRandomNumber(professor.Mobile);
                    return(new ApiResponse
                    {
                        ErrorId = professor.Mobile == null || professor.Mobile.Trim() == ""
                                ? (int)Helper.ApiOutputError.NotExists
                                : (int)Helper.ApiOutputError.NoError,

                        ErrorTitle = professor.Mobile == null || professor.Mobile.Trim() == ""
                                ? ((Helper.ApiOutputError)Helper.ApiOutputError.NotExists).ToString()
                                : ((Helper.ApiOutputError)Helper.ApiOutputError.NoError).ToString(),

                        Result = $"{professor.Mobile}-{ smsRepository.SendRandomNumber(professor.Mobile, randomNumber, _config)}"
                    });
                }
                else
                {
                    return(new ApiResponse
                    {
                        ErrorId = (int)Helper.ApiOutputError.NotExists,
                        ErrorTitle = ((Helper.ApiOutputError)Helper.ApiOutputError.NotExists).ToString(),
                    });
                }


            default:
                return(new ApiResponse
                {
                    ErrorId = (int)Helper.ApiOutputError.NotExists,
                    ErrorTitle = ((Helper.ApiOutputError)Helper.ApiOutputError.NotExists).ToString(),
                });
            }
        }
        public ActionResult <ApiResponse> Get(Helper.ObjectType objectType, string code, string password, string randomcode)
        {
            switch (objectType)
            {
            case Helper.ObjectType.Student:
                var studentRepo = new StudentRepository();
                var student     = studentRepo.Select(code);
                if (student.StudentCode != null)
                {
                    var smsRepository           = new SmsRepository();
                    var checkRandomnumberResult = smsRepository.CheckRandomNumber(student.Mobile, randomcode);

                    //var studentNewPass = this.GetNewPassword(student.StudentCode ,"");
                    var UrlChangePassForStudent_InBaseService = _config.BaseServiceUrlChangePasswordStudent + $"{student.StudentCode}/{password}";

                    var resualt1 = ClientHelper.GetValue <bool>(UrlChangePassForStudent_InBaseService, _config).FirstOrDefault();

                    if (checkRandomnumberResult)
                    {
                        return new ApiResponse
                               {
                                   ErrorId = student.Mobile == null || student.Mobile.Trim() == ""
                                    ? (int)Helper.ApiOutputError.NotExists
                                    : (int)Helper.ApiOutputError.NoError,

                                   ErrorTitle = student.Mobile == null || student.Mobile.Trim() == ""
                                    ? ((Helper.ApiOutputError)Helper.ApiOutputError.NotExists).ToString()
                                    : ((Helper.ApiOutputError)Helper.ApiOutputError.NoError).ToString(),

                                   Result = studentRepo.ChangePassword(student.StudentCode, password) && resualt1
                               }
                    }
                    ;
                    else
                    {
                        return(new ApiResponse
                        {
                            ErrorId = (int)Helper.ApiOutputError.InCorrectRandomNumber,
                            ErrorTitle = ((Helper.ApiOutputError)Helper.ApiOutputError.InCorrectRandomNumber).ToString(),
                        });
                    }
                }
                else
                {
                    return(new ApiResponse
                    {
                        ErrorId = (int)Helper.ApiOutputError.NotExists,
                        ErrorTitle = ((Helper.ApiOutputError)Helper.ApiOutputError.NotExists).ToString(),
                    });
                }

            case Helper.ObjectType.Professor:
                var professorRepository = new ProfessorRepository();
                var professor           = professorRepository.Select(code);
                if (professor.ProfessorCode != null)
                {
                    var smsRepository           = new SmsRepository();
                    var checkRandomnumberResult = smsRepository.CheckRandomNumber(professor.Mobile, randomcode);

                    //var profNewPass = this.GetNewPassword("",professor.ProfessorCode);
                    var UrlChangePassForTeacher_InBaseService = _config.BaseServiceUrlChangePasswordTeacher + $"{professor.ProfessorCode}/{password}";

                    var resualt2 = ClientHelper.GetValue <bool>(UrlChangePassForTeacher_InBaseService, _config).FirstOrDefault();

                    return(new ApiResponse
                    {
                        ErrorId = professor.Mobile == null || professor.Mobile.Trim() == ""
                                ? (int)Helper.ApiOutputError.NotExists
                                : (int)Helper.ApiOutputError.NoError,

                        ErrorTitle = professor.Mobile == null || professor.Mobile.Trim() == ""
                                ? ((Helper.ApiOutputError)Helper.ApiOutputError.NotExists).ToString()
                                : ((Helper.ApiOutputError)Helper.ApiOutputError.NoError).ToString(),

                        Result = professorRepository.ChangePassword(professor.ProfessorCode, password) && resualt2
                    });
                }
                else
                {
                    return(new ApiResponse
                    {
                        ErrorId = (int)Helper.ApiOutputError.NotExists,
                        ErrorTitle = ((Helper.ApiOutputError)Helper.ApiOutputError.NotExists).ToString(),
                    });
                }

            default:
                return(new ApiResponse
                {
                    ErrorId = (int)Helper.ApiOutputError.NotExists,
                    ErrorTitle = ((Helper.ApiOutputError)Helper.ApiOutputError.NotExists).ToString(),
                });
            }
        }