Exemple #1
0
        public async Task <ActionResult <EmployeeExtraHoursDetail> > Insert([FromBody] EmployeeExtraHoursDetail _EmployeeExtraHoursDetail)
        {
            EmployeeExtraHoursDetail _EmployeeExtraHoursDetailq = new EmployeeExtraHoursDetail();

            try
            {
                using (var transaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        _EmployeeExtraHoursDetailq = _EmployeeExtraHoursDetail;
                        Customer _custo = new Customer();
                        _custo = await _context.Customer
                                 .Where(q => q.CustomerId == _EmployeeExtraHoursDetail.CustomerId).FirstOrDefaultAsync();

                        _EmployeeExtraHoursDetailq.CustomerName = _custo.CustomerName;
                        _context.EmployeeExtraHoursDetail.Add(_EmployeeExtraHoursDetailq);
                        await _context.SaveChangesAsync();

                        BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora
                        {
                            IdOperacion  = _EmployeeExtraHoursDetailq.EmployeeExtraHoursDetailId,
                            DocType      = "EmployeeExtraHoursDetail",
                            ClaseInicial =
                                Newtonsoft.Json.JsonConvert.SerializeObject(_EmployeeExtraHoursDetailq, new JsonSerializerSettings {
                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                            }),
                            Accion              = "Insertar",
                            FechaCreacion       = DateTime.Now,
                            FechaModificacion   = DateTime.Now,
                            UsuarioCreacion     = _EmployeeExtraHoursDetailq.UsuarioCreacion,
                            UsuarioModificacion = _EmployeeExtraHoursDetailq.UsuarioModificacion,
                            UsuarioEjecucion    = _EmployeeExtraHoursDetailq.UsuarioModificacion,
                        });

                        await _context.SaveChangesAsync();

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                        throw ex;
                    }
                }
            }
            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(_EmployeeExtraHoursDetailq)));
        }
Exemple #2
0
        public async Task <IActionResult> GetEmployeeExtraHoursDetailById(Int64 EmployeeExtraHoursDetailId)
        {
            EmployeeExtraHoursDetail Items = new EmployeeExtraHoursDetail();

            try
            {
                Items = await _context.EmployeeExtraHoursDetail.Where(q => q.EmployeeExtraHoursDetailId == EmployeeExtraHoursDetailId).FirstOrDefaultAsync();
            }
            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(Items)));
        }