public GetLastEstadoBitacoraByBecarioIdResponse GetLastEstadoBitacoraByBecarioId(int becarioId)
        {
            var response = new GetLastEstadoBitacoraByBecarioIdResponse();

            try
            {
                var bitacorasRevertibles = _bitacoraBecarioRepository.GetByCriteria(x => x.BecarioId == becarioId && x.TipoBitacora.HasValue && x.Revertible.HasValue && x.Revertible.Value);

                bitacorasRevertibles = bitacorasRevertibles.OrderByDescending(x => x.BitacoraId);
                var bitacoraARevertir = bitacorasRevertibles.FirstOrDefault();

                if (bitacoraARevertir != null)
                {
                    var becario = _becarioRepository.GetOne(x => x.BecarioId == becarioId);

                    if (becario != null && (bitacoraARevertir.EstadoAnteriorId.HasValue))
                    {
                        response.EstadoAnteriorId = (int)bitacoraARevertir.EstadoAnteriorId;
                        response.IsValid          = true;
                    }
                }
            }
            catch (Exception ex)
            {
                response.IsValid      = false;
                response.ErrorMessage = ex.Message;
            }
            return(response);
        }
示例#2
0
        public BacktrackBecarioResponse BacktrackBecario(int becarioId)
        {
            var response = new BacktrackBecarioResponse();

            try
            {
                var bitacorasRevertibles = _bitacoraBecarioRepository.GetByCriteria(x => x.BecarioId == becarioId && x.TipoBitacora.HasValue && x.Revertible.HasValue && x.Revertible.Value);

                bitacorasRevertibles = bitacorasRevertibles.OrderByDescending(x => x.BitacoraId);
                var bitacoraARevertir = bitacorasRevertibles.FirstOrDefault();

                if (bitacoraARevertir != null)
                {
                    var becario = _becarioRepository.GetOne(x => x.BecarioId == becarioId);

                    if (becario != null)
                    {
                        if (bitacoraARevertir.EstadoAnteriorId.HasValue)
                        {
                            becario.TipoEstadoBecarioId = bitacoraARevertir.EstadoAnteriorId.Value;
                        }

                        _becarioRepository.Update(becario);

                        bitacoraARevertir.Revertible = false;
                        _bitacoraBecarioRepository.Update(bitacoraARevertir);

                        _bitacoraBecarioService.GenerateBitacoraBecarioRetroceder(becario.BecarioId, bitacoraARevertir.BitacoraId);
                        response.IsValid = true;
                    }
                }
            }
            catch (Exception ex)
            {
                response.IsValid      = false;
                response.ErrorMessage = ex.Message;
            }
            return(response);
        }