Exemplo n.º 1
0
        public override AbstractDomainModel Query(AbstractDomainModel domainModel, DomainModelEnum domainModelType)
        {
            try
            {
                if (domainModel != null)
                {
                    switch (domainModelType)
                    {
                    case DomainModelEnum.AUTHENTICATE:
                        authenticate = (DomainModel.Models.Authenticate)domainModel;
                        if (authenticate.Email == null || authenticate.Email.Length <= 0)
                        {
                            authenticate.ResponseMessage = "Email is required";
                        }
                        else if (authenticate.Password == null || authenticate.Password.Length <= 0)
                        {
                            authenticate.ResponseMessage = "Password is required";
                        }
                        else
                        {
                            FactoryFacade factory = new FactoryFacade();
                            unitOfWork   = factory.UnitOfWorkFactory.CreateUnitOfWork(typeof(JunkCar.UnitOfWork.UOWs.AccountsUOW));
                            authenticate = (DomainModel.Models.Authenticate)unitOfWork.Get(authenticate, OperationTypeEnum.AUTHENTICATE);
                            authenticate.ResponseMessage = "Valid";
                        }
                        break;

                    case DomainModelEnum.GET_SECURITY_QUESTION:
                        forgotPassword = (DomainModel.Models.ForgotPassword)domainModel;
                        if (forgotPassword.UserId == null || forgotPassword.UserId.Length <= 0)
                        {
                            forgotPassword.ResponseMessage = "User id is required";
                        }
                        else
                        {
                            FactoryFacade factory = new FactoryFacade();
                            unitOfWork     = factory.UnitOfWorkFactory.CreateUnitOfWork(typeof(JunkCar.UnitOfWork.UOWs.AccountsUOW));
                            forgotPassword = (DomainModel.Models.ForgotPassword)unitOfWork.Get(forgotPassword, OperationTypeEnum.GET_SECURITY_QUESTION);
                            forgotPassword.ResponseMessage = "Valid";
                        }
                        break;

                    case DomainModelEnum.CHECK_SECURITY_QUESTION_ANSWER:
                        forgotPassword = (DomainModel.Models.ForgotPassword)domainModel;
                        if (forgotPassword.SecurityQuestionAnswer == null || forgotPassword.SecurityQuestionAnswer.Length <= 0)
                        {
                            forgotPassword.ResponseMessage = "Please answer the given question";
                        }
                        else
                        {
                            FactoryFacade factory = new FactoryFacade();
                            unitOfWork     = factory.UnitOfWorkFactory.CreateUnitOfWork(typeof(JunkCar.UnitOfWork.UOWs.AccountsUOW));
                            forgotPassword = (DomainModel.Models.ForgotPassword)unitOfWork.Get(forgotPassword, OperationTypeEnum.CHECK_SECURITY_QUESTION_ANSWER);
                        }
                        break;

                    case DomainModelEnum.CHECK_VERIFICATION_CODE:
                        forgotPassword = (DomainModel.Models.ForgotPassword)domainModel;
                        if (forgotPassword.VerificationCode == 0)
                        {
                            forgotPassword.ResponseMessage = "Please enter the given verification code";
                        }
                        else
                        {
                            FactoryFacade factory = new FactoryFacade();
                            unitOfWork     = factory.UnitOfWorkFactory.CreateUnitOfWork(typeof(JunkCar.UnitOfWork.UOWs.AccountsUOW));
                            forgotPassword = (DomainModel.Models.ForgotPassword)unitOfWork.Get(forgotPassword, OperationTypeEnum.CHECK_VERIFICATION_CODE);
                        }
                        break;

                    case DomainModelEnum.RESET_PASSWORD:
                        forgotPassword = (DomainModel.Models.ForgotPassword)domainModel;
                        if (forgotPassword.NewPassword == null || forgotPassword.NewPassword.Length <= 0)
                        {
                            forgotPassword.ResponseMessage = "Please enter new password";
                        }
                        else
                        {
                            FactoryFacade factory = new FactoryFacade();
                            unitOfWork     = factory.UnitOfWorkFactory.CreateUnitOfWork(typeof(JunkCar.UnitOfWork.UOWs.AccountsUOW));
                            forgotPassword = (DomainModel.Models.ForgotPassword)unitOfWork.Get(forgotPassword, OperationTypeEnum.RESET_PASSWORD);
                        }
                        break;

                    case DomainModelEnum.CHECK_USER_ID:
                        authenticate = (DomainModel.Models.Authenticate)domainModel;
                        if (authenticate.Email == null || authenticate.Email.Length <= 0)
                        {
                            authenticate.ResponseMessage = "Please enter valid email";
                        }
                        else
                        {
                            FactoryFacade factory = new FactoryFacade();
                            unitOfWork   = factory.UnitOfWorkFactory.CreateUnitOfWork(typeof(JunkCar.UnitOfWork.UOWs.AccountsUOW));
                            authenticate = (DomainModel.Models.Authenticate)unitOfWork.Get(authenticate, OperationTypeEnum.CHECK_USER_ID);
                        }
                        break;

                    case DomainModelEnum.GET_USER_INFO:
                        userProfile = (DomainModel.Models.UserProfile)domainModel;
                        if (userProfile.UserId == null || userProfile.UserId.Length <= 0)
                        {
                            userProfile.ResponseMessage = "Please enter valid email";
                        }
                        else
                        {
                            FactoryFacade factory = new FactoryFacade();
                            unitOfWork  = factory.UnitOfWorkFactory.CreateUnitOfWork(typeof(JunkCar.UnitOfWork.UOWs.AccountsUOW));
                            userProfile = (DomainModel.Models.UserProfile)unitOfWork.Get(userProfile, OperationTypeEnum.GET_USER_INFO);
                        }
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    switch (domainModelType)
                    {
                    case DomainModelEnum.AUTHENTICATE:
                        authenticate.ResponseMessage = "Invalid domain model";
                        break;

                    case DomainModelEnum.GET_SECURITY_QUESTION:
                        forgotPassword.ResponseMessage = "Invalid domain model";
                        break;

                    case DomainModelEnum.CHECK_SECURITY_QUESTION_ANSWER:
                        forgotPassword.ResponseMessage = "Invalid domain model";
                        break;

                    case DomainModelEnum.CHECK_VERIFICATION_CODE:
                        forgotPassword.ResponseMessage = "Invalid domain model";
                        break;

                    case DomainModelEnum.RESET_PASSWORD:
                        forgotPassword.ResponseMessage = "Invalid domain model";
                        break;

                    case DomainModelEnum.CHECK_USER_ID:
                        authenticate.ResponseMessage = "Invalid domain model";
                        break;

                    case DomainModelEnum.GET_USER_INFO:
                        userProfile.ResponseMessage = "Invalid domain model";
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                switch (domainModelType)
                {
                case DomainModelEnum.AUTHENTICATE:
                    authenticate.ResponseMessage = ex.Message;
                    break;

                case DomainModelEnum.GET_SECURITY_QUESTION:
                    forgotPassword.ResponseMessage = ex.Message;
                    break;

                case DomainModelEnum.CHECK_SECURITY_QUESTION_ANSWER:
                    forgotPassword.ResponseMessage = ex.Message;
                    break;

                case DomainModelEnum.CHECK_VERIFICATION_CODE:
                    forgotPassword.ResponseMessage = ex.Message;
                    break;

                case DomainModelEnum.RESET_PASSWORD:
                    forgotPassword.ResponseMessage = ex.Message;
                    break;

                case DomainModelEnum.CHECK_USER_ID:
                    authenticate.ResponseMessage = ex.Message;
                    break;

                case DomainModelEnum.GET_USER_INFO:
                    userProfile.ResponseMessage = ex.Message;
                    break;

                default:
                    break;
                }
            }
            switch (domainModelType)
            {
            case DomainModelEnum.AUTHENTICATE:
                return(authenticate);

            case DomainModelEnum.GET_SECURITY_QUESTION:
                return(forgotPassword);

            case DomainModelEnum.CHECK_SECURITY_QUESTION_ANSWER:
                return(forgotPassword);

            case DomainModelEnum.CHECK_VERIFICATION_CODE:
                return(forgotPassword);

            case DomainModelEnum.RESET_PASSWORD:
                return(forgotPassword);

            case DomainModelEnum.CHECK_USER_ID:
                return(authenticate);

            case DomainModelEnum.GET_USER_INFO:
                return(userProfile);

            default:
                break;
            }
            return(null);
        }
        public override AbstractDomainModel Update(AbstractDomainModel domainModel, CareHub.Factory.Enumerations.DomainModelEnum domainModelType)
        {
            DomainModel.Models.ChangePassword changePassword = (DomainModel.Models.ChangePassword)domainModel;
            DomainModel.Models.ForgotPassword forgotPassword = (DomainModel.Models.ForgotPassword)domainModel;
            DomainModel.Models.EditProfile    editProfile    = (DomainModel.Models.EditProfile)domainModel;
            try
            {
                if (domainModel != null)
                {
                    switch (domainModelType)
                    {
                    case CareHub.Factory.Enumerations.DomainModelEnum.CHANGE_PASSWORD:
                        if (changePassword.CurrentPassword == null || changePassword.CurrentPassword.Length <= 0)
                        {
                            changePassword.ResponseMessage = "Current password is required.";
                        }
                        else if (changePassword.NewPassword == null || changePassword.NewPassword.Length <= 0)
                        {
                            changePassword.ResponseMessage = "New password is required.";
                        }
                        else
                        {
                            FactoryFacade factory = new FactoryFacade();
                            unitOfWork = factory.UnitOfWorkFactory.CreateUnitOfWork(typeof(CareHub.UnitOfWork.ChangePasswordUOW));
                            unitOfWork.Update(changePassword);
                            unitOfWork.Commit();
                            CareHub.Core.ConfigurationEmails.ConfigurationEmail.ChangePasswordEmail(changePassword.UserId, changePassword.NewPassword, changePassword.UserId);
                            changePassword.ResponseMessage = "Password changed successfully";
                        }
                        break;

                    case CareHub.Factory.Enumerations.DomainModelEnum.FORGOT_PASSWORD:
                        //  if (forgotPassword.CurrentPassword == null || forgotPassword.CurrentPassword.Length <= 0)
                        // { message = "Current password is required"; }
                        if (forgotPassword.NewPassword == null || forgotPassword.NewPassword.Length <= 0)
                        {
                            forgotPassword.ResponseMessage = "New password is required";
                        }
                        else
                        {
                            FactoryFacade factory = new FactoryFacade();
                            unitOfWork = factory.UnitOfWorkFactory.CreateUnitOfWork(typeof(CareHub.UnitOfWork.ForgotPasswordUOW));
                            unitOfWork.Update(forgotPassword);
                            unitOfWork.Commit();

                            /*  DomainModel.Models.ProviderRegistration providerRegistration = new DomainModel.Models.ProviderRegistration();
                             * unitOfWork = factory.UnitOfWorkFactory.CreateUnitOfWork(typeof(CareHub.UnitOfWork.ProviderRegistrationUOW));
                             * providerRegistration = (DomainModel.Models.ProviderRegistration)unitOfWork.Get(providerRegistration);
                             */
                            CareHub.Core.ConfigurationEmails.ConfigurationEmail.ForgotPasswordEmail(forgotPassword.UserId, forgotPassword.NewPassword, forgotPassword.UserId);
                            forgotPassword.ResponseMessage = "New password has been sent successfully";
                        }
                        break;

                    case CareHub.Factory.Enumerations.DomainModelEnum.EDIT_PROFILE:
                        if (editProfile.FirstName == null || editProfile.FirstName.Length <= 0)
                        {
                            editProfile.ResponseMessage = "First name is required.";
                        }
                        else if (editProfile.Gender == 0)
                        {
                            editProfile.ResponseMessage = "Gender is required.";
                        }
                        else if (editProfile.CountryId == 0)
                        {
                            editProfile.ResponseMessage = "Country is required.";
                        }
                        else if (editProfile.StateId == 0)
                        {
                            editProfile.ResponseMessage = "State is required.";
                        }
                        else if (editProfile.CityId == 0)
                        {
                            editProfile.ResponseMessage = "City is required.";
                        }
                        else if (editProfile.LocalityId == 0)
                        {
                            editProfile.ResponseMessage = "Locality is required.";
                        }
                        else
                        {
                            /////////
                            FactoryFacade factory = new FactoryFacade();
                            unitOfWork = factory.UnitOfWorkFactory.CreateUnitOfWork(typeof(CareHub.UnitOfWork.ChangePasswordUOW));
                            unitOfWork.Update(editProfile);
                            unitOfWork.Commit();
                            editProfile.ResponseMessage = "Profile updated successfully.";
                        }
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    switch (domainModelType)
                    {
                    case CareHub.Factory.Enumerations.DomainModelEnum.CHANGE_PASSWORD:
                        changePassword.ResponseMessage = "Invalid domain model.";
                        break;

                    case CareHub.Factory.Enumerations.DomainModelEnum.FORGOT_PASSWORD:
                        forgotPassword.ResponseMessage = "Invalid domain model.";
                        break;

                    case CareHub.Factory.Enumerations.DomainModelEnum.EDIT_PROFILE:
                        editProfile.ResponseMessage = "Invalid domain model.";
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                switch (domainModelType)
                {
                case CareHub.Factory.Enumerations.DomainModelEnum.CHANGE_PASSWORD:
                    changePassword.ResponseMessage = ex.Message;
                    break;

                case CareHub.Factory.Enumerations.DomainModelEnum.FORGOT_PASSWORD:
                    forgotPassword.ResponseMessage = ex.Message;
                    break;

                case CareHub.Factory.Enumerations.DomainModelEnum.EDIT_PROFILE:
                    editProfile.ResponseMessage = ex.Message;
                    break;

                default:
                    break;
                }
            }
            switch (domainModelType)
            {
            case CareHub.Factory.Enumerations.DomainModelEnum.CHANGE_PASSWORD:
                return(changePassword);

            case CareHub.Factory.Enumerations.DomainModelEnum.FORGOT_PASSWORD:
                return(forgotPassword);

            case CareHub.Factory.Enumerations.DomainModelEnum.EDIT_PROFILE:
                return(editProfile);

            default:
                break;
            }
            return(null);
        }