Exemplo n.º 1
0
        private async Task FriendInviteSetPunctuation(User user)
        {
            var friendInviteSource = await _userPunctuationSourceRepository.GetById((int)UserPunctuationSourceEnum.FriendInvitation);

            _userPunctuationRepository.Save(new UserPunctuation
            {
                CreatedAt         = DateTime.Now,
                CurrentMonth      = DateTime.Now.Month,
                CurrentYear       = DateTime.Now.Year,
                Description       = "CONVITE DE AMIGOS - CONVIDADO",
                OperationType     = 'C',
                Punctuation       = 5,
                ReferenceEntityId = 0,
                User = user,
                UserPunctuationSource = friendInviteSource
            });

            var participant = (await _userAccessCodeInviteRepository.CustomFind(x => x.Code.Equals(user.AccessCodeInvite), x => x.User)).Select(x => x.User).FirstOrDefault();

            _userPunctuationRepository.Save(new UserPunctuation
            {
                CreatedAt         = DateTime.Now,
                CurrentMonth      = DateTime.Now.Month,
                CurrentYear       = DateTime.Now.Year,
                Description       = "CONVITE DE AMIGOS - PARTICIPANTE",
                OperationType     = 'C',
                Punctuation       = 10,
                ReferenceEntityId = 0,
                User = participant,
                UserPunctuationSource = friendInviteSource
            });
        }
Exemplo n.º 2
0
        public async Task PointsExpiration()
        {
            var dateConfigured = (await _expiredConfigurationPointsRepository.GetAll()).First().ExpiresIn;

            if (dateConfigured.Day == DateTime.Now.Day)
            {
                var users = await _userRepository.GetAll();

                foreach (var item in users)
                {
                    var balanceToExpire = await PointsToExpire(item.Id);

                    if (balanceToExpire > 0)
                    {
                        _userPunctuationRepository.Save(new UserPunctuation
                        {
                            CreatedAt         = DateTime.Now,
                            CurrentMonth      = DateTime.Now.Month,
                            CurrentYear       = DateTime.Now.Year,
                            Description       = "EXPIRACAO DE PONTOS",
                            OperationType     = 'D',
                            Punctuation       = -1 * balanceToExpire,
                            ReferenceEntityId = 0,
                            User = item,
                            UserPunctuationSource = await _userPunctuationSourceRepository.GetById(5)
                        });

                        await _unitOfWork.CommitAsync();
                    }
                }
            }
        }
Exemplo n.º 3
0
        public async Task TrainingPunctuationProcesses(User user, string trainingName, int trainingId)
        {
            var lastUserTrainingCompleted = await _trainingUserPointsRepository.CustomFind(x => x.User.Id == user.Id &&
                                                                                           x.ResultId == (int)TrainingResultEnum.Approved &&
                                                                                           x.TrainingDoneAt.Month == DateTime.Now.AddMonths(-1).Month &&
                                                                                           x.TrainingDoneAt.Year == DateTime.Now.AddMonths(-1).Year);

            var lastTraining = await _trainingRepository.CustomFind(x => x.CurrentMonth == DateTime.Now.AddMonths(-1).Month &&
                                                                    x.CurrentYear == DateTime.Now.AddMonths(-1).Year && !x.hasTrainingMaterial && x.trainingKind == 2);

            var trainingValidation = lastTraining.Count() >= 2 ? 2 : 1;

            decimal point = 10;

            var lastPoint = (await _userPunctuationRepository.CustomFind(x => x.User.Id == user.Id &&
                                                                         x.UserPunctuationSource.Id == (int)UserPunctuationSourceEnum.TrainingSaleman)).OrderBy(x => x.Id);

            if (lastUserTrainingCompleted.Count() >= trainingValidation)
            {
                var lastMonthToApply    = lastPoint.Where(x => x.CurrentMonth == DateTime.Now.AddMonths(-1).Month&& x.CurrentYear == DateTime.Now.AddMonths(-1).Year).LastOrDefault();
                var currentMonthToApply = lastPoint.Where(x => x.CurrentMonth == DateTime.Now.Month && x.CurrentYear == DateTime.Now.Year).LastOrDefault();

                if (currentMonthToApply != null)
                {
                    point = currentMonthToApply.Punctuation;
                }
                else if (lastMonthToApply != null && lastMonthToApply.Punctuation < 50)
                {
                    point = lastMonthToApply.Punctuation + 10;
                }
                else if (lastMonthToApply != null && lastMonthToApply.Punctuation >= 50)
                {
                    point = 50;
                }
            }

            _logger.Info($" Nova pontuacao inserida no mes {DateTime.Now.Month} de {DateTime.Now.Year} no valor {point} para o usuario com id {user.Id} ");

            _userPunctuationRepository.Save(new UserPunctuation
            {
                CurrentMonth      = DateTime.Now.Month,
                CurrentYear       = DateTime.Now.Year,
                CreatedAt         = DateTime.Now,
                Description       = trainingName,
                OperationType     = 'C',
                Punctuation       = point,
                ReferenceEntityId = trainingId,
                User = user,
                UserPunctuationSource = await _userPunctuationSourceRepository.GetById((int)UserPunctuationSourceEnum.TrainingSaleman)
            });

            await _unitOfWork.CommitAsync();
        }
Exemplo n.º 4
0
        private async Task ProcessesSalesman(IEnumerable <Sale> sales)
        {
            var sourceSalesman = await _userPunctuationSourceRepository.GetById((int)UserPunctuationSourceEnum.Sales);

            foreach (var sale in sales)
            {
                _userPunctuationRepository.Save(new UserPunctuation
                {
                    CreatedAt         = DateTime.Now,
                    CurrentMonth      = sale.CurrentMonth,
                    CurrentYear       = sale.CurrentYear,
                    Description       = $"PONTUAÇÃO VENDAS {sale.CurrentMonth}/{sale.CurrentYear}",
                    OperationType     = 'C',
                    Punctuation       = sale.Punctuation,
                    ReferenceEntityId = sale.Id,
                    User = sale.User,
                    UserPunctuationSource = sourceSalesman
                });

                sale.Processed = true;
            }
        }
Exemplo n.º 5
0
        public async Task <RescueResponseDto <Order> > DoRescue(RescueRequestDto rescueRequestDto)
        {
            var user = await _userRepository.CustomFind(x => x.Cpf.Equals(rescueRequestDto.Cpf) && (x.UserStatus.Id == (int)UserStatusEnum.Active || x.UserStatus.Id == (int)UserStatusEnum.OnlyCatalog));

            _logger.Info($"resgate para login {rescueRequestDto.Cpf} com codigo externo {rescueRequestDto.ExternalOrderId} - iniciada");

            if (!user.Any())
            {
                _logger.Info($"resgate para login {rescueRequestDto.Cpf} com codigo externo {rescueRequestDto.ExternalOrderId} - usuario invalido");
                return(new RescueResponseDto <Order>
                {
                    Success = false,
                    Message = "usuario invalido"
                });
            }

            var lastRescue = await _orderRepository.GetLast(x => x.User.Cpf.Equals(rescueRequestDto.Cpf), x => x.Id);

            if (lastRescue != null && (DateTime.Now - lastRescue.CreatedAt).TotalMinutes < 2)
            {
                _logger.Fatal($"resgate para login {rescueRequestDto.Cpf} com codigo externo {rescueRequestDto.ExternalOrderId} - suspeita de fraude por tentativa de gerar pedidos em um pequeno intervalo de tempo");
                return(new RescueResponseDto <Order>
                {
                    Success = false,
                    Message = "suspeita de fraude por tentativa de gerar pedidos em um pequeno intervalo de tempo"
                });
            }


            if (!rescueRequestDto.RescueRequestItems.Any())
            {
                _logger.Info($"resgate para login {rescueRequestDto.Cpf} com codigo externo {rescueRequestDto.ExternalOrderId} - pedido não possue itens");
                return(new RescueResponseDto <Order>
                {
                    Success = false,
                    Message = "pedido não possue itens"
                });
            }

            var balance = (await _userPunctuationRepository.CustomFind(x => x.User.Id == user.First().Id)).Sum(x => x.Punctuation);
            var order   = new Order();

            if (balance < rescueRequestDto.Total)
            {
                _logger.Info($"autorizacao de pedido para login {rescueRequestDto.Cpf} com codigo externo {rescueRequestDto.ExternalOrderId} - autorizacao recusada saldo insuficiente");
                return(new RescueResponseDto <Order>
                {
                    Success = false,
                    Message = "Saldo insuficiente"
                });
            }

            order = new Order
            {
                Activated       = true,
                ConversionRate  = rescueRequestDto.ConversionRate,
                CreatedAt       = DateTime.Now,
                ExternalOrderId = rescueRequestDto.ExternalOrderId,
                Freight         = rescueRequestDto.Freight,
                Login           = rescueRequestDto.Cpf,
                ForecastDate    = rescueRequestDto.ForecastDate,
                OrderStatus     = await _orderStatusRepository.GetById((int)OrderStatusEnum.Confirmed),
                OrderValue      = rescueRequestDto.OrderValue,
                Total           = rescueRequestDto.Total,
                User            = user.First()
            };

            _orderRepository.Save(order);

            await _unitOfWork.CommitAsync();

            _userPunctuationRepository.Save(new UserPunctuation
            {
                CreatedAt             = DateTime.Now,
                CurrentMonth          = DateTime.Now.Month,
                CurrentYear           = DateTime.Now.Year,
                Description           = "Pedido Confirmado",
                OperationType         = 'D',
                Punctuation           = -1 * rescueRequestDto.Total,
                ReferenceEntityId     = order.Id,
                UserPunctuationSource = await _userPunctuationSourceRepository.GetById((int)SourceUserPunctuationEnum.OrderConfirmed),
                User = user.First()
            });

            foreach (var item in rescueRequestDto.RescueRequestItems)
            {
                _orderItemRepository.Save(new OrderItem
                {
                    Activated       = true,
                    Ammout          = item.Ammout,
                    Category        = item.Category,
                    CodeItem        = item.CodeItem,
                    CreatedAt       = DateTime.Now,
                    Department      = item.Department,
                    ExternalOrderId = rescueRequestDto.ExternalOrderId,
                    Order           = order,
                    Partner         = item.Partner,
                    ProductName     = item.ProductName,
                    TotalValue      = item.TotalValue,
                    UnitValue       = item.UnitValue
                });
            }

            var confirmSaved = await _unitOfWork.CommitAsync();

            if (confirmSaved)
            {
                order.User = null;

                _logger.Info($"autorizacao de pedido para login {rescueRequestDto.Cpf} com codigo externo {rescueRequestDto.ExternalOrderId} - Pedido gerado com sucesso!");
                return(new RescueResponseDto <Order>
                {
                    Success = true,
                    Message = "Pedido gerado com sucesso!",
                    Data = new List <Order> {
                        order
                    }
                });
            }
            else
            {
                _logger.Info($"autorizacao de pedido para login {rescueRequestDto.Cpf} com codigo externo {rescueRequestDto.ExternalOrderId} - autorizacao recusada ocorreu erro ao tentar gerar o pedido");
                return(new RescueResponseDto <Order>
                {
                    Success = false,
                    Message = "ocorreu erro ao tentar gerar o pedido"
                });
            }
        }