Example #1
0
        public IHttpActionResult Post([FromBody] InventarioLocal inventarioLocal)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                _repository.Insert(inventarioLocal);

                return(Ok());
            }
            catch (System.Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Example #2
0
        public IHttpActionResult Post([FromBody] Inventario inventario)
        {
            try
            {
                var usuarios = inventario.Usuarios;

                inventario.Usuarios = null;

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                _repository.Insert(inventario);

                foreach (var filial in inventario.Filiais)
                {
                    _filialRepository.Insert(new InventarioFilial()
                    {
                        FilialID     = filial.ID,
                        InventarioID = inventario.ID
                    });
                }

                if (inventario.Geral)
                {
                    foreach (var filial in inventario.Filiais)
                    {
                        var locaisFilial = _localDbRepository.GetByFilialID(filial.ID);

                        foreach (var local in locaisFilial)
                        {
                            _localRepository.Insert(new InventarioLocal()
                            {
                                LocalID      = local.ID,
                                InventarioID = inventario.ID
                            });
                        }
                    }
                }
                else
                {
                    foreach (var local in inventario.Locais)
                    {
                        _localRepository.Insert(new InventarioLocal()
                        {
                            LocalID      = local.ID,
                            InventarioID = inventario.ID
                        });
                    }
                }

                foreach (var usuario in usuarios)
                {
                    usuario.InventarioID = inventario.ID;

                    _usuarioRepository.Insert(usuario);
                }

                return(Ok());
            }
            catch (System.Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }