예제 #1
0
        public SystemValidationModel Desactivate(int id)
        {
            var proveedor = _context.Set <Proveedor>().Include(x => x.Compras).FirstOrDefault(x => x.Active && x.Id == id);

            if (proveedor.Compras.Where(x => x.Active).ToList().Count > 0)
            {
                return new SystemValidationModel()
                       {
                           Success = false, Message = "No se puede eliminar por que el proveedor tiene compras"
                       }
            }
            ;
            proveedor.Active = false;
            _context.Entry(proveedor).State = EntityState.Modified;
            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Id      = proveedor.Id,
                Message = success ? "Se ha eliminado correctamente el proveedor" : "No se pudo eliminar el proveedor",
                Success = success
            };

            return(validation);
        }
    }
예제 #2
0
        public SystemValidationModel ValidateStockPedido(List <DetallePedido> detallesPedio)
        {
            var result = new SystemValidationModel()
            {
                Success = true
            };

            //List<string> productosStock = new List<string>();
            //var productosIds = detallesPedio.Select(x => x.ProductoId).ToList();
            //var productos = _context.Set<Producto>().Where(x => productosIds.Contains(x.Id));
            //foreach (var detalle in detallesPedio)
            //{
            //    var producto = productos.FirstOrDefault(x => x.Id == detalle.ProductoId);
            //    var cantidadDetalle = detalle.Cantidad;
            //    if (detalle.Equivalencia > 0)
            //        cantidadDetalle = cantidadDetalle * detalle.Equivalencia;
            //    if (producto.Stock < cantidadDetalle)
            //    {
            //        result.Success = false;
            //        productosStock.Add(producto.Nombre);
            //    }
            //}
            //result.Object = productosStock;
            return(result);
        }
예제 #3
0
        public SystemValidationModel Desactivate(int id)
        {
            var producto      = GetById(id);
            var detalleVenta  = _context.Set <DetalleVenta>().Where(x => x.Active && x.Venta.Estado != Constants.EstadoVenta.Anulado && x.ProductoId == id);
            var detalleCompra = _context.Set <DetalleCompra>().Where(x => x.Active && x.Compra.Estado != Constants.EstadoCompra.Anulado && x.ProductoId == id);
            var detallePedido = _context.Set <DetallePedido>().Where(x => x.Active && x.Pedido.Estado != Constants.EstadoPedido.Anulado && x.ProductoId == id);

            if (detalleVenta.Count() > 0 || detalleCompra.Count() > 0 || detallePedido.Count() > 0)
            {
                return new SystemValidationModel()
                       {
                           Success = false, Message = "No se puede eliminar un producto que este en una venta, un pedido o una compra"
                       }
            }
            ;
            producto.Active = false;
            _context.Entry(producto).State = EntityState.Modified;
            foreach (var presentacion in producto.ProductoPresentaciones)
            {
                presentacion.Active = false;

                _context.Entry(presentacion).State = EntityState.Modified;
            }
            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Id      = producto.Id,
                Message = success ? "Se ha eliminado correctamente el producto" : "No se pudo eliminar el producto",
                Success = success
            };

            return(validation);
        }
예제 #4
0
        public SystemValidationModel Edit(ProductosEditViewModel viewModel)
        {
            var producto = GetById(viewModel.Id);

            producto = Mapper.Map(viewModel, producto);
            _context.Entry(producto).State = EntityState.Modified;

            var presentacionesIdToDelete = producto.ProductoPresentaciones.Select(x => x.Id).Except(viewModel.ProductoPresentaciones.Where(x => x.Id > 0).Select(x => x.Id));

            foreach (var presentacion in producto.ProductoPresentaciones.Where(x => presentacionesIdToDelete.Contains(x.Id)))
            {
                _context.Entry(presentacion).State = EntityState.Deleted;
            }

            foreach (var presentacionViewModel in viewModel.ProductoPresentaciones.Where(x => x.Id == 0))
            {
                var presentacion = Mapper.Map <ProductoPresentacion>(presentacionViewModel);
                _context.Entry(presentacion).State = EntityState.Added;
                producto.ProductoPresentaciones.Add(presentacion);
            }
            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Id      = producto.Id,
                Message = success ? "Se ha editado correctamente el producto" : "No se pudo editar el producto",
                Success = success
            };

            return(validation);
        }
예제 #5
0
        public SystemValidationModel Edit(InventariosEditViewModel viewModel)
        {
            var inventario = GetById(viewModel.Id);

            inventario.Estado = GetEstado(inventario);
            _context.Entry(inventario).State = EntityState.Modified;
            foreach (var detalle in viewModel.DetalleInventario)
            {
                var item = inventario.DetalleInventario.FirstOrDefault(x => x.Id == detalle.Id);
                item.StockActual           = detalle.StockActual;
                item.StockEncontrado       = detalle.StockEncontrado;
                _context.Entry(item).State = EntityState.Modified;
            }


            if (inventario.Estado == Constants.InventarioEstado.Terminado)
            {
                UpdateStock(viewModel); inventario.UsuarioFinId = viewModel.UsuarioId;
            }


            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Id      = inventario.Id,
                Message = success ? "Se ha guardado correctamente el inventario" : "No se pudo guardar el inventario",
                Success = success
            };

            return(validation);
        }
        public SystemValidationModel Save(OrdenPagoComprasAddViewModel viewModel)
        {
            var ordenPago = Mapper.Map <OrdenPagoCompra>(viewModel);

            ordenPago.Estado = Constants.OrdenPagoCompraEstado.Pendiente;
            var comprasIds = viewModel.OrdenPagoDetalle.Select(x => x.CompraId).ToList();
            var compras    = _context.Set <Compra>().Where(x => comprasIds.Contains(x.Id)).ToList();

            _context.Entry(ordenPago).State = EntityState.Added;
            foreach (var compra in compras)
            {
                compra.Estado = Constants.EstadoCompra.PendientedePago;
                _context.Entry(compra).State = EntityState.Modified;
            }

            foreach (var detalle in ordenPago.OrdenPagoDetalle)
            {
                _context.Entry(detalle).State = EntityState.Added;
            }
            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Id      = ordenPago.Id,
                Message = success ? "Se ha guardado correctamente la orden de pago" : "No se pudo guardar la orden de pago",
                Success = success
            };

            return(validation);
        }
예제 #7
0
        public SystemValidationModel UpdatePrecioVenta(List <int> productoIds, int sucursalId)
        {
            var productos = GetAll().Include(x => x.ProductoSucursal).Include(x => x.ProductoPresentaciones).Where(x => productoIds.Contains(x.Id));
            var compras   = _context.Set <DetalleCompra>().Include(x => x.Compra).Where(x => productoIds.Contains(x.ProductoId) && x.Compra.Estado == Constants.EstadoCompra.PendientedePago);

            foreach (var producto in productos)
            {
                var sumaCompras          = compras.Where(x => x.ProductoId == producto.Id && x.Compra.SucursalId == sucursalId).Sum(x => x.MontoTotal);
                var cant                 = compras.Where(x => x.ProductoId == producto.Id).Sum(x => x.Equivalencia * x.Cantidad);
                var precioPromedioUnidad = sumaCompras / cant;
                producto.PrecioVenta = decimal.Round(precioPromedioUnidad + precioPromedioUnidad * Convert.ToDecimal(producto.PorcentajeGanancia / 100), 0);
                foreach (var presentacion in producto.ProductoPresentaciones)
                {
                    var precioPresentacion = precioPromedioUnidad * presentacion.Equivalencia;
                    presentacion.PrecioVenta = decimal.Round(precioPresentacion + precioPresentacion * Convert.ToDecimal(presentacion.PorcentajeGanancia / 100), 0);
                }
                _context.Entry(producto).State = EntityState.Modified;
            }

            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Message = success ? "Se ha guardado correctamente el precio de venta" : "No se pudo guardar el precio de venta",
                Success = success
            };

            return(validation);
        }
        public SystemValidationModel Save(AddCategoriaViewModel viewModel)
        {
            var categoria      = Mapper.Map <Categoria>(viewModel);
            var categoriaExist = _context.Set <Categoria>().FirstOrDefault(x => x.Nombre.ToLower().Trim() == viewModel.Nombre.ToLower().Trim());

            if (categoriaExist != null)
            {
                return(new SystemValidationModel()
                {
                    Success = false, Message = "Ya existe una categoria con el mismo nombre"
                });
            }
            _context.Entry(categoria).State = EntityState.Added;
            foreach (var subCategoria in viewModel.SubCategorias)
            {
                var subCategoriaEntity = Mapper.Map <SubCategoria>(subCategoria);
                _context.Entry(subCategoriaEntity).State = EntityState.Added;
                categoria.SubCategorias.Add(subCategoriaEntity);
            }
            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Success = success,
                Id      = categoria.Id
            };

            return(validation);
        }
        public SystemValidationModel Edit(CategoriaProductosEditViewModel viewModel)
        {
            var checkCatageria = GetByName(viewModel.Nombre);

            if (checkCatageria != null && checkCatageria.Id != viewModel.Id)
            {
                return new SystemValidationModel()
                       {
                           Success = false, Message = "Ya existe una categoria con el mismo nombre"
                       }
            }
            ;
            var categoriaProducto = GetById(viewModel.Id);

            categoriaProducto = Mapper.Map(viewModel, categoriaProducto);

            _context.Entry(categoriaProducto).State = EntityState.Modified;
            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Id      = categoriaProducto.Id,
                Message = success ? "Se ha modificado la categoria" : "No se pudo modificado la categoria",
                Success = success
            };

            return(validation);
        }
예제 #10
0
        public SystemValidationModel Edit(UsuariosEditViewModel viewModel)
        {
            var usuario      = GetById(viewModel.Id);
            var usuarioExist = _context.Set <Usuario>().FirstOrDefault(x => x.Email.ToLower().Trim() == viewModel.Email.ToLower().Trim() && x.Id != viewModel.Id);

            if (usuarioExist != null)
            {
                return(new SystemValidationModel()
                {
                    Success = false, Message = "Ya existe un usuario con el mismo email"
                });
            }
            if (!string.IsNullOrEmpty(viewModel.Password))
            {
                usuario.SetPassword(viewModel.Password);
            }
            usuario = Mapper.Map(viewModel, usuario);
            _context.Entry(usuario).State = EntityState.Modified;
            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Success = success,
                Message = success ? "Se ha editado correctamente el usuario" : "No se pudo editar el usuario"
            };

            return(validation);
        }
예제 #11
0
        public SystemValidationModel Desactivate(int id)
        {
            var cliente = GetById(id);
            var ventas  = _context.Set <Venta>().Where(x => x.Active && x.Estado != Constants.EstadoVenta.Anulado && x.ClienteId == id);

            if (ventas.Count() > 0)
            {
                return new SystemValidationModel()
                       {
                           Success = false, Message = "No se puede eliminar un cliente que tiene ventas"
                       }
            }
            ;
            cliente.Active = false;
            _context.Entry(cliente).State = EntityState.Modified;
            foreach (var direccion in cliente.Direcciones)
            {
                direccion.Active = false;

                _context.Entry(direccion).State = EntityState.Modified;
            }
            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Success = success,
                Message = success ? "Se ha eliminado correctamente el cliente" : "No se pudo eliminar el cliente"
            };

            return(validation);
        }
    }
        public SystemValidationModel Save(SucursalesAddViewModel viewModel)
        {
            var checkSucursal = GetByName(viewModel.Nombre);

            if (checkSucursal != null)
            {
                return new SystemValidationModel()
                       {
                           Success = false, Message = "Ya existe una sucursal con el mismo nombre"
                       }
            }
            ;
            checkSucursal = GetAll().FirstOrDefault(x => x.CodigoEstablecimiento == viewModel.CodigoEstablecimiento);
            if (checkSucursal != null)
            {
                return new SystemValidationModel()
                       {
                           Success = false, Message = "Ya existe una sucursal con el mismo codigo de establecimiento"
                       }
            }
            ;
            var sucursal = Mapper.Map <Sucursal>(viewModel);

            _context.Entry(sucursal).State = EntityState.Added;
            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Id      = sucursal.Id,
                Message = success ? "Se ha guardado correctamente la sucursal" : "No se pudo guardar la sucursal",
                Success = success
            };

            return(validation);
        }
예제 #13
0
        public SystemValidationModel Desactivate(int id)
        {
            var recibo = GetById(id);

            recibo.Active = false;
            _context.Entry(recibo).State = EntityState.Modified;
            var reciboCuotaIds = recibo.Cuotas.Select(x => x.Id);

            var cuotasToDelete = _context.Set <Cuota>().Where(x => x.Active && reciboCuotaIds.Contains(x.Id)).ToList();

            foreach (var cuota in cuotasToDelete)
            {
                cuota.Recibo = null;
                _context.Entry(cuota).State = EntityState.Modified;
            }

            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Id      = recibo.Id,
                Message = success ? "Se ha confirmado correctamente el recibo" : "No se pudo confirmado el recibo",
                Success = success
            };

            return(validation);
        }
예제 #14
0
        public SystemValidationModel Save(ProductosAddViewModel viewModel)
        {
            var producto = Mapper.Map <Producto>(viewModel);

            _context.Entry(producto).State = EntityState.Added;
            foreach (var presentacion in producto.ProductoPresentaciones)
            {
                _context.Entry(presentacion).State = EntityState.Added;
            }
            var productoSucursal = new ProductoSucursal()
            {
                SucursalId = viewModel.SucursalId, Stock = viewModel.Stock
            };

            _context.Entry(productoSucursal).State = EntityState.Added;
            producto.ProductoSucursal.Add(productoSucursal);
            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Id      = producto.Id,
                Message = success ? "Se ha guardado correctamente el producto" : "No se pudo guardar el producto",
                Success = success
            };

            return(validation);
        }
예제 #15
0
        public SystemValidationModel Edit(PedidosEditViewModel viewModel)
        {
            var pedido = GetById(viewModel.Id);

            pedido = Mapper.Map(viewModel, pedido);
            _context.Entry(pedido).State = EntityState.Modified;

            var detalleIdToDelete = pedido.DetallePedido.Select(x => x.Id).Except(viewModel.DetallePedido.Where(x => x.Id > 0).Select(x => x.Id));

            foreach (var detalle in pedido.DetallePedido.Where(x => detalleIdToDelete.Contains(x.Id)))
            {
                _context.Entry(detalle).State = EntityState.Deleted;
            }

            foreach (var detalle in viewModel.DetallePedido.Where(x => x.Id == 0))
            {
                var detallePedido = Mapper.Map <DetallePedido>(detalle);
                _context.Entry(detallePedido).State = EntityState.Added;
                pedido.DetallePedido.Add(detallePedido);
            }

            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Success = success,
                Message = success ? "Se ha editado correctamente el pedido" : "No se pudo editar el pedido"
            };

            return(validation);
        }
예제 #16
0
        public SystemValidationModel ChangeEstado(int id, EstadoPedido estado, string razonAnulado)
        {
            var pedido = GetById(id);

            pedido.Estado = estado;

            if (estado == EstadoPedido.Anulado)
            {
                pedido.RazonAnulado = razonAnulado;
            }
            _context.Entry(pedido).State = EntityState.Modified;
            if (estado == EstadoPedido.EntregadoPorDelivery && !pedido.Delivery)
            {
                return new SystemValidationModel()
                       {
                           Success = false, Message = "El pedido no cuenta con deliver"
                       }
            }
            ;
            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Id      = pedido.Id,
                Message = success ? "Se ha cambiado correctamente el estado del pedido" : "No se pudo modificar",
                Success = success
            };

            return(validation);
        }
    }
        public SystemValidationModel Edit(UpsertCarreraViewModel viewModel)
        {
            var carreraExist = _context.Set <Carrera>().FirstOrDefault(x => x.Nombre.ToLower().Trim() == viewModel.Nombre.ToLower().Trim() && x.Id != viewModel.Id);

            if (carreraExist != null)
            {
                return(new SystemValidationModel()
                {
                    Success = false, Message = "Ya existe una carrera con el mismo nombre"
                });
            }
            carreraExist = _context.Set <Carrera>().FirstOrDefault(x => x.Abreviatura.ToLower().Trim() == viewModel.Abreviatura.ToLower().Trim() && x.Id != viewModel.Id);
            if (carreraExist != null)
            {
                return(new SystemValidationModel()
                {
                    Success = false, Message = "Ya existe una carrera con la misma abreviatura"
                });
            }
            var carrera = GetById(viewModel.Id);

            carrera = Mapper.Map(viewModel, carrera);
            _context.Entry(carrera).State = EntityState.Modified;
            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Success = success,
                Message = success ? "Se ha editado correctamente la carrera" : "No se pudo editar la carrera"
            };

            return(validation);
        }
        public SystemValidationModel Add(UpsertCarreraViewModel viewModel)
        {
            var carrera      = Mapper.Map <Carrera>(viewModel);
            var carreraExist = _context.Set <Carrera>().FirstOrDefault(x => x.Nombre.ToLower().Trim() == viewModel.Nombre.ToLower().Trim());

            if (carreraExist != null)
            {
                return(new SystemValidationModel()
                {
                    Success = false, Message = "Ya existe una carrera con el mismo nombre"
                });
            }
            carreraExist = _context.Set <Carrera>().FirstOrDefault(x => x.Abreviatura.ToLower().Trim() == viewModel.Abreviatura.ToLower().Trim());
            if (carreraExist != null)
            {
                return(new SystemValidationModel()
                {
                    Success = false, Message = "Ya existe una carrera con la misma abreviatura"
                });
            }
            carrera.Active = true;
            _context.Entry(carrera).State = EntityState.Added;
            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Success = success,
                Id      = carrera.Id
            };

            return(validation);
        }
예제 #19
0
        public SystemValidationModel Desactivate(int id)
        {
            var caja = _context.Set <Caja>().Include(x => x.Usuarios).Where(x => x.Active).FirstOrDefault(x => x.Id == id);

            if (caja.Usuarios.Where(x => x.Active).ToList().Count > 0)
            {
                return new SystemValidationModel()
                       {
                           Success = false, Message = "No se puede eliminar, la caja esta asignado a usuarios"
                       }
            }
            ;
            if (caja.Timbrados.Where(x => x.Active).ToList().Count > 0)
            {
                return new SystemValidationModel()
                       {
                           Success = false, Message = "No se puede eliminar, la caja esta asignado a timbrados"
                       }
            }
            ;
            caja.Active = false;
            _context.Entry(caja).State = EntityState.Modified;
            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Id      = caja.Id,
                Message = success ? "Se ha eliminado correctamente la caja" : "No se pudo eliminar la caja",
                Success = success
            };

            return(validation);
        }
예제 #20
0
        public SystemValidationModel Desactivate(int id)
        {
            var rol = _context.Set <Rol>().Include(x => x.Usuarios).Where(x => x.Active).FirstOrDefault(x => x.Id == id);

            if (rol.Usuarios.Where(x => x.Active).ToList().Count > 0)
            {
                return new SystemValidationModel()
                       {
                           Success = false, Message = "No se puede eliminar, el rol esta asignado a usuarios"
                       }
            }
            ;
            rol.Active = false;
            _context.Entry(rol).State = EntityState.Modified;
            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Id      = rol.Id,
                Message = success ? "Se ha eliminado correctamente el rol" : "No se pudo eliminar el rol",
                Success = success
            };

            return(validation);
        }
    }
        public SystemValidationModel Confirmar(OrdenPagoComprasAddViewModel viewModel)
        {
            var ordenPago = GetById(viewModel.Id);

            ordenPago.Estado = Constants.OrdenPagoCompraEstado.Pagado;
            ordenPago.Cambio = viewModel.PagoCompra.Cambio;
            var comprasIds = ordenPago.OrdenPagoDetalle.Select(x => x.CompraId).ToList();
            var compras    = _context.Set <Compra>().Where(x => comprasIds.Contains(x.Id) && x.Active).ToList();

            foreach (var compra in compras)
            {
                compra.Estado = Constants.EstadoCompra.Pagado;
                _context.Entry(compra).State = EntityState.Modified;
            }
            var proveedor = _context.Set <Proveedor>().FirstOrDefault(x => x.Id == viewModel.Proveedor.ProveedorId);

            proveedor.Saldo -= viewModel.MontoTotal;
            _context.Entry(proveedor).State = EntityState.Modified;
            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Id      = ordenPago.Id,
                Message = success ? "Se ha confirmado correctamente la orden de pago" : "No se pudo confirmar la orden de pago",
                Success = success
            };

            return(validation);
        }
예제 #22
0
        public SystemValidationModel Save(VentasAddViewModel viewModel)
        {
            var venta = Mapper.Map <Venta>(viewModel);

            venta.DateCreated = DateTime.Now;
            //var timbrado = _timbrados.GetValidTimbrado(viewModel.SucursalId, viewModel.CajaId);
            //if (timbrado == null)
            //	return new SystemValidationModel() { Success = false, Message = "No existe un timbrado valido registrado" };
            //venta.Timbrado = timbrado;
            //var nroFactura = GetValidNroFactura(timbrado);
            //if (nroFactura == null)
            //	return new SystemValidationModel() { Success = false, Message = "No existen numeros validos para el timbrado actual" };

            if (viewModel.PagoVenta.Cambio != 0)
            {
                venta.Cambio = viewModel.PagoVenta.Cambio;
            }
            DescontarStock(viewModel.DetalleVenta, viewModel.SucursalId);
            venta.Estado = viewModel.CondicionVenta == Constants.CondicionVenta.Contado ? Constants.EstadoVenta.Pagado : Constants.EstadoVenta.PendientedePago;

            if (venta.Estado == Constants.EstadoVenta.Pagado)
            {
                SaveDetalleCaja(venta, viewModel);
            }

            if (venta.CondicionVenta == Constants.CondicionVenta.Credito)
            {
                AumentarSaldoCliente(venta);
            }

            _context.Entry(venta).State = EntityState.Added;
            foreach (var detalle in venta.DetalleVenta)
            {
                _context.Entry(detalle).State = EntityState.Added;
            }
            foreach (var cuota in venta.Cuotas)
            {
                _context.Entry(cuota).State = EntityState.Added;
            }

            if (viewModel.PedidoId != null)
            {
                var pedido = _pedidos.GetById(viewModel.PedidoId.Value);
                ChecForUpdatePedido(pedido, venta.DetalleVenta);
                pedido.Estado = pedido.Delivery ? Constants.EstadoPedido.EntregadoPorDelivery : Constants.EstadoPedido.Finalizado;
                _context.Entry(pedido).State = EntityState.Modified;
            }

            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Id      = venta.Id,
                Message = success ? "Se ha guardado correctamente la venta" : "No se pudo guardar la venta",
                Success = success
            };

            return(validation);
        }
예제 #23
0
        public SystemValidationModel Confirmar(RecibosEditViewModel viewModel)
        {
            var recibo = GetById(viewModel.Id);

            recibo.Estado = Constants.EstadoRecibo.Pagado;
            if (viewModel.PagoRecibo.Cambio != 0)
            {
                recibo.Cambio = viewModel.PagoRecibo.Cambio;
            }
            _context.Entry(recibo).State = EntityState.Modified;
            var reciboCuotaIds    = recibo.Cuotas.Select(x => x.Id);
            var cuotasIds         = viewModel.Cuotas.Select(x => x.CuotaId).ToList();
            var cuotasToDeleteIds = reciboCuotaIds.Except(cuotasIds).ToList();
            var cuotasToAdd       = cuotasIds.Except(reciboCuotaIds).ToList();
            var cuotas            = _context.Set <Cuota>().Where(x => x.Active && x.VentaId == viewModel.Venta.VentaId).ToList();
            var cuotasToConfirm   = cuotas.Where(x => x.Active && (cuotasToAdd.Contains(x.Id) || (x.ReciboId == viewModel.Id && !cuotasToDeleteIds.Contains(x.Id)))).ToList();

            SaveDetalleCaja(recibo, viewModel);
            DisminuirSaldoCliente(recibo);
            var cuotasToDelete = _context.Set <Cuota>().Where(x => x.Active && cuotasToDeleteIds.Contains(x.Id)).ToList();

            foreach (var cuota in cuotasToConfirm)
            {
                cuota.Estado = Constants.EstadoCuota.Pagado;
                if (cuota.ReciboId == null)
                {
                    recibo.Cuotas.Add(cuota);
                }
                _context.Entry(cuota).State = EntityState.Modified;
            }

            foreach (var cuota in cuotasToDelete)
            {
                cuota.Recibo = null;
                _context.Entry(cuota).State = EntityState.Modified;
            }

            var venta       = _context.Set <Venta>().FirstOrDefault(x => x.Id == viewModel.Venta.VentaId);
            var totalCuotas = cuotas.Where(x => x.Estado == Constants.EstadoCuota.Pagado).Sum(x => x.Monto);

            if (venta.MontoTotal == totalCuotas)
            {
                venta.Estado = Constants.EstadoVenta.Pagado;
                _context.Entry(venta).State = EntityState.Modified;
            }

            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Id      = recibo.Id,
                Message = success ? "Se ha confirmado correctamente el recibo" : "No se pudo confirmado el recibo",
                Success = success
            };

            return(validation);
        }
예제 #24
0
        public SystemValidationModel Edit(Venta venta)
        {
            _context.Entry(venta).State = EntityState.Modified;

            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Message = success ? "Se ha editado correctamente la venta" : "No se pudo editado la venta",
                Success = success
            };

            return(validation);
        }
예제 #25
0
        public SystemValidationModel Edit(Usuario usuario)
        {
            _context.Entry(usuario).State = EntityState.Modified;
            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Id      = usuario.Id,
                Message = success ? "Se ha editado correctamente el usuario" : "No se pudo editar el usuario",
                Success = success
            };

            return(validation);
        }
        public SystemValidationModel Save(AddActaEUViewModel viewModel)
        {
            var estudiante = _estudiantes.GetByCedulaIdentidad(viewModel.CedulaIdentidad);

            if (estudiante == null)
            {
                return new SystemValidationModel()
                       {
                           Message = "No existe un estudiante registrado con la cedula de identidad", Success = false
                       }
            }
            ;
            var acta = new ActaEU()
            {
                EstudianteId = estudiante.Id,
                CarreraId    = viewModel.CarreraSeleccionadaId,
            };

            foreach (var categoria in viewModel.Categorias)
            {
                foreach (var subcategoria in categoria.Detalle)
                {
                    if (subcategoria.HorasExtensionRealizadas != 0 && subcategoria.HorasRelojRealizadas != 0)
                    {
                        var detalleActa = Mapper.Map <ActaEUDetalle>(subcategoria);

                        if (subcategoria.SubCategoriaId == 0)
                        {   //significa que la categoria no tiene subcategoria
                            detalleActa.CategoriaId    = categoria.CategoriaId;
                            detalleActa.SubCategoriaId = null;
                        }
                        else
                        {
                            detalleActa.SubCategoriaId = subcategoria.SubCategoriaId;
                        }
                        _context.Entry(detalleActa).State = EntityState.Added;
                        acta.ActaEUDetalle.Add(detalleActa);
                    }
                }
            }
            _context.Entry(acta).State = EntityState.Added;
            var actaId     = _context.SaveChanges();
            var validation = new SystemValidationModel()
            {
                Id      = actaId,
                Success = actaId > 0
            };

            return(validation);
        }
예제 #27
0
        public SystemValidationModel Edit(ClientesEditViewModel viewModel)
        {
            var cliente = GetAll().FirstOrDefault(x => x.Id != viewModel.Id && x.RazonSocial == viewModel.RazonSocial);

            if (cliente != null)
            {
                return new SystemValidationModel()
                       {
                           Success = false, Message = "Ya existe un cliente registrado con el mismo razon social"
                       }
            }
            ;
            cliente = GetAll().FirstOrDefault(x => x.Id != viewModel.Id && x.Ruc == viewModel.Ruc);
            if (cliente != null)
            {
                return new SystemValidationModel()
                       {
                           Success = false, Message = "Ya existe un cliente registrado con el mismo RUC"
                       }
            }
            ;

            cliente = GetById(viewModel.Id);
            cliente = Mapper.Map(viewModel, cliente);
            _context.Entry(cliente).State = EntityState.Modified;

            var direccionesIdToDelete = cliente.Direcciones.Select(x => x.Id).Except(viewModel.Direcciones.Where(x => x.Id > 0).Select(x => x.Id));

            foreach (var direccion in cliente.Direcciones.Where(x => direccionesIdToDelete.Contains(x.Id)))
            {
                _context.Entry(direccion).State = EntityState.Deleted;
            }

            foreach (var direccion in viewModel.Direcciones.Where(x => x.Id == 0))
            {
                var direccionEntity = Mapper.Map <Direccion>(direccion);
                _context.Entry(direccionEntity).State = EntityState.Added;
                cliente.Direcciones.Add(direccionEntity);
            }

            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Success = success,
                Message = success ? "Se ha editado correctamente el cliente" : "No se pudo editar el cliente"
            };

            return(validation);
        }
예제 #28
0
        public SystemValidationModel Desactivate(int id)
        {
            var estudiante = GetById(id);

            estudiante.Active = false;
            _context.Entry(estudiante).State = EntityState.Modified;
            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Success = success,
                Message = success ? "Se ha eliminado el estudiante" : "No se pudo eliminar el estudiante"
            };

            return(validation);
        }
예제 #29
0
        public SystemValidationModel Anular(int id)
        {
            var venta = GetById(id);

            venta.Estado = Constants.EstadoVenta.Anulado;
            _context.Entry(venta).State = EntityState.Modified;
            var success    = _context.SaveChanges() > 0;
            var validation = new SystemValidationModel()
            {
                Message = success ? "Se ha confirmado correctamente la venta" : "No se pudo confirmar la venta",
                Success = success
            };

            return(validation);
        }
예제 #30
0
        public async Task <SystemValidationModel> ChangeSucursal(int id)
        {
            var user     = _usuarios.GetForLogin(Email);
            var sucursal = _sucursales.GetById(id);
            await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

            var claims = new ClaimsIdentity(SecurityHelper.GetUserClaims(user, sucursal), "Cookie");
            await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claims));

            var validation = new SystemValidationModel()
            {
                Success = true
            };

            return(validation);
        }