Example #1
0
        public async Task <IActionResult> GetPurchDocumentById(Int64 PurchDocumentId)
        {
            PurchDocument Items = new PurchDocument();

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


            return(await Task.Run(() => Ok(Items)));
        }
Example #2
0
        public async Task <ActionResult <PurchDocument> > Insert([FromBody] PurchDocument _PurchDocument)
        {
            PurchDocument _PurchDocumentq = new PurchDocument();

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

            return(await Task.Run(() => Ok(_PurchDocumentq)));
        }
Example #3
0
        public async Task <IActionResult> Delete([FromBody] PurchDocument _PurchDocument)
        {
            PurchDocument _PurchDocumentq = new PurchDocument();

            try
            {
                _PurchDocumentq = _context.PurchDocument
                                  .Where(x => x.PurchDocumentId == (Int64)_PurchDocument.PurchDocumentId)
                                  .FirstOrDefault();

                _context.PurchDocument.Remove(_PurchDocumentq);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(await Task.Run(() => BadRequest($"Ocurrio un error:{ex.Message}")));
            }

            return(await Task.Run(() => Ok(_PurchDocumentq)));
        }
Example #4
0
        public async Task <ActionResult <PurchDocument> > Update([FromBody] PurchDocument _PurchDocument)
        {
            PurchDocument _PurchDocumentq = _PurchDocument;

            try
            {
                _PurchDocumentq = await(from c in _context.PurchDocument
                                        .Where(q => q.PurchDocumentId == _PurchDocument.PurchDocumentId)
                                        select c
                                        ).FirstOrDefaultAsync();

                _context.Entry(_PurchDocumentq).CurrentValues.SetValues((_PurchDocument));
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(await Task.Run(() => BadRequest($"Ocurrio un error:{ex.Message}")));
            }

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