public async Task <IActionResult> PutProductoPresentacion(int id, ProductoPresentacion productoPresentacion)
        {
            if (id != productoPresentacion.Id)
            {
                return(BadRequest());
            }

            _context.Entry(productoPresentacion).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductoPresentacionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> PutCliente(int id, Cliente cliente)
        {
            if (id != cliente.Id)
            {
                return(BadRequest());
            }
            if (cliente.Domicilio.Id == 0)
            {
                _context.Entry(cliente.Domicilio).State = EntityState.Added;
            }
            else
            {
                _context.Entry(cliente.Domicilio).State = EntityState.Modified;
            }
            _context.Entry(cliente).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClienteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #3
0
        public async Task <IActionResult> PutFactura(int id, Factura factura)
        {
            if (id != factura.Id)
            {
                return(BadRequest());
            }

            _context.Entry(factura).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FacturaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #4
0
        public async Task <IActionResult> PutMovimientoInventario(int id, MovimientoInventario movimientoInventario)
        {
            if (id != movimientoInventario.Id)
            {
                return(BadRequest());
            }

            _context.Entry(movimientoInventario).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MovimientoInventarioExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #5
0
 /// <summary>
 /// Generic Delete method for the entities
 /// </summary>
 /// <param name="entityToDelete"></param>
 public virtual void Delete(TEntity entityToDelete)
 {
     if (Context.Entry(entityToDelete).State == EntityState.Detached)
     {
         DbSet.Attach(entityToDelete);
     }
     DbSet.Remove(entityToDelete);
 }
        public async Task <ActionResult <ReciboCobranzas> > PostReciboCobranzas(ReciboCobranzas reciboCobranzas)
        {
            try
            {
                List <ImputacionComprobantesVenta> imputaciones = reciboCobranzas.Imputaciones;
                List <MovimientoCaja> movimientoCajas           = reciboCobranzas.movimientosCaja;
                Cliente cliente = reciboCobranzas.Cliente;
                reciboCobranzas.Cliente         = null;
                reciboCobranzas.Imputaciones    = null;
                reciboCobranzas.movimientosCaja = null;

                _context.reciboCobranzas.Add(reciboCobranzas);
                cliente.saldoCC -= reciboCobranzas.totalComprobante;
                _context.Entry(cliente).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                foreach (ImputacionComprobantesVenta imputacion in imputaciones)
                {
                    imputacion.ReciboCobranzasId     = reciboCobranzas.Id;
                    _context.Entry(imputacion).State = EntityState.Added;

                    imputacion.FacturaVenta.totalCancelado += imputacion.totalImputado;
                    if (imputacion.FacturaVenta.totalCancelado == imputacion.FacturaVenta.totalComprobante)
                    {
                        imputacion.FacturaVenta.EstadoFacturaId = 2;
                    }
                    _context.Entry(imputacion.FacturaVenta).State = EntityState.Modified;

                    await _context.SaveChangesAsync();
                }

                foreach (MovimientoCaja movimientoCaja in movimientoCajas)
                {
                    movimientoCaja.ReciboCobranzasId = reciboCobranzas.Id;
                    movimientoCaja.entra             = true;
                    movimientoCaja.sale = false;
                    _context.Entry(movimientoCaja).State = EntityState.Added;

                    movimientoCaja.Caja.saldo += movimientoCaja.totalMovimiento;
                    _context.Entry(movimientoCaja.Caja).State = EntityState.Modified;


                    await _context.SaveChangesAsync();
                }


                return(CreatedAtAction("GetReciboCobranzas", new { id = reciboCobranzas.Id }, reciboCobranzas));
            }
            catch (Exception es)
            {
                throw;
            }
        }
Пример #7
0
        public async Task <ActionResult <OrdenPago> > PostOrdenPago(OrdenPago ordenPago)
        {
            try
            {
                List <ImputacionComprobantesCompra> imputaciones = ordenPago.Imputaciones;
                List <MovimientoCaja> movimientoCajas            = ordenPago.movimientosCaja;
                Proveedor             proveedor = ordenPago.Proveedor;
                ordenPago.Proveedor       = null;
                ordenPago.Imputaciones    = null;
                ordenPago.movimientosCaja = null;

                _context.ordenPago.Add(ordenPago);
                proveedor.saldoCC += ordenPago.totalComprobante;
                _context.Entry(proveedor).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                foreach (ImputacionComprobantesCompra imputacion in imputaciones)
                {
                    imputacion.OrdenPagoId           = ordenPago.Id;
                    _context.Entry(imputacion).State = EntityState.Added;

                    imputacion.FacturaCompras.totalCancelado += imputacion.totalImputado;
                    if (imputacion.FacturaCompras.totalCancelado == imputacion.FacturaCompras.totalComprobante)
                    {
                        imputacion.FacturaCompras.EstadoFacturaId = 2;
                    }
                    _context.Entry(imputacion.FacturaCompras).State = EntityState.Modified;

                    await _context.SaveChangesAsync();
                }

                foreach (MovimientoCaja movimientoCaja in movimientoCajas)
                {
                    movimientoCaja.OrdenPagoId           = ordenPago.Id;
                    movimientoCaja.entra                 = false;
                    movimientoCaja.sale                  = true;
                    _context.Entry(movimientoCaja).State = EntityState.Added;

                    movimientoCaja.Caja.saldo -= movimientoCaja.totalMovimiento;
                    _context.Entry(movimientoCaja.Caja).State = EntityState.Modified;


                    await _context.SaveChangesAsync();
                }

                return(CreatedAtAction("GetOrdenPago", new { id = ordenPago.Id }, ordenPago));
            }
            catch (Exception es)
            {
                throw;
            }
        }
Пример #8
0
        public async Task <IActionResult> PutTeacherSubject(Guid id, TeacherSubject teacherSubject)
        {
            if (id != teacherSubject.Id)
            {
                return(BadRequest());
            }

            _context.Entry(teacherSubject).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TeacherSubjectExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #9
0
        public async Task <IHttpActionResult> PutItem(long id, T item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != item.Id)
            {
                return(BadRequest());
            }

            db.Entry(item).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #10
0
        public async Task <IActionResult> PutMark(Guid id, Mark mark)
        {
            if (id != mark.Id)
            {
                return(BadRequest());
            }

            _context.Entry(mark).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MarkExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #11
0
        public async Task <IActionResult> PutBanner(int id, Banner banner)
        {
            if (id != banner.Id)
            {
                return(BadRequest());
            }
            string rutaActualImagen = _context.banner.Where(x => x.Id == id).Select(x => x.Foto).ToList()[0];

            if (rutaActualImagen != banner.Foto)
            {
                var fotoImagen = Convert.FromBase64String(banner.Foto);
                banner.Foto = await almacenadorDeArchivos.EditarArchivo(fotoImagen,
                                                                        "jpg", "banners", rutaActualImagen);
            }

            _context.Entry(banner).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BannerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutEmployeeDetails(int id, EmployeeDetails employeeDetails)
        {
            if (id != employeeDetails.EmpId)
            {
                return(BadRequest());
            }

            _context.Entry(employeeDetails).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmployeeDetailsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #13
0
        public async Task <IActionResult> PutSchoolYear(Guid id, SchoolYear schoolYear)
        {
            if (id != schoolYear.Id)
            {
                return(BadRequest());
            }

            _context.Entry(schoolYear).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SchoolYearExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #14
0
        public async Task <IActionResult> PutLectureship(Guid id, Lectureship lectureship)
        {
            if (id != lectureship.Id)
            {
                return(BadRequest());
            }

            _context.Entry(lectureship).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LectureshipExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutTipoListaPrecioProvincia(int id, TipoListaPrecioProvincia tipoListaPrecioProvincia)
        {
            if (id != tipoListaPrecioProvincia.Id)
            {
                return(BadRequest());
            }

            _context.Entry(tipoListaPrecioProvincia).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TipoListaPrecioProvinciaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #16
0
        public async Task <IActionResult> PutDeposito(int id, Deposito deposito)
        {
            if (id != deposito.Id)
            {
                return(BadRequest());
            }

            _context.Entry(deposito).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DepositoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <T> Update(T entity)
        {
            context.Entry(entity).State = EntityState.Modified;
            await context.SaveChangesAsync().ConfigureAwait(false);

            return(entity);
        }
        public async Task<IActionResult> PutVendedorDepartamento(int id, VendedorDepartamento vendedorDepartamento)
        {
            if (id != vendedorDepartamento.Id)
            {
                return BadRequest();
            }

            _context.Entry(vendedorDepartamento).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VendedorDepartamentoExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return NoContent();
        }
Пример #19
0
        public async Task <IActionResult> PutComprobante(int id, Comprobante comprobante)
        {
            if (id != comprobante.Id)
            {
                return(BadRequest());
            }

            _context.Entry(comprobante).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ComprobanteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #20
0
        public async Task <IActionResult> PutFormulaProducto(int id, FormulaProducto formulaProducto)
        {
            if (id != formulaProducto.Id)
            {
                return(BadRequest());
            }
            _context.Entry(formulaProducto).State = EntityState.Modified;

            foreach (DetalleFormula detalle in formulaProducto.DetallesFormula)
            {
                if (detalle.Id == 0)
                {
                    _context.Entry(detalle).State = EntityState.Added;
                }
                else
                {
                    _context.Entry(detalle).State = EntityState.Modified;
                }
            }

            var detallesId      = formulaProducto.DetallesFormula.Select(x => x.Id).ToList();
            var detallesABorrar = _context.detalleFormula.Where(x => !detallesId.Contains(x.Id) && x.FormulaProductoId == formulaProducto.Id).ToList();

            _context.detalleFormula.RemoveRange(detallesABorrar);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FormulaProductoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #21
0
        public async Task <IActionResult> PutListaPrecios(int id, ListaPrecios listaPrecios)
        {
            if (id != listaPrecios.Id)
            {
                return(BadRequest());
            }

            _context.Entry(listaPrecios).State = EntityState.Modified;
            listaPrecios.DetalleListaPrecios.ForEach(x =>
            {
                if (x.Id == 0)
                {
                    _context.Entry(x).State = EntityState.Added;
                }
                else
                {
                    _context.Entry(x).State = EntityState.Modified;
                }
            });
            var detallesId      = listaPrecios.DetalleListaPrecios.Select(x => x.Id).ToList();
            var detallesABorrar = _context.detalleListaPrecios.Where(x => !detallesId.Contains(x.Id) && x.ListaPreciosId == listaPrecios.Id).ToList();

            _context.detalleListaPrecios.RemoveRange(detallesABorrar);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ListaPreciosExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #22
0
        public async Task <IActionResult> PutPedido(int id, Pedido pedido)
        {
            if (id != pedido.Id)
            {
                return(BadRequest());
            }
            if (CheckListarDePrecios(pedido.ClienteId, pedido.Domicilio.ProvinciaId, pedido.ListaPreciosId).Result)
            {
            }
            else
            {
                return(BadRequest("La lista de precios que usted esta usando no está habilitada para este cliente o caducado"));
            }

            pedido.Cliente      = null;
            pedido.EstadoPedido = null;
            pedido.Vendedor     = null;
            pedido.detallePedido.ForEach(x => x.ProductoPresentacion = null);
            pedido.Domicilio.Departamento = null;
            pedido.Domicilio.Provincia    = null;
            pedido.ListaPrecios           = null;



            foreach (DetallePedido detallePedido in pedido.detallePedido)
            {
                if (detallePedido.Id != 0)
                {
                    _context.Entry(detallePedido).State = EntityState.Modified;
                }
                else
                {
                    _context.Entry(detallePedido).State = EntityState.Added;
                }
            }

            var detalleIds      = pedido.detallePedido.Select(x => x.Id).ToList();
            var detallesABorrar = _context.detallePedido.Where(x => !detalleIds.Contains(x.Id) && x.PedidoId == pedido.Id).ToList();

            _context.detallePedido.RemoveRange(detallesABorrar);


            _context.Entry(pedido.Domicilio).State = EntityState.Modified;
            _context.Entry(pedido).State           = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                if (!PedidoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #23
0
 public virtual void Atualizar(TEntity entity)
 {
     Context.Entry <TEntity>(entity).State = EntityState.Modified;
 }