Пример #1
0
        private async Task GetClients()
        {
            await NavigationHelper.ShowLoading();

            ListaClientes.Clear();
            try
            {
                var user = await CacheAccess.GetSecure <User>(CacheKeys.USER_KEY);

                var clients = await TryGetClientsFromCache();

                foreach (var client in clients.Clients)
                {
                    ListaClientes.Add(client);
                }
                NoData = ListaClientes.Count < 1 ? true : false;
            }
            catch
            {
                UserDialogs.Instance.Toast("Não foi possível carregar os clientes");
                await _navigationService.NavigateAsync(NavigationSettings.MenuPrincipal);
            }
            finally
            {
                await NavigationHelper.PopLoading();
            }
        }
Пример #2
0
        private async void GoToMyTrophies()
        {
            CanExecuteInitial();
            await NavigationHelper.ShowLoading();
            var parameter = new NavigationParameters();
            try
            {
                var user = await CacheAccess.GetSecure<User>(CacheKeys.USER_KEY);
                var myTrophies = await _trophyAppService.GetCurrentTrophies(user.UsuarioId.ToString());
                parameter.Add(NavigationKeyParameters.MyTrophies, myTrophies.Trophies);
                if (myTrophies.Trophies.Count < 1)
                {
                    _userDialogs.Toast("Você não possui Troféus!", new TimeSpan(0, 0, 3));
                }
                else
                {
                    await _navigationService.NavigateAsync(NavigationSettings.TrophyRoom, parameter);
                }

            }
            catch
            {
                _userDialogs.Toast("Não foi possível carregar seus troféus, verifique sua conexão.", new TimeSpan(0, 0, 3));
            }
            finally
            {
                await NavigationHelper.PopLoading();
                CanExecuteEnd();
            }
        }
Пример #3
0
        public override async void OnNavigatingTo(NavigationParameters parameters)
        {
            if (parameters.ContainsKey(NavigationKeyParameters.SelectedSale))
            {
                ButtonText       = "EDITAR VENDA";
                SaleRegistered   = parameters[NavigationKeyParameters.SelectedSale] as Sale;
                NameAndDateLabel = "Venda para: " + SaleRegistered.ClientName + ", " + Formatter.FormatDate(SaleRegistered.SaleDate);
                _isEditSale      = true;
            }
            else if (parameters.ContainsKey(NavigationKeyParameters.SelectedClient))
            {
                ButtonText = "SALVAR VENDA";
                Client selectedClient = (Client)parameters[NavigationKeyParameters.SelectedClient];
                SaleRegistered.ClienteId  = selectedClient.ClienteId;
                SaleRegistered.ClientName = selectedClient.Name;
                _isEditSale = false;

                try
                {
                    CurrentUser = await CacheAccess.GetSecure <User>(CacheKeys.USER_KEY);

                    SaleRegistered.UsuarioId = CurrentUser.UsuarioId;
                }
                catch
                {
                    _userDialogs.Toast("Tivemos um problema com seu usuário, faça o Login novamente!");
                }
                NameAndDateLabel = "Venda para: " + SaleRegistered.ClientName + ", " + Formatter.FormatDate(DateTime.Now);
            }
            if (SaleRegistered != null && SaleRegistered.Description != null)
            {
                DescriptionPlaceHolderVisible = (SaleRegistered.Description.Length > 0) ? false : true;
            }
            base.OnNavigatingTo(parameters);
        }
        public override async void OnNavigatedTo(NavigationParameters parameters)
        {
            base.OnNavigatedTo(parameters);

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

                invitePoints = await _userAppService.GetUserInvitePointsForChallenge(user.UsuarioId.ToString());

                registerPoints = await _clientsAppService.GetUserClientPointsForChallenge(user.UsuarioId.ToString());

                salesPoints = await _salesAppService.GetUserSalePointsForChallenge(user.UsuarioId.ToString());
            }
            catch
            {
                await NavigationService.GoBackAsync();

                UserDialogs.Instance.Toast("Não foi possivel carregar os desafios, verifique sua conexão.");
            }

            if (parameters.ContainsKey(NavigationKeyParameters.CurrentChallenges))
            {
                foreach (var challenge in ((List <Challenge>)parameters[NavigationKeyParameters.CurrentChallenges]))
                {
                    Challenges.Add(challenge);
                    challenge.StartDateFormatted = Formatter.FormatDate(challenge.StartDate);
                    challenge.EndDateFormatted   = Formatter.FormatDate(challenge.EndDate);
                    challenge.ParameterFormatted = Formatter.FormatChallengeType((ChallengeType)challenge.Parameter);
                    challenge.CurrentSituation   = GetCurrentSituationMissingPoints((ChallengeType)challenge.Parameter, challenge.Goal);
                    challenge.PrizeFormatted     = challenge.Prize.ToString();
                }
            }
            await NavigationHelper.PopLoading();
        }
        private async void SendEmail()
        {
            CanExecuteInitial();

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

                foreach (var client in Birthdays)
                {
                    await _userAppService.SendBirthdayEmail(client.Email, user.Name);
                }
                UserDialogs.Instance.Toast("Email(s) enviado(s) com sucesso!");
                await PopupAnniversaryHelper.EsconderAsync();
            }
            catch
            {
                UserDialogs.Instance.Toast("Não foi possível enviar os emails, verifique sua conexão.");
            }
            finally
            {
                await NavigationHelper.PopLoading();
            }
            CanExecuteEnd();
        }
        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);
        }
Пример #7
0
        private async void Confirm()
        {
            try
            {
                await NavigationHelper.ShowLoading();

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

                await _userAppService.Logout(user.UsuarioId.ToString());

                await CacheAccess.DeleteAll();

                await _navigationService.NavigateAsync(NavigationSettings.AbsoluteLogin);

                try
                {
                    Analytics.TrackEvent(InsightsTypeEvents.ActionView, new Dictionary <string, string>
                    {
                        { InsightsPagesNames.LoginPage, InsightsActionNames.Logout }
                    });
                }
                catch { }
            }
            catch (Exception ex)
            {
                _userDialogs.Toast(ex.Message);
                await NavigationHelper.PopLoading();
            }
            finally
            {
                await NavigationHelper.PopLoading();
            }
        }
Пример #8
0
        private async Task <GetSalesByUserIdResponse> SaveNewSaleInCache()
        {
            var sales = new GetSalesByUserIdResponse();

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

                sales = await _salesAppService.GetSalesByUserId(user.UsuarioId.ToString());

                await CacheAccess.Insert <List <Sale> >(CacheKeys.SALES, sales.Sales);
            }
            catch
            { }
            return(sales);
        }
        private async Task GetParametersForChallenge()
        {
            var user = new User();
            var currentSeasonReponse = new SeasonResponse();
            var currentChallenges    = new GetCurrentChallengesResponse();
            var myTrophies           = new GetThophiesByUserIdResponse();

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

            try
            {
                currentSeasonReponse = await _seasonAppService.CurrentSeason();
            }
            catch
            {}
            await CheckRegisterChallengeCompleted(myTrophies.Trophies, user.UsuarioId.ToString(), currentChallenges.Challenges, currentSeasonReponse.Entity);
        }
Пример #10
0
        private async Task <GetClientsByUserIdResponse> TryGetClientsFromCache()
        {
            var clients = new GetClientsByUserIdResponse();

            try
            {
                clients.Clients = await CacheAccess.Get <List <Client> >(CacheKeys.CLIENTS);
            }
            catch
            {
                var user = await CacheAccess.GetSecure <User>(CacheKeys.USER_KEY);

                clients = await _clientAppService.GetClientsByUserId(user.UsuarioId.ToString());

                await CacheAccess.Insert <List <Client> >(CacheKeys.CLIENTS, clients.Clients);
            }
            return(clients);
        }
Пример #11
0
        private async void ChangePassword()
        {
            try
            {
                try
                {
                    Analytics.TrackEvent(InsightsTypeEvents.ActionView, new Dictionary <string, string>
                    {
                        { InsightsPagesNames.ResetPasswordPage, InsightsActionNames.ChangePassword }
                    });
                }
                catch { }
                TimeSpan duration = new TimeSpan(0, 0, 3);
                if (string.IsNullOrEmpty(RepeatPassword) || string.IsNullOrEmpty(Password))
                {
                    _userDialogs.Toast("Preencha os dois campos para continuar.", duration);
                    return;
                }
                await NavigationHelper.ShowLoading();

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

                await _userAppService.ChangePassword(new ChangePasswordRequest()
                {
                    NewPassword = Password,
                    OldPassword = RepeatPassword,
                    UsuarioId   = user.UsuarioId
                });

                _userDialogs.Toast("Senha Alterada com Sucesso!", duration);
                await _navigationService.GoBackAsync();

                await NavigationHelper.PopLoading();
            }
            catch (Exception ex)
            {
                _userDialogs.Toast(ex.Message);
                await NavigationHelper.PopLoading();
            }
        }
Пример #12
0
        private async Task GetUserFromCache()
        {
            await NavigationHelper.ShowLoading();

            try
            {
                User = await CacheAccess.GetSecure <User>(CacheKeys.USER_KEY);

                var salesResponse = await _salesAppService.GetSalesByUserId(User.UsuarioId.ToString());

                float profit = 0;
                foreach (var sale in salesResponse.Sales)
                {
                    profit += sale.SaleValue;
                }
                Profit = "Faturamento: " + Formatter.FormatMoney((decimal)profit);
            }
            catch
            {
                UserDialogs.Instance.Toast("Não foi possível carregar seus dados, verifique sua conexão!");
            }
            await NavigationHelper.PopLoading();
        }
Пример #13
0
        public override async void OnNavigatedTo(NavigationParameters parameters)
        {
            base.OnNavigatedTo(parameters);
            try
            {
                var user = await CacheAccess.GetSecure <User>(CacheKeys.USER_KEY);

                var token = await CacheAccess.GetSecure <Guid>(CacheKeys.ACCESS_TOKEN);

                var currentSeasonReponse = await _seasonAppService.CurrentSeason();

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

                var myTrophies = await _trophyAppService.GetCurrentTrophies(user.UsuarioId.ToString());

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

                var currentChallenges = await _challengesAppService.GetCurrentChallenges(currentSeasonReponse.Entity.TemporadaId.ToString());

                localBirthdays = await CheckAnniversary();

                Settings.AccessToken = token.ToString();
                Settings.UserId      = user.UsuarioId.ToString();
                await CheckInviteChallengeCompleted(myTrophies.Trophies, user.UsuarioId.ToString(), currentChallenges.Challenges, currentSeasonReponse.Entity);

                await _navigationService.NavigateAsync(NavigationSettings.MenuPrincipal);
            }
            catch
            {
                Settings.AccessToken = string.Empty;
                Settings.UserId      = string.Empty;
                await _navigationService.NavigateAsync(NavigationSettings.AbsoluteLogin);
            }
            finally
            {
            }
        }
        public override async void OnNavigatedTo(NavigationParameters parameters)
        {
            base.OnNavigatedTo(parameters);

            await NavigationHelper.ShowLoading();

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

                var salesResponse = await TryGetSalesFromCache();

                salesResponse.Sales.OrderByDescending(sale => sale.SaleDate).ToList();

                AdjustColorsFromSales(salesResponse.Sales);

                var salesDisordered = new List <Sale>(salesResponse.Sales);
                foreach (var sale in salesDisordered)
                {
                    sale.CardLabel = sale.ClientName + ", " + sale.SaleDate.ToString("dd/MM/yyyy");
                }
                salesDisordered = salesDisordered.OrderByDescending(sale => sale.SaleDate).ToList();

                SalesList = new ObservableCollection <Sale>(salesDisordered);
                NoData    = SalesList.Count < 1 ? true : false;
            }
            catch (Exception ex)
            {
                _userDialogs.Toast(ex.Message);
                await _navigationService.GoBackAsync();
            }

            Device.BeginInvokeOnMainThread(async() =>
            {
                await NavigationHelper.PopLoading();
            });
        }
        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 { }
        }
Пример #17
0
        private async Task GetAppUsers()
        {
            AppUsers.Clear();
            var AppUsersOrdered = new List <User>();

            try
            {
                var users       = (await _userAppService.GetAppUsers()).Users;
                var allAppUsers = await _userAppService.GetAllAppUsers();

                switch (ListType)
                {
                case CarouselBannerType.AveragePiecesForSale:
                    users = users.Count < 6 ? users.OrderByDescending(u => u.AverageItensPerSalePoints).ToList().GetRange(0, users.Count) : users.OrderByDescending(u => u.AverageItensPerSalePoints).ToList().GetRange(0, 5);

                    foreach (var user in users)
                    {
                        user.ListRankingPoints = Formatter.FormatAveragePiecesForSale(user.AverageItensPerSalePoints);
                    }
                    AppUsersOrdered = allAppUsers.Users.OrderByDescending(user => user.AverageItensPerSalePoints).ToList();
                    break;

                case CarouselBannerType.AverageTicket:

                    users = users.Count < 6 ? users.OrderByDescending(u => u.AverageTicketPoints).ToList().GetRange(0, users.Count) : users.OrderByDescending(u => u.AverageTicketPoints).ToList().GetRange(0, 5);

                    foreach (var user in users)
                    {
                        user.ListRankingPoints = Formatter.FormatMoney(user.AverageTicketPoints);
                    }
                    AppUsersOrdered = allAppUsers.Users.OrderByDescending(user => user.AverageTicketPoints).ToList();
                    break;

                case CarouselBannerType.RegisterAlliedFlowers:

                    users = users.Count < 6 ? users.OrderByDescending(u => u.InviteAllyFlowersPoints).ToList().GetRange(0, users.Count) : users.OrderByDescending(u => u.InviteAllyFlowersPoints).ToList().GetRange(0, 5);

                    foreach (var user in users)
                    {
                        user.ListRankingPoints = user.InviteAllyFlowersPoints.ToString();
                    }
                    AppUsersOrdered = allAppUsers.Users.OrderByDescending(user => user.InviteAllyFlowersPoints).ToList();
                    break;

                case CarouselBannerType.RegisterClients:

                    users = users.Count < 6 ? users.OrderByDescending(u => u.RegisterClientsPoints).ToList().GetRange(0, users.Count) : users.OrderByDescending(u => u.RegisterClientsPoints).ToList().GetRange(0, 5);

                    foreach (var user in users)
                    {
                        user.ListRankingPoints = user.RegisterClientsPoints.ToString();
                    }
                    AppUsersOrdered = allAppUsers.Users.OrderByDescending(user => user.RegisterClientsPoints).ToList();
                    break;

                case CarouselBannerType.RegisteredSales:

                    users = users.Count < 6 ? users.OrderByDescending(u => u.SalesNumberPoints).ToList().GetRange(0, users.Count) : users.OrderByDescending(u => u.SalesNumberPoints).ToList().GetRange(0, 5);

                    foreach (var user in users)
                    {
                        user.ListRankingPoints = user.SalesNumberPoints.ToString();
                    }
                    AppUsersOrdered = allAppUsers.Users.OrderByDescending(user => user.SalesNumberPoints).ToList();
                    break;

                case CarouselBannerType.Total:
                    foreach (var user in users)
                    {
                        user.ListRankingPoints = (user.RegisterClientsPoints +
                                                  user.InviteAllyFlowersPoints +
                                                  user.SalesNumberPoints).ToString();
                        user.TotalPoints = (user.RegisterClientsPoints +
                                            user.InviteAllyFlowersPoints +
                                            user.SalesNumberPoints);
                    }

                    users = users.Count < 6 ? users.OrderByDescending(u => u.TotalPoints).ToList().GetRange(0, users.Count) : users.OrderByDescending(u => u.TotalPoints).ToList().GetRange(0, 5);

                    AppUsersOrdered = allAppUsers.Users.OrderByDescending(user => user.TotalPoints).ToList();
                    break;
                }

                foreach (var user in users)
                {
                    AppUsers.Add(user);
                }
            }
            catch
            {
                _userDialogs.Toast("Não foi possível obter os usuários");
                await _navigationService.NavigateAsync(NavigationSettings.MenuPrincipal);
            }


            ThisUser = new User();

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

            GetThisUserRankingPosition(AppUsersOrdered, ListType);

            AppUsers = FillUserRankingPosition(AppUsers);

            InsertPageTitleAndPoints();
        }
Пример #18
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);
            }
        }
        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);
            }
        }