public async Task <IActionResult> GetJournalEntryConfigurationLineById(Int64 JournalEntryConfigurationLineId)
        {
            JournalEntryConfigurationLine Items = new JournalEntryConfigurationLine();

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


            return(await Task.Run(() => Ok(Items)));
        }
Пример #2
0
        public async Task <ActionResult <JournalEntryConfiguration> > Update([FromBody] JournalEntryConfiguration _JournalEntryConfiguration)
        {
            JournalEntryConfiguration _JournalEntryConfigurationq = new JournalEntryConfiguration();

            try
            {
                _JournalEntryConfigurationq = await(from c in _context.JournalEntryConfiguration
                                                    .Where(q => q.JournalEntryConfigurationId == _JournalEntryConfiguration.JournalEntryConfigurationId)
                                                    select c
                                                    ).FirstOrDefaultAsync();

                _context.Entry(_JournalEntryConfigurationq).CurrentValues.SetValues((_JournalEntryConfiguration));


                foreach (var item in _JournalEntryConfiguration.JournalEntryConfigurationLine)
                {
                    item.JournalEntryConfigurationId = _JournalEntryConfigurationq.JournalEntryConfigurationId;

                    JournalEntryConfigurationLine data = await _context.JournalEntryConfigurationLine
                                                         .Where(q => q.JournalEntryConfigurationLineId == item.JournalEntryConfigurationLineId).FirstOrDefaultAsync();

                    if (data == null)
                    {
                        _context.JournalEntryConfigurationLine.Add(item);
                    }
                    else
                    {
                        _context.Entry(data).CurrentValues.SetValues((item));
                    }
                }



                //_context.JournalEntryConfiguration.Update(_JournalEntryConfigurationq);
                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(_JournalEntryConfigurationq)));
        }
        public async Task <ActionResult <JournalEntryConfigurationLine> > Insert([FromBody] JournalEntryConfigurationLine _JournalEntryConfigurationLine)
        {
            JournalEntryConfigurationLine _JournalEntryConfigurationLineq = new JournalEntryConfigurationLine();

            try
            {
                _JournalEntryConfigurationLineq = _JournalEntryConfigurationLine;
                _JournalEntryConfigurationLineq.FechaCreacion     = DateTime.Now;
                _JournalEntryConfigurationLineq.FechaModificacion = DateTime.Now;
                _context.JournalEntryConfigurationLine.Add(_JournalEntryConfigurationLineq);
                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(_JournalEntryConfigurationLineq)));
        }
        public async Task <IActionResult> Delete([FromBody] JournalEntryConfigurationLine _JournalEntryConfigurationLine)
        {
            JournalEntryConfigurationLine _JournalEntryConfigurationLineq = new JournalEntryConfigurationLine();

            try
            {
                _JournalEntryConfigurationLineq = _context.JournalEntryConfigurationLine
                                                  .Where(x => x.JournalEntryConfigurationLineId == (Int64)_JournalEntryConfigurationLine.JournalEntryConfigurationLineId)
                                                  .FirstOrDefault();

                _context.JournalEntryConfigurationLine.Remove(_JournalEntryConfigurationLineq);
                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(_JournalEntryConfigurationLineq)));
        }
        public async Task <ActionResult <JournalEntryConfigurationLine> > Update([FromBody] JournalEntryConfigurationLine _JournalEntryConfigurationLine)
        {
            JournalEntryConfigurationLine _JournalEntryConfigurationLineq = _JournalEntryConfigurationLine;

            try
            {
                _JournalEntryConfigurationLineq = await(from c in _context.JournalEntryConfigurationLine
                                                        .Where(q => q.JournalEntryConfigurationLineId == _JournalEntryConfigurationLine.JournalEntryConfigurationLineId)
                                                        select c
                                                        ).FirstOrDefaultAsync();

                _context.Entry(_JournalEntryConfigurationLineq).CurrentValues.SetValues((_JournalEntryConfigurationLine));

                //_context.JournalEntryConfigurationLine.Update(_JournalEntryConfigurationLineq);
                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(_JournalEntryConfigurationLineq)));
        }