public async Task <Respuesta <IClienteDTO> > CrearCliente(IClienteDTO cliente) { return(await new Wrapper <IClienteDTO>().EjecutarTransaccionAsync(async() => { Cliente nuevoCliente = mapper.Map <Cliente>(cliente); contexto.Add(nuevoCliente); await contexto.SaveChangesAsync(); return FabricaRespuesta <IClienteDTO> .RespuestaCreacionExitosa(new List <IClienteDTO> { nuevoCliente }); }, async() => await FabricaRespuesta <IClienteDTO> .RespuestaFallida(Mensajes.ErrorEnCreacion))); }
public async Task <Respuesta <IFacturaDTO> > CrearFactura(IFacturaDTO factura) { return(await new Wrapper <IFacturaDTO>().EjecutarTransaccionAsync(async() => { Factura nuevaFactura = mapper.Map <Factura>(factura); contexto.Add(nuevaFactura); await contexto.SaveChangesAsync(); return FabricaRespuesta <IFacturaDTO> .RespuestaCreacionExitosa(new List <IFacturaDTO> { nuevaFactura }); }, async() => await FabricaRespuesta <IFacturaDTO> .RespuestaFallida(Mensajes.ErrorEnCreacion))); }
public async Task <Respuesta <ICategoriaDTO> > CrearCategoria(ICategoriaDTO categoria) { return(await new Wrapper <ICategoriaDTO>().EjecutarTransaccionAsync(async() => { Categoria nuevaCategoria = mapper.Map <Categoria>(categoria); contexto.Add(nuevaCategoria); await contexto.SaveChangesAsync(); return FabricaRespuesta <ICategoriaDTO> .RespuestaCreacionExitosa(new List <ICategoriaDTO> { nuevaCategoria }); }, async() => await FabricaRespuesta <ICategoriaDTO> .RespuestaFallida(Mensajes.ErrorEnCreacion))); }
public async Task <Respuesta <IProductoCompuestoDTO> > CrearProducto(IProductoCompuestoDTO producto) { return(await new Wrapper <IProductoCompuestoDTO>().EjecutarTransaccionAsync(async() => { Producto nuevoProducto = mapper.Map <Producto>(producto); contexto.Add(nuevoProducto); await contexto.SaveChangesAsync(); InventarioProducto inventario = new InventarioProducto() { IdProducto = nuevoProducto.IdProducto, Cantidad = producto.Cantidad }; contexto.Add(inventario); await contexto.SaveChangesAsync(); producto.IdInventario = inventario.IdInventario; producto.IdProducto = nuevoProducto.IdProducto; return FabricaRespuesta <IProductoCompuestoDTO> .RespuestaCreacionExitosa(new List <IProductoCompuestoDTO> { producto }); }, async() => await FabricaRespuesta <IProductoCompuestoDTO> .RespuestaFallida(Mensajes.ErrorEnCreacion))); }