Пример #1
0
        public override async void OnNavigatedTo(NavigationParameters parameters)
        {
            base.OnNavigatedTo(parameters);
            string firstAccess = "false";

            if (parameters.ContainsKey(NavigationKeyParameters.FirstAccess))
                firstAccess = parameters[NavigationKeyParameters.FirstAccess] as string;
            if (parameters.ContainsKey(NavigationKeyParameters.ClientsBirthday))
            {
                await Task.Delay(2000);
                var listBirthdays = parameters[NavigationKeyParameters.ClientsBirthday] as ObservableCollection<Client>;
                await CacheAccess.Insert<ObservableCollection<Client>>(CacheKeys.BIRTHDAYS, listBirthdays);
                if (firstAccess == "true")
                {
                    int dayMonthCache = 0;
                    try
                    {
                        dayMonthCache = await CacheAccess.Get<int>(CacheKeys.DAY_MONTH);
                    }
                    catch { }
                    if (dayMonthCache != DateTime.Now.Day)
                    {
                        await PopupAnniversaryHelper.Mostrar(_userAppService);
                    }
                }
            }
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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
            {
            }
        }
        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 { }
        }