public async Task <ActionResult <string> > CrearProducto(Producto producto)
        {
            try
            {
                if (string.IsNullOrEmpty(producto.NombreProducto) || producto.PrecioUnitario == 0)
                {
                    throw new Exception("Los campos NombreProducto,  PrecioUnitario son obligatorios!!!!", new Exception("Los campos NombreProducto,  PrecioUnitario son obligatorios!!!!"));
                }
                else if (producto.StockMin <= 5 || producto.StockMax == 0 || producto.Saldo == 0)
                {
                    throw new Exception("El campo StockMin no puede ser menor a 5 !!!", new Exception("El campo StockMin no puede ser menor a 5 !!!"));
                }
                else if (producto.StockMax <= 5)
                {
                    throw new Exception("El campo StockMax debe ser mayor a 5 !!!", new Exception("El campo StockMax debe ser mayor a 5 !!!"));
                }
                else if (producto.Saldo == 0)
                {
                    throw new Exception("El campo Saldo no puede ser igual a cero !!!", new Exception("El campo Saldo no puede ser igual a cero !!!"));
                }
                else
                {
                    _context.Productos.Add(producto);
                    await _context.SaveChangesAsync();

                    return(Ok(new { success = true, message = "Producto creado con exito!!!" }));;
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(new { success = false, message = ex.InnerException.Message }));
            }
        }
        public async Task <ActionResult <string> > CrearCliente(Cliente cliente)
        {
            try
            {
                if (string.IsNullOrEmpty(cliente.Nombres) ||
                    string.IsNullOrEmpty(cliente.Apellidos) ||
                    string.IsNullOrEmpty(cliente.Direccion) ||
                    string.IsNullOrEmpty(cliente.Celular) ||
                    string.IsNullOrEmpty(cliente.Correo) ||
                    cliente.FechaNacimiento == null)
                {
                    throw new Exception("Todos los campos son obligatorios!!!!", new Exception("Todos los campos son obligatorios!!!!"));
                }
                else
                {
                    _context.Clientes.Add(cliente);
                    await _context.SaveChangesAsync();

                    return(Ok(new { success = true, message = "Cliente creado con exito!!!" }));;
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(new { success = false, message = ex.InnerException.Message }));
            }
        }
        public async Task <ActionResult <string> > CreaUsuarioApp(UsuarioApp usuarioApp)
        {
            try
            {
                if (string.IsNullOrEmpty(usuarioApp.Nombres) ||
                    string.IsNullOrEmpty(usuarioApp.Apellidos) ||
                    string.IsNullOrEmpty(usuarioApp.Usuario) ||
                    string.IsNullOrEmpty(usuarioApp.Clave) ||
                    usuarioApp.Estado == 0)
                {
                    throw new Exception("Todos los campos son obligatorios!!!!", new Exception("Todos los campos son obligatorios!!!!"));
                }
                else
                {
                    usuarioApp.Clave = Ultilidades.MD5Hash(usuarioApp.Clave);

                    _context.Usuarios.Add(usuarioApp);
                    await _context.SaveChangesAsync();

                    return(Ok(new { success = true, message = "Datos Guardas con exito!!!" }));;
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(new { success = false, message = ex.InnerException.Message }));
            }
        }
Exemple #4
0
        public async Task <ActionResult <Factura> > CrearFactura(Factura factura)
        {
            try
            {
                if (string.IsNullOrEmpty(factura.NoFactura) || factura.Fecha == null || factura.IdCliente == 0 || factura.Valor == 0 || factura.IdUsuario == 0)
                {
                    throw new Exception("Todos los campos son obligatorios!!!!", new Exception("Todos los campos son obligatorios!!!!"));
                }
                else if (factura.detalleFacturas.Count == 0)
                {
                    throw new Exception("La factura por lo menos debe contener un producto !!!", new Exception("La factura por lo menos debe contener un producto !!!"));
                }
                else
                {
                    _context.Facturas.Add(factura);

                    foreach (var item in factura.detalleFacturas)
                    {
                        if (item.IdProducto == 0)
                        {
                            throw new Exception("Producto no valido o no ha selecionado ninguno producto del sistema !!!", new Exception("Producto no valido o no ha selecionado ninguno producto del sistema !!!"));
                        }
                        else
                        {
                            _context.DetalleFacturas.Add(item);
                        }
                    }

                    await _context.SaveChangesAsync();

                    return(Ok(new { success = true, message = "Factura creada con exito!!!" }));;
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(new { success = false, message = ex.InnerException.Message }));
            }
        }