Exemplo n.º 1
0
        public async Task <IActionResult> GetEndososSaldoByLineByIdCD(EndososCertificadosLine _EndososCertificadosLine)
        {
            EndososLiberacion Items = new EndososLiberacion();

            try
            {
                Items = await _context.EndososLiberacion
                        .OrderByDescending(q => q.EndososLiberacionId)
                        .Where(q => q.EndososLineId == _EndososCertificadosLine.EndososCertificadosLineId)
                        .FirstOrDefaultAsync();

                EndososCertificadosLine _endosoline = await
                                                      _context.EndososCertificadosLine
                                                      .Where(q => q.EndososCertificadosLineId == _EndososCertificadosLine.EndososCertificadosLineId).FirstOrDefaultAsync();

                if (Items == null)
                {
                    Items = new EndososLiberacion {
                        EndososId = 0, EndososLineId = 0, Saldo = _endosoline.Quantity
                    };
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(BadRequest($"Ocurrio un error:{ex.Message}"));
            }

            //  int Count = Items.Count();
            return(Ok(Items));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetEndososCertificadosLineById(Int64 EndososCertificadosLineId)
        {
            EndososCertificadosLine Items = new EndososCertificadosLine();

            try
            {
                Items = await _context.EndososCertificadosLine.Where(q => q.EndososCertificadosLineId == EndososCertificadosLineId).FirstOrDefaultAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(BadRequest($"Ocurrio un error:{ex.Message}"));
            }


            return(Ok(Items));
        }
Exemplo n.º 3
0
        public async Task <ActionResult <EndososCertificadosLine> > Insert([FromBody] EndososCertificadosLine _EndososCertificadosLine)
        {
            EndososCertificadosLine _EndososCertificadosLineq = new EndososCertificadosLine();

            try
            {
                _EndososCertificadosLineq = _EndososCertificadosLine;
                _context.EndososCertificadosLine.Add(_EndososCertificadosLineq);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(BadRequest($"Ocurrio un error:{ex.Message}"));
            }

            return(Ok(_EndososCertificadosLineq));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Delete([FromBody] EndososCertificadosLine _EndososCertificadosLine)
        {
            EndososCertificadosLine _EndososCertificadosLineq = new EndososCertificadosLine();

            try
            {
                _EndososCertificadosLineq = _context.EndososCertificadosLine
                                            .Where(x => x.EndososCertificadosLineId == (Int64)_EndososCertificadosLine.EndososCertificadosLineId)
                                            .FirstOrDefault();

                _context.EndososCertificadosLine.Remove(_EndososCertificadosLineq);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(BadRequest($"Ocurrio un error:{ex.Message}"));
            }

            return(Ok(_EndososCertificadosLineq));
        }
Exemplo n.º 5
0
        public async Task <ActionResult <EndososCertificadosLine> > Update([FromBody] EndososCertificadosLine _EndososCertificadosLine)
        {
            EndososCertificadosLine _EndososCertificadosLineq = _EndososCertificadosLine;

            try
            {
                _EndososCertificadosLineq = await(from c in _context.EndososCertificadosLine
                                                  .Where(q => q.EndososCertificadosLineId == _EndososCertificadosLine.EndososCertificadosLineId)
                                                  select c
                                                  ).FirstOrDefaultAsync();

                _context.Entry(_EndososCertificadosLineq).CurrentValues.SetValues((_EndososCertificadosLine));

                //_context.EndososCertificadosLine.Update(_EndososCertificadosLineq);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(BadRequest($"Ocurrio un error:{ex.Message}"));
            }

            return(Ok(_EndososCertificadosLineq));
        }
Exemplo n.º 6
0
        public async Task <ActionResult <GoodsReceived> > AgruparCertificados([FromBody] List <Int64> listacertificados)
        {
            List <CertificadoDeposito> _goodsreceivedlis = new List <CertificadoDeposito>();

            try
            {
                string inparams = "";
                foreach (var item in listacertificados)
                {
                    inparams += item + ",";
                }

                inparams = inparams.Substring(0, inparams.Length - 1);


                _goodsreceivedlis = await _context.CertificadoDeposito.Include(q => q._CertificadoLine)
                                    .Where(q => listacertificados.Contains(q.IdCD)).ToListAsync();

                foreach (var item in _goodsreceivedlis)
                {
                    Int64 Id = 0;
                    Id = await _context.EndososCertificados
                         .Where(q => q.IdCD == item.IdCD)
                         .Select(q => q.EndososCertificadosId).FirstOrDefaultAsync();

                    if (Id > 0)
                    {
                        EndososLiberacion _endosoliberado = new EndososLiberacion();
                        _endosoliberado = await _context.EndososLiberacion
                                          .Where(q => q.EndososId == Id)
                                          .FirstOrDefaultAsync();

                        EndososCertificadosLine line = await _context.EndososCertificadosLine
                                                       .Where(q => q.EndososCertificadosLineId == _endosoliberado.EndososLineId)
                                                       .FirstOrDefaultAsync();

                        CertificadoLine _cline = item._CertificadoLine.Where(q => q.SubProductId == line.SubProductId).FirstOrDefault();
                        _cline.Quantity = _cline.Quantity - _endosoliberado.Saldo;
                    }
                }



                //_goodsreceivedlis = await _context.CertificadoDeposito.Where(q => q.IdCD == Convert.ToInt64(listacertificados[0])).FirstOrDefault();

                //using (var command = _context.Database.GetDbConnection().CreateCommand())
                //{
                //    command.CommandText = ("  SELECT  grl.SubProductId,grl.UnitMeasureId, grl.SubProductName, grl.UnitMeasurName         "
                //   + " , SUM(Quantity) AS Cantidad, SUM(grl.IdCD) AS IdCD         "
                //   + " , SUM(grl.Quantity) * (grl.Price)  AS Total                            "
                //   + " ,Price "
                //   + $"  FROM CertificadoLine grl                 where  CertificadoLineId in ({inparams})                                "
                //   + "  GROUP BY grl.SubProductId,grl.UnitMeasureId, grl.SubProductName, grl.UnitMeasurName,grl.IdCD,grl.Price       "
                // );

                //    _context.Database.OpenConnection();
                //    using (var result = command.ExecuteReader())
                //    {
                //        // do something with result
                //        while (await result.ReadAsync())
                //        {
                //            _goodsreceivedlis._CertificadoLine.Add(new CertificadoLine
                //            {
                //                SubProductId = Convert.ToInt64(result["SubProductId"]),
                //                SubProductName = result["SubProductName"].ToString(),
                //                UnitMeasureId = Convert.ToInt64(result["UnitMeasureId"]),
                //                UnitMeasurName = result["UnitMeasurName"].ToString(),
                //                Quantity = Convert.ToInt32(result["Cantidad"]),
                //                IdCD = Convert.ToInt32(result["IdCD"]),
                //                Price = Convert.ToDouble(result["Price"]),

                //               // Total = Convert.ToDouble(result["Total"]),

                //            });
                //        }
                //    }
                //}
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                throw ex;
            }

            return(await Task.Run(() => Ok(_goodsreceivedlis)));
        }