예제 #1
0
        /// <summary>
        /// Method to add patient to database.
        /// </summary>
        /// <param name="newPatientDto">newPatientDto contains information of patient to be added.</param>
        /// <returns>ResponseModel containing patient addition status</returns>
        public ResponseModel Add(PatientDto newPatientDto, int userId)
        {
            var validationStatus = ValidateRequest.ValidatePatientDto(newPatientDto);

            if (!(bool)validationStatus.First)
            {
                return(ReturnStatements.BadRequestResponse(validationStatus.Second));
            }

            newPatientDto = validationStatus.Second;

            using (var unitOfWork = new UnitOfWork())
            {
                var dbPatient = DtoToDatabase.Patient(newPatientDto, userId);
                unitOfWork.Patients.Add(dbPatient);
                var saveResponse = unitOfWork.Complete();

                if (saveResponse.Equals(Integers.UnsuccessfullDatabaseSave))
                {
                    return(ReturnStatements.FailedResponse(DynamicListForResponse.Create(newPatientDto)));
                }

                SendMail(newPatientDto);
                return(ReturnStatements.SuccessResponse(DynamicListForResponse.Create(newPatientDto)));
            }
        }
예제 #2
0
        /// <summary>
        /// Method to create a new forgot password request.
        /// </summary>
        /// <param name="forgotPasswordDto">forgotpassword dto contains dtails required by system to generate a new forgot password request.</param>
        /// <returns>ResponseModel containing the forgot password request creation status</returns>
        public ResponseModel ForgotPassword(ForgotPasswordDto forgotPasswordDto)
        {
            var validationStatus = ValidateRequest.ValidateForgotPasswordDto(forgotPasswordDto);

            if (!(bool)validationStatus.First)
            {
                return(ReturnStatements.BadRequestResponse(validationStatus.Second));
            }

            forgotPasswordDto = validationStatus.Second;
            using (var unitOfWork = new UnitOfWork())
            {
                var user = unitOfWork.Users.Find(m => m.Handle.Equals(forgotPasswordDto.Handle));

                if (user == null)
                {
                    return(ReturnStatements.FailedResponse(Strings.UserDoNotExist));
                }

                user.ForgotPasswordFlag = true;
                user.ForgotPasswordCode = Functions.GenerateCode().ToString();
                unitOfWork.Users.Update(user);
                var saveResponse = unitOfWork.Complete();

                if (saveResponse.Equals(Integers.UnsuccessfullDatabaseSave))
                {
                    return(ReturnStatements.FailedResponse(DynamicListForResponse.Create(forgotPasswordDto)));
                }

                SendMail(forgotPasswordDto.Handle, user.ForgotPasswordCode, user.EmailId, true);
                return(ReturnStatements.SuccessResponse(DynamicListForResponse.Create(forgotPasswordDto)));
            }
        }
예제 #3
0
        /// <summary>
        /// Method to add user to database.
        /// </summary>
        /// <param name="newUserDto">newUserDto contains personal information of user and user id and password.</param>
        /// <returns>ResponseModel of user addition in database.</returns>
        public ResponseModel Add(UserDto newUserDto)
        {
            var validationStatus = ValidateRequest.ValidateUserDto(newUserDto);

            if (!(bool)validationStatus.First)
            {
                return(ReturnStatements.BadRequestResponse(validationStatus.Second));
            }
            newUserDto = validationStatus.Second;
            using (var unitOfWork = new UnitOfWork())
            {
                var checkIfUserAlreadyExist = unitOfWork.Users.Find(m => m.Handle.Equals(newUserDto.Handle) || m.EmailId.Equals(newUserDto.EmailId)) != null;

                if (checkIfUserAlreadyExist)
                {
                    return(ReturnStatements.BadRequestResponse(Strings.UserAlreadyExist));
                }
                var dbUser         = DtoToDatabase.User(newUserDto);
                var loginDto       = new LoginDto(loginHandle: newUserDto.Handle, loginPassword: newUserDto.Password);
                var dbUserPassword = DtoToDatabase.UserPassword(loginDto, dbUser.Id);
                dbUserPassword.User = dbUser;
                unitOfWork.UserPasswords.Add(dbUserPassword);

                var saveResponse = unitOfWork.Complete();

                if (saveResponse.Equals(Integers.UnsuccessfullDatabaseSave))
                {
                    return(ReturnStatements.FailedResponse(DynamicListForResponse.Create(loginDto)));
                }

                SendMail(loginDto.LoginHandle, dbUser.VerificationCode, dbUser.EmailId, false);
                return(ReturnStatements.SuccessResponse(DynamicListForResponse.Create(loginDto)));
            }
        }
예제 #4
0
        /// <summary>
        /// Method to reset user password
        /// </summary>
        /// <param name="resetPasswordDto">resetPasswordDto contains information to reset a password for a user</param>
        /// <returns>ResponseModel associated to the status of resetting a user password</returns>
        public ResponseModel ResetPassword(ResetPasswordDto resetPasswordDto)
        {
            var validationStatus = ValidateRequest.ValidateResetPasswordDto(resetPasswordDto);

            if (!(bool)validationStatus.First)
            {
                return(ReturnStatements.BadRequestResponse(validationStatus.Second));
            }

            using (var unitOfWork = new UnitOfWork())
            {
                var userList = unitOfWork.Users.FindOnConstraint(m => m.Handle.Equals(resetPasswordDto.Handle), prop => prop.UserPasswords).ToList();

                //Check if no user exist.
                if (userList.Count.Equals(0))
                {
                    return(ReturnStatements.FailedResponse(Strings.UserDoNotExist));
                }

                //Get user at first index. Since handles are unique , therefore only one record will be fetched from database.
                var user = userList[0];

                if (!user.ForgotPasswordFlag)
                {
                    return(ReturnStatements.FailedResponse(Strings.NoRequestCreated));
                }

                if (user.ForgotPasswordCode.Equals(resetPasswordDto.VerificationCode))
                {
                    user.ForgotPasswordFlag = false;
                    var userPassword     = user.UserPasswords;
                    var passwordToUpdate = userPassword.Where(m => m.Status.Equals(true)).ToList()[0];
                    passwordToUpdate.Password     = resetPasswordDto.Password;
                    passwordToUpdate.CreationDate = Functions.GetCurrentDate();
                    passwordToUpdate.CreationTime = Functions.GetCurrentTime();
                    unitOfWork.Users.Update(user);
                    unitOfWork.UserPasswords.Update(passwordToUpdate);
                    var saveResponse = unitOfWork.Complete();
                    if (saveResponse.Equals(Integers.UnsuccessfullDatabaseSave))
                    {
                        return(ReturnStatements.FailedResponse(DynamicListForResponse.Create(resetPasswordDto)));
                    }
                    return(ReturnStatements.SuccessResponse(DynamicListForResponse.Create(resetPasswordDto)));
                }
                return(ReturnStatements.FailedResponse(Strings.VerificationCodeMismatch));
            }
        }
        /// <summary>
        /// Method to add patient insurance to database.
        /// </summary>
        /// <param name="newpatientInsurance">newpatientInsurance containing required information of patient insurance</param>
        /// <param name="userId">userId is the id of the logged in user who made the request to add a patient insurance</param>
        /// <returns>HttpResponseMessage containing addition status of patient insurance</returns>
        public ResponseModel Add(AddPatientInsurance newPatientInsurance, int userId)
        {
            var validationStatus = ValidateRequest.ValidatePatientInsuranceDto(newPatientInsurance);

            if (!(bool)validationStatus.First)
            {
                return(ReturnStatements.BadRequestResponse(validationStatus.Second));
            }
            newPatientInsurance = validationStatus.Second;
            using (var unitOfWork = new UnitOfWork())
            {
                var dbPatientInsurance = DtoToDatabase.PatientInsurance(new Pair {
                    First = newPatientInsurance, Second = userId
                });
                unitOfWork.PatientInsurances.Add(dbPatientInsurance);
                var saveResponse = unitOfWork.Complete();

                if (saveResponse.Equals(Integers.UnsuccessfullDatabaseSave))
                {
                    return(ReturnStatements.FailedResponse(DynamicListForResponse.Create(newPatientInsurance)));
                }
                return(ReturnStatements.SuccessResponse(DynamicListForResponse.Create(newPatientInsurance)));
            }
        }