Exemple #1
0
        public async Task <IActionResult> AddStock([FromBody] StockChange ent)
        {
            var material = await DbContext.Material
                           .SingleOrDefaultAsync(m => m.Id == ent.materialId);

            if (material == null)
            {
                return(NotFound());
            }

            material.EstoqueHistorico.Add(new EstoqueHistorico
            {
                Quantidade = ent.quantity,
                Tipo       = "E",
                UsuarioId  = Operator.Id,
                MaterialId = ent.materialId,
                Data       = DateTime.UtcNow
            });

            material.QuantidadeAtual += ent.quantity;

            DbContext.Entry(material).State = EntityState.Modified;

            await DbContext.SaveChangesAsync();

            return(StatusCode(StatusCodes.Status204NoContent));
        }
Exemple #2
0
        public async Task <IActionResult> RemoveStock([FromBody] StockChange ent)
        {
            if (ent.taskId == null)
            {
                throw new ValidationExn("Informe o código da tarefa.");
            }

            var material = await DbContext.Material
                           .SingleOrDefaultAsync(m => m.Id == ent.materialId);

            if (material == null)
            {
                return(NotFound());
            }

            if (material.QuantidadeAtual - ent.quantity < 0)
            {
                throw new ValidationExn("Estoque insuficiente.");
            }

            material.EstoqueHistorico.Add(new EstoqueHistorico
            {
                Quantidade = ent.quantity,
                Tipo       = "S",
                UsuarioId  = Operator.Id,
                MaterialId = ent.materialId,
                TarefaId   = ent.taskId,
                Data       = DateTime.UtcNow
            });

            material.QuantidadeAtual -= ent.quantity;

            DbContext.Entry(material).State = EntityState.Modified;

            await DbContext.SaveChangesAsync();

            return(StatusCode(StatusCodes.Status204NoContent));
        }