public async Task <IActionResult> UpdateUser([FromBody] UserDto user)
        {
            try
            {
                Users users = new Users();
                if (user.UserType == "C")
                {
                    CustomerRegistration customerRegistration = _customerRegistrationService.GetCustomer(user.Id);
                    users = await _usersService.GetUser(customerRegistration.UsersID.Value);
                }
                else if (user.UserType == "M")
                {
                    Merchant merchant = await _merchantService.GetMerchant(user.Id);

                    users = await _usersService.GetUser(merchant.UsersID.Value);
                }
                else if (user.UserType == "N")
                {
                    NaqelUsers naqelUsers = await _naqelUsersService.GetNaqelUser(user.Id);

                    users = await _usersService.GetUser(naqelUsers.UsersID.Value);

                    naqelUsers.FirstName = user.FirstName;
                    naqelUsers.LastName  = user.LastName;
                    naqelUsers.Email     = user.Email;
                    naqelUsers.Address   = user.Address;
                    naqelUsers.Country   = Convert.ToInt32(user.Country);
                    naqelUsers.UserType  = user.NaqelUserType;
                    naqelUsers.Mobile    = user.Mobile;
                    await _naqelUsersService.UpdateNaqelUser(naqelUsers);

                    string _getNaqelUsertypedec = await _lookupTypeValuesService.Getlookupdec(Convert.ToInt32(user.NaqelUserType));

                    await _usersService.UpdateUserType(user.Email, _getNaqelUsertypedec);
                }
                if (users != null)
                {
                    users.Status = user.IsActive == "1" ? 1 : 0;
                }
                await _usersService.UpdateUser(users);

                return(Ok(new GenericResultDto <string> {
                    Result = "User updated successfully"
                }));
            }

            catch (Exception err)
            {
                return(BadRequest(new GenericResultDto <string> {
                    Result = err.Message
                }));
            }
            return(Ok(new GenericResultDto <string> {
                Result = "User updated successfully"
            }));
        }
        public async Task <IActionResult> GetProfileDetails([FromBody] GetProfileDto customerRegistrationDto)
        {
            try
            {
                ProfileDto profileDto = new ProfileDto();
                var        _getUsers  = await _UsersService.UserPWD(new CustomerRegistrationDto { Email = customerRegistrationDto.Email });

                if (_getUsers != null)
                {
                    if (_getUsers.Type.ToUpper() == "C")
                    {
                        strImagePath = _configuration["FilePath:ImagePath"] + "ProfileImages/";
                        string strServerURL = _configuration["FilePath:ServerURL"] + "ProfileImages/";
                        var    _types       = await _CustomerRegistrationService.Authenticate(new CustomerRegistrationDto
                                                                                              { Email = customerRegistrationDto.Email });

                        profileDto.FirstName        = _types.FirstName;
                        profileDto.LastName         = _types.LastName;
                        profileDto.Email            = _types.Email;
                        profileDto.Country          = _types.LookupCountry.Description;
                        profileDto.City             = _types.City;
                        profileDto.Mobile           = _types.Mobile;
                        profileDto.Address          = _types.Address;
                        profileDto.Status           = _getUsers.Status;
                        profileDto.Type             = _getUsers.Type;
                        profileDto.Id               = _getUsers.GUID;
                        profileDto.Customercurrency = _types.LookupCountry.ShortDesc;
                        if (_types.Wallet != null)
                        {
                            profileDto.Wallet = _types.Wallet.Amount;
                        }
                        else
                        {
                            profileDto.Wallet = 0;
                        }
                        if (_types.WalletPoints != null)
                        {
                            profileDto.WalletPoints = _types.WalletPoints.Points;
                        }
                        else
                        {
                            profileDto.WalletPoints = 0;
                        }
                        if ((System.IO.File.Exists(strImagePath + _types.Image + "")))
                        {
                            if (_types.Image == null || _types.Image == "")
                            {
                                profileDto.Image = strServerURL + "Dummy.jpg";
                            }
                            else
                            {
                                profileDto.Image = strServerURL + _types.Image;
                            }
                        }
                        else
                        {
                            profileDto.Image = strServerURL + "Dummy.jpg";
                        }
                    }
                    else if (_getUsers.Type.ToUpper() == "M")
                    {
                        string Categories = string.Empty, SellCountries = string.Empty;
                        MerchantDto.Email = customerRegistrationDto.Email;
                        Merchant Merchant = await _MerchantService.GetMerchantDetails(MerchantDto);

                        strImagePath = _configuration["FilePath:ImagePath"] + "MerchantImages/";
                        string strServerURL = _configuration["FilePath:ServerURL"] + "MerchantImages/";
                        profileDto.FirstName = Merchant.Name;
                        profileDto.Email     = Merchant.Email;
                        profileDto.Company   = Merchant.Company;
                        profileDto.Website   = Merchant.Website;
                        profileDto.Email     = Merchant.Email;
                        profileDto.Status    = _getUsers.Status;
                        profileDto.Type      = _getUsers.Type;
                        profileDto.Id        = Merchant.Id;
                        profileDto.MerchantRedirectionUrl = Merchant.MerchantRedirectionUrl;
                        profileDto.Country = Merchant.LookupCountry.Description;
                        profileDto.Company = Merchant.Company;

                        //foreach (var MerchantCategoryItem in Merchant.MerchantCategory)
                        //{
                        //    Categories += MerchantCategoryItem.Category.Name + ",";
                        //}
                        //foreach (var MerchantSellCountriesItem in Merchant.MerchantSellCountries)
                        //{
                        //    SellCountries += MerchantSellCountriesItem.LookupTypeValues.Description + ",";
                        //}


                        List <ProfileCategoriesDto> profileCategoriesList = new List <ProfileCategoriesDto>();
                        foreach (var CategoriesIteams in Merchant.MerchantCategory)
                        {
                            ProfileCategoriesDto ProfileCategories = new ProfileCategoriesDto();
                            ProfileCategories.CategoryId   = CategoriesIteams.Category.Id;
                            ProfileCategories.CategoryName = CategoriesIteams.Category.Name;
                            profileCategoriesList.Add(ProfileCategories);
                        }

                        List <ProfileSellCountriesDto> ProfileSellCountriesList = new List <ProfileSellCountriesDto>();
                        foreach (var SellCountriesIteams in Merchant.MerchantSellCountries)
                        {
                            ProfileSellCountriesDto ProfileSellCountries = new ProfileSellCountriesDto();
                            ProfileSellCountries.SellCountryId   = SellCountriesIteams.LookupTypeValues.Id;
                            ProfileSellCountries.SellCountryName = SellCountriesIteams.LookupTypeValues.Description;
                            ProfileSellCountriesList.Add(ProfileSellCountries);
                        }
                        profileDto.Categories    = profileCategoriesList;
                        profileDto.SellCountries = ProfileSellCountriesList;
                        if ((System.IO.File.Exists(strImagePath + Merchant.ProfileImage + "")))
                        {
                            profileDto.ProfileImage = strServerURL + Merchant.ProfileImage;
                        }
                        else
                        {
                            profileDto.ProfileImage = strServerURL + "Dummy.jpg";
                        }
                        if ((System.IO.File.Exists(strImagePath + Merchant.CompanyImage)))
                        {
                            profileDto.CompanyImage = strServerURL + Merchant.CompanyImage;
                        }
                        else
                        {
                            profileDto.CompanyImage = strServerURL + "Dummy.jpg";
                        }
                    }
                    else
                    {
                        objNaqelUsersDto.Email = customerRegistrationDto.Email;
                        NaqelUsers NaqelUsers = await _NaqelUsersService.GetNaqelUserDetails(objNaqelUsersDto);

                        profileDto.FirstName     = NaqelUsers.FirstName;
                        profileDto.LastName      = NaqelUsers.LastName;
                        profileDto.Country       = NaqelUsers.LookupTypeCountry.Description;
                        profileDto.Email         = NaqelUsers.Email;
                        profileDto.Mobile        = NaqelUsers.Mobile;
                        profileDto.Address       = NaqelUsers.Address;
                        profileDto.Status        = _getUsers.Status;
                        profileDto.Type          = _getUsers.Type;
                        profileDto.Id            = NaqelUsers.Id;
                        profileDto.NaqelUserType = NaqelUsers.UserType;
                        strImagePath             = _configuration["FilePath:ImagePath"] + "NaqelUsersImages/";
                        string strServerURL = _configuration["FilePath:ServerURL"] + "NaqelUsersImages/";
                        if ((System.IO.File.Exists(strImagePath + NaqelUsers.Image + "")))
                        {
                            profileDto.Image = strServerURL + NaqelUsers.Image;
                        }
                        else
                        {
                            profileDto.Image = strServerURL + "Dummy.jpg";
                        }
                    }
                    return(Ok(profileDto));
                }
                else
                {
                    return(Ok(new GenericResultDto <string> {
                        Result = "User Profile not found"
                    }));
                }
            }

            catch (Exception err)
            {
                return(BadRequest(new GenericResultDto <string> {
                    Result = err.Message
                }));
            }
        }
        public async Task <IActionResult> UsersLoginAuthenticate([FromBody] LoginDto loginDto)
        {
            try
            {
                var _checkLoginAuthentication = await _UsersService.LoginAuthenticate(new CustomerRegistrationDto
                {
                    Email = loginDto.Email
                });

                if (_checkLoginAuthentication != null)
                {
                    var tokenDto = await _CustomerRegistrationService.GetToken(new TokenDto
                                                                               { Type = _checkLoginAuthentication.Type,
                                                                                 GUID = _checkLoginAuthentication.GUID });

                    if (EncryptionHelper.Decrypt(_checkLoginAuthentication.PWD) == loginDto.PWD)
                    {
                        await _UsersService.UpdateGUID(new CustomerRegistrationDto
                        {
                            Email = loginDto.Email
                        });

                        if (_checkLoginAuthentication.Type == "C")
                        {
                            var _getData = await _CustomerRegistrationService.Authenticate(new CustomerRegistrationDto
                            {
                                Email = loginDto.Email
                            });

                            UsersProfileDto UsersProfileDto = new UsersProfileDto();
                            UsersProfileDto.Id       = _checkLoginAuthentication.Id;
                            UsersProfileDto.Username = _getData.Email;
                            UsersProfileDto.Type     = _checkLoginAuthentication.Type;
                            UsersProfileDto.Status   = _checkLoginAuthentication.Status;
                            UsersProfileDto.GUID     = _checkLoginAuthentication.GUID;
                            UsersProfileDto.token    = tokenDto.Token;
                            return(Ok(new LoginResultDto <UsersProfileDto>
                            {
                                Result = "Success",
                                LoginStatus = _checkLoginAuthentication.Status.ToString(),
                                ReEmail = _getData.Email,
                                ReFirstName = _getData.FirstName,
                                LoginType = _checkLoginAuthentication.Type,
                                ResultData = UsersProfileDto,
                                Token = UsersProfileDto.token
                            }));
                        }

                        else if (_checkLoginAuthentication.Type == "M")
                        {
                            string Categories = string.Empty, SellCountries = string.Empty;
                            MerchantDto.Email = loginDto.Email;
                            strImagePath      = _configuration["FilePath:ImagePath"] + "MerchantImages/";
                            string strServerURL    = _configuration["FilePath:ServerURL"] + "MerchantImages/";
                            var    Merchantdetails = await _MerchantService.GetMerchantDetailsByStatus(MerchantDto);

                            if (Merchantdetails != null)
                            {
                                Merchant Merchant = Merchantdetails;
                                MerchantProfile.Id   = Merchant.Id;
                                MerchantProfile.Name = Merchant.Name;
                                MerchantProfile.MerchantRedirectionUrl = Merchant.MerchantRedirectionUrl;
                                MerchantProfile.Country = Merchant.LookupCountry.Description;
                                foreach (var MerchantCategoryItem in Merchant.MerchantCategory)
                                {
                                    Categories += MerchantCategoryItem.Category.Name + ",";
                                }
                                foreach (var MerchantSellCountriesItem in Merchant.MerchantSellCountries)
                                {
                                    SellCountries += MerchantSellCountriesItem.LookupTypeValues.Description + ",";
                                }
                                MerchantProfile.Categories    = Categories.TrimEnd(',');
                                MerchantProfile.SellCountries = SellCountries.TrimEnd(',');
                                if ((System.IO.File.Exists(strImagePath + Merchant.ProfileImage + "")))
                                {
                                    MerchantProfile.ProfileImage = strServerURL + Merchant.ProfileImage;
                                }
                                else
                                {
                                    MerchantProfile.ProfileImage = strServerURL + "Dummy.jpg";
                                }
                                if ((System.IO.File.Exists(strImagePath + Merchant.CompanyImage)))
                                {
                                    MerchantProfile.ProfileImage = strServerURL + Merchant.CompanyImage;
                                }
                                else
                                {
                                    MerchantProfile.CompanyImage = strServerURL + "Dummy.jpg";
                                }
                                MerchantProfile.Company = Merchant.Company;

                                MerchantProfile.Website = Merchant.Website;
                                MerchantProfile.Email   = Merchant.Email;
                                return(Ok(new LoginResultDto <MerchantProfile>
                                {
                                    Result = "Success",
                                    LoginStatus = _checkLoginAuthentication.Status.ToString(),
                                    ReEmail = Merchant.Email,
                                    ReFirstName = Merchant.Name,
                                    LoginType = _checkLoginAuthentication.Type,
                                    Website = Merchant.Website,
                                    ResultData = MerchantProfile,
                                    Token = tokenDto.Token
                                }));
                            }
                            else
                            {
                                return(Ok(new GenericResultDto <string>
                                {
                                    Result = "Your account is under verification and after successful completion, will send a confirmation e-mail.",
                                    ReEmail = loginDto.Email
                                }));
                            }
                        }
                        else
                        {
                            objNaqelUsersDto.Email = loginDto.Email;
                            NaqelUsers NaqelUsers = await _NaqelUsersService.GetNaqelUserDetails(objNaqelUsersDto);

                            ProfileDto profileDto = new ProfileDto();
                            profileDto.Id        = NaqelUsers.Id;
                            profileDto.FirstName = NaqelUsers.FirstName;
                            profileDto.LastName  = NaqelUsers.LastName;
                            profileDto.Country   = NaqelUsers.LookupTypeCountry.Description;
                            profileDto.Email     = NaqelUsers.Email;
                            profileDto.Mobile    = NaqelUsers.Mobile;
                            profileDto.Address   = NaqelUsers.Address;
                            strImagePath         = _configuration["FilePath:ImagePath"] + "MerchantImages/";
                            string strServerURL = _configuration["FilePath:ServerURL"] + "MerchantImages/";
                            if ((System.IO.File.Exists(strImagePath + NaqelUsers.Image + "")))
                            {
                                profileDto.Image = strServerURL + NaqelUsers.Image;
                            }
                            else
                            {
                                profileDto.Image = strServerURL + "Dummy.jpg";
                            }
                            return(Ok(new LoginResultDto <ProfileDto>
                            {
                                Result = "Success",
                                LoginStatus = _checkLoginAuthentication.Status.ToString(),
                                ReEmail = NaqelUsers.Email,
                                ReFirstName = NaqelUsers.FirstName,
                                LoginType = _checkLoginAuthentication.Type,
                                ResultData = profileDto,
                                Token = tokenDto.Token
                            }));
                        }
                    }
                    else
                    {
                        return(Ok(new GenericResultDto <string>
                        {
                            Result = "Invalid password",
                            ReEmail = loginDto.Email
                        }));
                    }
                }
                else
                {
                    // if (_types != null && _types.Type == "M")
                    //   return BadRequest(new GenericResultDto<string> { Result = "Merchant Sign In Under Process", ReEmail = CustomerRegistrationDto.Email });
                    // else
                    return(Ok(new GenericResultDto <string> {
                        Result = "Invalid email", ReEmail = loginDto.Email
                    }));
                }
            }

            catch (Exception err)
            {
                return(BadRequest(new GenericResultDto <string> {
                    Result = err.Message
                }));
            }
            return(Ok(new GenericResultDto <string> {
                Result = "Valid email"
            }));
        }