public override async void OnNavigatingTo(NavigationParameters parameters)
        {
            await NavigationHelper.ShowLoading();

            GetGamificationPointsResponse currentPoints = new GetGamificationPointsResponse();

            try
            {
                currentPoints.Entity = await CacheAccess.GetSecure <Points>(CacheKeys.POINTS);
            }
            catch
            {
                currentPoints = await _gamificationPointsAppService.GetCurrentGamificationPoints();

                await CacheAccess.InsertSecure <Points>(CacheKeys.POINTS, currentPoints.Entity);
            }
            if (currentPoints.Entity != null)
            {
                GamificationInvitePoints   = currentPoints.Entity.InviteFlower;
                GamificationRegisterPoints = currentPoints.Entity.RegisterNewClients;
                GamificationSalesPoints    = currentPoints.Entity.SalesNumber;
            }

            await NavigationHelper.PopLoading();

            base.OnNavigatingTo(parameters);
        }
Beispiel #2
0
        private async void ExecuteLogin()
        {
            try
            {
                CanExecuteInitial();
                await NavigationHelper.ShowLoading();

                var response = await _userAppService.Login(new LoginRequest()
                {
                    Email    = Login,
                    Origin   = 0,
                    Password = Password
                });

                if (response != null && response.User != null)
                {
                    await CacheAccess.InsertSecure <User>(CacheKeys.USER_KEY, response.User);

                    await CacheAccess.InsertSecure <Guid>(CacheKeys.ACCESS_TOKEN, response.Token);

                    Settings.AccessToken = response.Token.ToString();
                    Settings.UserId      = response.User.UsuarioId.ToString();
                    await _navigationService.NavigateAsync(NavigationSettings.MenuPrincipal);

                    try
                    {
                        Analytics.TrackEvent(InsightsTypeEvents.ActionView, new Dictionary <string, string>
                        {
                            { InsightsPagesNames.LoginPage, InsightsActionNames.LoginSuccess }
                        });
                    }
                    catch { }
                    var teste2 = await _salesAppService.GetUserSalePointsForChallenge(response.User.UsuarioId.ToString());

                    var teste3 = await _clientsAppService.GetUserClientPointsForChallenge(response.User.UsuarioId.ToString());
                }
                else
                {
                    TimeSpan duration = new TimeSpan(0, 0, 2);
                    _userDialogs.Toast("Login ou senha incorretos");
                    throw new Exception("Ocorreu um erro, tente novamente mais tarde.");
                }
            }
            catch (Exception ex)
            {
                Analytics.TrackEvent(InsightsTypeEvents.ActionView, new Dictionary <string, string>
                {
                    { InsightsPagesNames.LoginPage, InsightsActionNames.LoginFailed }
                });
                UserDialogs.Instance.Toast("Não foi possível fazer o Login, verifique sua conexão");
            }
            finally
            {
                await NavigationHelper.PopLoading();

                CanExecuteEnd();
            }
        }
        private async void RegisterNewClient()
        {
            if (!string.IsNullOrEmpty(ClientSelectedForEdition.Name) && !string.IsNullOrEmpty(ClientSelectedForEdition.Email) && !string.IsNullOrEmpty(ClientSelectedForEdition.Telephone) && !string.IsNullOrEmpty(ClientSelectedForEdition.Birthdate.ToString()))
            {
                try
                {
                    await NavigationHelper.ShowLoading();

                    var user = await CacheAccess.GetSecure <User>(CacheKeys.USER_KEY);

                    var userGuid = user.UsuarioId;

                    if (RegisterOrEditText.Contains("CADASTRAR"))
                    {
                        await _clientsAppService.RegisterClient(new RegisterClientRequest()
                        {
                            UsuarioId = userGuid,
                            Birthdate = ClientSelectedForEdition.Birthdate,
                            Cep       = ClientSelectedForEdition.Cep,
                            Email     = ClientSelectedForEdition.Email,
                            Name      = ClientSelectedForEdition.Name,
                            Telephone = ClientSelectedForEdition.Telephone
                        });

                        var myClients = await _clientsAppService.GetClientsByUserId(user.UsuarioId.ToString());

                        await CacheAccess.Insert <List <Client> >(CacheKeys.CLIENTS, myClients.Clients);

                        var points = new GetGamificationPointsResponse();
                        points = await _gamificationPointsAppService.GetCurrentGamificationPoints();

                        await CacheAccess.InsertSecure <Points>(CacheKeys.POINTS, points.Entity);

                        user.RegisterClientsPoints += (int)points.Entity.RegisterNewClients;

                        await _userAppService.UpdateUserPoints(new UpdateUserPointsRequest()
                        {
                            UsuarioId = userGuid,
                            AverageItensPerSalePoints = user.AverageItensPerSalePoints,
                            AverageTicketPoints       = user.AverageTicketPoints,
                            RegisterClientsPoints     = user.RegisterClientsPoints,
                            InviteAllyFlowersPoints   = user.InviteAllyFlowersPoints,
                            SalesNumberPoints         = user.SalesNumberPoints
                        });

                        await CacheAccess.InsertSecure <User>(CacheKeys.USER_KEY, user);
                        await GetParametersForChallenge();

                        TimeSpan duration = new TimeSpan(0, 0, 3);
                        if (!_hasWonTrophy)
                        {
                            UserDialogs.Instance.Toast("Parabéns! Você ganhou " + points.Entity.RegisterNewClients + " Sementes com esse Cadastro!", duration);
                        }
                        try
                        {
                            Analytics.TrackEvent(InsightsTypeEvents.ActionView, new Dictionary <string, string>
                            {
                                { InsightsPagesNames.RegisterClientsPage, InsightsActionNames.AddNewClient }
                            });
                        }
                        catch { }
                    }
                    else
                    {
                        try
                        {
                            await _clientsAppService.UpdateClientInfo(new UpdateClientInfoRequest()
                            {
                                ClienteId = ClientSelectedForEdition.ClienteId,
                                Birthdate = ClientSelectedForEdition.Birthdate,
                                Cep       = ClientSelectedForEdition.Cep,
                                Email     = ClientSelectedForEdition.Email,
                                Name      = ClientSelectedForEdition.Name,
                                Telephone = ClientSelectedForEdition.Telephone
                            });

                            var myClients = await _clientsAppService.GetClientsByUserId(user.UsuarioId.ToString());

                            await CacheAccess.Insert <List <Client> >(CacheKeys.CLIENTS, myClients.Clients);
                        }
                        catch
                        {
                            UserDialogs.Instance.Toast("Não foi possível editar sua cliente, verifique sua conexão!");
                        }
                        UserDialogs.Instance.Toast("Colecionadora editada com sucesso!");
                        try
                        {
                            Analytics.TrackEvent(InsightsTypeEvents.ActionView, new Dictionary <string, string>
                            {
                                { InsightsPagesNames.RegisterClientsPage, InsightsActionNames.EditClient }
                            });
                        }
                        catch { }
                    }
                }
                catch (Exception ex)
                {
                    if (RegisterOrEditText.Contains("CADASTRAR"))
                    {
                        UserDialogs.Instance.Toast(ex.Message);
                    }
                    else
                    {
                        UserDialogs.Instance.Toast("Não foi possível editar a Colecionadora.");
                    }
                }
                finally
                {
                    await NavigationHelper.PopLoading();

                    if (!_cameFromClientsForSale)
                    {
                        await _navigationService.NavigateAsync(NavigationSettings.MenuPrincipal);
                    }
                    else
                    {
                        await _navigationService.GoBackAsync();
                    }
                }
            }
            else
            {
                TimeSpan duration = new TimeSpan(0, 0, 2);
                _userDialogs.Toast("Insira todos os dados obrigatórios.", duration);
            }
        }
        private async Task CheckRegisterChallengeCompleted(List <Trophy> myTrophies, string usuarioId, List <Challenge> currentChallenges, Season CurrentSeason)
        {
            try
            {
                int myRegisterPoints = 0;
                var user             = await CacheAccess.GetSecure <User>(CacheKeys.USER_KEY);

                try
                {
                    myRegisterPoints = await CacheAccess.Get <int>(CacheKeys.REGISTER_POINTS_FOR_CHALLENGE);
                }
                catch
                {
                    myRegisterPoints = await _clientsAppService.GetUserClientPointsForChallenge(usuarioId);

                    await CacheAccess.Insert <int>(CacheKeys.REGISTER_POINTS_FOR_CHALLENGE, myRegisterPoints);
                }

                foreach (var challenge in currentChallenges)
                {
                    bool _hasTrophy        = false;
                    bool _hasEnoughtPoints = false;
                    if (challenge.Parameter == 3)
                    {
                        foreach (var trophy in myTrophies)
                        {
                            if (trophy.DesafioId.ToString() == challenge.DesafioId.ToString())
                            {
                                _hasTrophy = true;
                                break;
                            }
                        }
                        _hasEnoughtPoints = (myRegisterPoints >= challenge.Goal) ? true : false;
                    }
                    if (!_hasTrophy && _hasEnoughtPoints)
                    {
                        await _trophyAppService.InsertNewTrophy(new InsertTrophyRequest
                        {
                            DesafioId   = challenge.DesafioId,
                            EndDate     = challenge.EndDate,
                            StartDate   = challenge.StartDate,
                            Goal        = challenge.Goal,
                            Name        = challenge.Name,
                            Parameter   = challenge.Parameter,
                            TemporadaId = CurrentSeason.TemporadaId,
                            UsuarioId   = new Guid(usuarioId),
                            Prize       = challenge.Prize
                        });

                        await _userAppService.UpdateUserPoints(new UpdateUserPointsRequest()
                        {
                            AverageItensPerSalePoints = user.AverageItensPerSalePoints,
                            AverageTicketPoints       = user.AverageTicketPoints,
                            InviteAllyFlowersPoints   = user.InviteAllyFlowersPoints,
                            RegisterClientsPoints     = user.RegisterClientsPoints + challenge.Prize,
                            SalesNumberPoints         = user.SalesNumberPoints,
                            UsuarioId = user.UsuarioId
                        });

                        await CacheAccess.InsertSecure <User>(CacheKeys.USER_KEY, user);

                        _hasWonTrophy = true;
                        UserDialogs.Instance.Toast("Você acabou de ganhar um Troféu de Cadastro de Clientes! Parabéns!", new TimeSpan(0, 0, 4));
                    }
                }
            }
            catch { }
        }
        private async void SendEmail()
        {
            string MensagemPadrão = "Testando o envio de email";

            try
            {
                TimeSpan duration = new TimeSpan(0, 0, 2);
                if (string.IsNullOrEmpty(Email) || string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(Cpf) || string.IsNullOrEmpty(PrimaryTelephone))
                {
                    _userDialogs.Toast("Dados Incompletos!", duration);
                }

                else
                {
                    await NavigationHelper.ShowLoading();

                    var user = await CacheAccess.GetSecure <User>(CacheKeys.USER_KEY);

                    var userGuid = user.UsuarioId;

                    var email_name = new Dictionary <string, string>();
                    email_name.Add(Email, user.Name);
                    await _userAppService.SendEmail(Email, Name, user.Name, Cpf, PrimaryTelephone, Cep, user.Email);

                    var points = await CacheAccess.GetSecure <Points>(CacheKeys.POINTS);

                    user.InviteAllyFlowersPoints += points.InviteFlower;

                    await _userAppService.UpdateUserPoints(new UpdateUserPointsRequest()
                    {
                        UsuarioId = userGuid,
                        AverageItensPerSalePoints = user.AverageItensPerSalePoints,
                        AverageTicketPoints       = user.AverageTicketPoints,
                        RegisterClientsPoints     = user.RegisterClientsPoints,
                        InviteAllyFlowersPoints   = user.InviteAllyFlowersPoints,
                        SalesNumberPoints         = user.SalesNumberPoints
                    });

                    await CacheAccess.InsertSecure <User>(CacheKeys.USER_KEY, user);

                    try
                    {
                        Analytics.TrackEvent(InsightsTypeEvents.ActionView, new Dictionary <string, string>
                        {
                            { InsightsPagesNames.LoginPage, InsightsActionNames.ForgotPassword }
                        });
                    }
                    catch { }
                    _userDialogs.Toast("Email enviado com Sucesso! Você ganhou " + points.InviteFlower + " Sementes com o convite!", duration);
                }
            }
            catch (Exception ex)
            {
                _userDialogs.Toast("Não foi possível enviar o convite, verifique sua conexão com a internet!");
            }
            finally
            {
                await NavigationHelper.PopLoading();

                await _navigationService.NavigateAsync(NavigationSettings.MenuPrincipal);
            }
        }
Beispiel #6
0
        private async void SaveSale()
        {
            TimeSpan duration = new TimeSpan(0, 0, 3);

            if (IsSaleValid())
            {
                await NavigationHelper.ShowLoading();

                if (!_isEditSale)
                {
                    CanExecuteInitial();
                    try
                    {
                        var user = await CacheAccess.GetSecure <User>(CacheKeys.USER_KEY);

                        var userGuid = user.UsuarioId;

                        Analytics.TrackEvent(InsightsTypeEvents.ActionView, new Dictionary <string, string>
                        {
                            { InsightsPagesNames.RegisterSalePage, InsightsActionNames.SaveSale }
                        });

                        await _salesAppService.InsertNewSale(new InsertNewSaleRequest
                        {
                            UsuarioId        = userGuid,
                            UserName         = user.Name,
                            ClienteId        = SaleRegistered.ClienteId,
                            ClientName       = SaleRegistered.ClientName,
                            NumberSoldPieces = SaleRegistered.NumberSoldPieces,
                            SaleDate         = DateTime.Now,
                            SalePaidValue    = SaleRegistered.SalePaidValue,
                            SaleValue        = SaleRegistered.SaleValue,
                            Description      = SaleRegistered.Description
                        });

                        var userSales = await SaveNewSaleInCache();

                        float salesValue        = 0;
                        int   salesCount        = 0;
                        int   salesNumberPieces = 0;
                        foreach (var sale in userSales.Sales)
                        {
                            salesValue        += sale.SaleValue;
                            salesNumberPieces += sale.NumberSoldPieces;
                            salesCount++;
                        }
                        int AverageTicketPoints = (int)salesValue / salesCount;
                        int AverageItensPerSale = salesNumberPieces / salesCount;

                        GetGamificationPointsResponse currentPoints = new GetGamificationPointsResponse();
                        try
                        {
                            currentPoints.Entity = await CacheAccess.GetSecure <Points>(CacheKeys.POINTS);
                        }
                        catch
                        {
                            currentPoints = await _gamificationPointsAppService.GetCurrentGamificationPoints();

                            await CacheAccess.InsertSecure <Points>(CacheKeys.POINTS, currentPoints.Entity);
                        }
                        user.AverageItensPerSalePoints = AverageItensPerSale;
                        user.AverageTicketPoints      += AverageTicketPoints;
                        user.SalesNumberPoints        += (int)currentPoints.Entity.SalesNumber;

                        await _userAppService.UpdateUserPoints(new UpdateUserPointsRequest()
                        {
                            UsuarioId = userGuid,
                            AverageItensPerSalePoints = user.AverageItensPerSalePoints,
                            AverageTicketPoints       = user.AverageTicketPoints,
                            RegisterClientsPoints     = user.RegisterClientsPoints,
                            InviteAllyFlowersPoints   = user.InviteAllyFlowersPoints,
                            SalesNumberPoints         = user.SalesNumberPoints
                        });

                        await CacheAccess.InsertSecure <User>(CacheKeys.USER_KEY, user);
                        await GetParametersForChallenge();

                        if (!_hasWonTrophy)
                        {
                            UserDialogs.Instance.Toast("Parabéns! Você ganhou " + currentPoints.Entity.SalesNumber + " Sementes com essa Venda!", duration);
                        }
                        await _navigationService.NavigateAsync(NavigationSettings.MenuPrincipal);
                    }
                    catch
                    {
                        _userDialogs.Toast("Não foi possível registrar sua venda");
                    }
                    finally
                    {
                        CanExecuteEnd();
                        await NavigationHelper.PopLoading();
                    }
                }
                else
                {
                    try
                    {
                        await _salesAppService.UpdateSale(SaleRegistered.VendaId.ToString(), SaleRegistered.SaleValue, SaleRegistered.SalePaidValue, SaleRegistered.NumberSoldPieces, SaleRegistered.Description);

                        var userSales = await SaveNewSaleInCache();

                        _userDialogs.Toast("Venda Editada com sucesso!");
                    }
                    catch
                    {
                        _userDialogs.Toast("Não foi possível editar sua venda!");
                    }
                    finally
                    {
                        await NavigationHelper.PopLoading();

                        await _navigationService.GoBackAsync();
                    }
                }
            }
            else
            {
                _userDialogs.Toast("Faltam Dados para preencher!", duration);
            }
        }