示例#1
0
        public Response <UserDTO> ForgotPassword(UserDTO userDTO)
        {
            try
            {
                using (VDEntities entities = new VDEntities())
                {
                    var dbUser = entities.Users.Where(x => x.MobileNumber == userDTO.MobileNumber)
                                 .Where(x => x.CountryCode == userDTO.CountryCode)
                                 .Where(ut => ut.UserType == userDTO.UserType).FirstOrDefault();

                    if (dbUser == null)
                    {
                        return(new Response <UserDTO>(false, "Invalid Mobile Number", null));
                    }

                    if (dbUser.UserType.Equals("DOCTOR"))
                    {
                        var doctorDb = entities.Doctors.Where(x => x.UserID == dbUser.ID).FirstOrDefault();
                        if (doctorDb == null)
                        {
                            return(new Response <UserDTO>(false, "Invalid Mobile Number", null));
                        }
                        else
                        {
                            UserEmail.DoctorForgotPassword(doctorDb);
                            UserSMS.DoctorForgotPasswordSMS(doctorDb);
                            return(new Response <UserDTO>(true, "your password has been sent to your mobile number and email address", null));
                        }
                    }
                    else if (dbUser.UserType.Equals("PARENT"))
                    {
                        var childDB = entities.Children.Where(x => x.UserID == dbUser.ID).FirstOrDefault();
                        if (childDB == null)
                        {
                            return(new Response <UserDTO>(false, "Invalid Mobile Number", null));
                        }
                        else
                        {
                            UserEmail.ParentForgotPassword(childDB);
                            UserSMS.ParentForgotPasswordSMS(childDB);
                            return(new Response <UserDTO>(true, "your password has been sent to your mobile number and email address", null));
                        }
                    }
                    else
                    {
                        return(new Response <UserDTO>(false, "Please contact with admin", null));
                    }
                }
            }
            catch (Exception e)
            {
                return(new Response <UserDTO>(false, GetMessageFromExceptionObject(e), null));
            }
        }