コード例 #1
0
        public async Task <IActionResult> MarcarNumeroSorteado([FromBody] ItemRifaViewModel itemRifaViewModel) =>
        await TratarResultadoAsync(async() =>
        {
            await _itemRifaService.ConfirmarNumeroSorteadoAsync(itemRifaViewModel);

            return(Ok());
        });
コード例 #2
0
        public async Task <bool> ConfirmarNumeroSorteadoAsync(ItemRifaViewModel itemRifaViewModel)
        {
            var itensRifa = await _itemRifaRepository.ListarPorRifaId(itemRifaViewModel.RifaId);

            var itensRifaSorteados = itensRifa.Where(item => item.Ativo && item.Sorteado).ToList();

            if (itensRifaSorteados.Any())
            {
                foreach (var item in itensRifaSorteados)
                {
                    if (item.ItemRifaId == itemRifaViewModel.ItemRifaId)
                    {
                        return(true);
                    }

                    MarcarSorteado(item, false);
                }

                await _itemRifaRepository.BulkUpdate(itensRifaSorteados);
            }

            var itemRifa = itensRifa.First(item => item.ItemRifaId == itemRifaViewModel.ItemRifaId);

            MarcarSorteado(itemRifa, true);

            return(await _itemRifaRepository.UpdateAsync(itemRifa) > 0);
        }
コード例 #3
0
        public async Task <RifaViewModel> ObterComItensAsync(int rifaId, List <ClienteViewModel> clientes, List <ClienteViewModel> vendedores)
        {
            var rifa = await _rifaRepository.GetByIdAsync(rifaId);

            var itensRifa = await _itemRifaRepository.ListarPorRifaId(rifaId);

            var rifaViewModel = RifaViewModel.MapFromEntity(rifa);

            rifaViewModel.ItensRifa = new List <ItemRifaViewModel>(itensRifa.Count);

            foreach (var item in itensRifa)
            {
                var itemRifa = ItemRifaViewModel.MapFromEntity(item);

                itemRifa.Cliente  = clientes.FirstOrDefault(c => c.ClienteId == item.ClienteId);
                itemRifa.Vendedor = vendedores.FirstOrDefault(v => v.ClienteId == item.VendedorId);
                rifaViewModel.ItensRifa.Add(itemRifa);
            }
            return(rifaViewModel);
        }