Пример #1
0
        public Respuesta MapFromDTORespuesta(DTORespuesta dto)
        {
            if (dto == null)
            {
                return(null);
            }
            Respuesta respuesta = new Respuesta()
            {
                Pregunta_idPregunta = dto.Pregunta_idPregunta,
                esCorrectoRespuesta = dto.esCorrectoRespuesta,
                contenidoRespuesta  = dto.contenidoRespuesta
            };

            PartidaMapper _mapperPartida = new PartidaMapper();

            if (dto.respondieron != null)
            {
                foreach (DTOPartida part in dto.respondieron)
                {
                    respuesta.respondieron.Add(_mapperPartida.MapFromDTO(part));
                }
            }

            return(respuesta);
        }
Пример #2
0
        public void UpdateRespuesta(int id, DTORespuesta respuesta)
        {
            try
            {
                using (UnitOfWork uow = new UnitOfWork())
                {
                    Respuesta entity = uow.RespuestaRepository.Get(id);
                    entity.idRespuesta         = respuesta.idRespuesta;
                    entity.contenidoRespuesta  = respuesta.contenidoRespuesta;
                    entity.esCorrectoRespuesta = respuesta.esCorrectoRespuesta;
                    entity.Pregunta_idPregunta = respuesta.Pregunta_idPregunta;
                    List <Partida> partidas = new List <Partida>();
                    foreach (var entityP in respuesta.respondieron)
                    {
                        Partida partida = new Partida();
                        partida.id                 = entityP.id;
                        partida.Juego_idJuego      = entityP.Juego_idJuego;
                        partida.User_loginnameUser = entityP.User_loginnameUser;
                        partida.nickUsuario        = entityP.nickUsuario;
                        partidas.Add(partida);
                    }

                    //User entityU = repositorioU.Get(respuesta.respondieron)


                    entity.respondieron = partidas;

                    uow.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #3
0
        public DTORespuesta MapToDTO(Respuesta respuesta)
        {
            if (respuesta == null)
            {
                return(null);
            }
            DTORespuesta pRespuesta = new DTORespuesta()
            {
                idRespuesta         = respuesta.idRespuesta,
                Pregunta_idPregunta = respuesta.Pregunta_idPregunta,
                esCorrectoRespuesta = respuesta.esCorrectoRespuesta,
                contenidoRespuesta  = respuesta.contenidoRespuesta,
            };

            PartidaMapper _mapperPartida = new PartidaMapper();

            if (respuesta.respondieron != null)
            {
                pRespuesta.respondieron = new List <DTOPartida>();
                foreach (Partida part in respuesta.respondieron)
                {
                    pRespuesta.respondieron.Add(_mapperPartida.MapToDTO(part));
                }
            }


            return(pRespuesta);
        }
Пример #4
0
        public IHttpActionResult UpdateRespuesta(int id, DTORespuesta respuesta)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != respuesta.idRespuesta)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            DTOBaseResponse response = new DTOBaseResponse();

            try
            {
                BusinessLogic.Controllers.RespuestaController controller = new BusinessLogic.Controllers.RespuestaController();
                controller.UpdateRespuesta(id, respuesta);
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error   = ex.ToString();
            }
            return(Ok(response));
        }
Пример #5
0
 public DTORespuesta GetRespuesta(int id)
 {
     using (UnitOfWork uow = new UnitOfWork())
     {
         var entity = uow.RespuestaRepository.Get(id);
         if (entity == null)
         {
             return(null);
         }
         DTORespuesta respuesta = _mapper.MapToDTO(entity);
         return(respuesta);
     }
 }
Пример #6
0
 public void CreateRespuesta(DTORespuesta respuesta)
 {
     try
     {
         using (UnitOfWork uow = new UnitOfWork())
         {
             uow.RespuestaRepository.Create(_mapper.MapFromDTORespuesta(respuesta));
             uow.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #7
0
        public DTORespuesta ValidaLogin(DTOLogin login)
        {
            DTORespuesta respuesta = modelo.ValidaLogin(login);

            if ((bool)respuesta.Resultado)
            {
                DTOUsuario user = mapper.Map <DTOUsuario, DTOUsuario>((DTOUsuario)respuesta.Elemento);

                DTOSessionUsuario sess = new DTOSessionUsuario();
                sess.Usuario         = mapper.Map <DTOUsuario, DTOUsuario>(user);
                sess.Funcionalidades = mFuncionalidad.GetFuncionalidadesByLogin(login.USU_USERNAME);

                UrlHelper url = new UrlHelper(System.Web.HttpContext.Current.Request.RequestContext);

                RegisterSession(sess);
            }

            return(respuesta);
        }
Пример #8
0
        public async Task <ActionResult> Login(DTOLogin user)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (string.IsNullOrWhiteSpace(user.USU_USERNAME) || string.IsNullOrWhiteSpace(user.USU_PASS))
                    {
                        return(RedirectToAction("Index", "Login"));
                    }

                    MSession     modelo    = new MSession();
                    DTORespuesta respuesta = modelo.ValidaLogin(user);

                    if ((bool)respuesta.Resultado)
                    {
                        DTOSessionUsuario sess = (DTOSessionUsuario)MSession.ReturnSessionObject();
                        sess.Usuario = await modeloLogin.UpdateUsuario(sess.Usuario);

                        //TODO: Eliminar los archivos asociados al usuario. (Async)
                        mFile = new MFile();
                        await mFile.eliminarArchivosByLoginAsync(sess.Usuario.USU_LOGIN);

                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        Session["ResultadoAccesoLogin"] = respuesta;
                        return(RedirectToAction("Index", "Login"));
                    }
                }
                else
                {
                    return(RedirectToAction("Index", "Login"));
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Login"));
            }
        }
        public DTORespuesta ValidaLogin(DTOLogin login)
        {
            DTORespuesta respuesta = new DTORespuesta();

            Essbio.SUL.Seguridad.Usuario user = null;
            try
            {
                user = new Essbio.SUL.Seguridad.Usuario(login.USU_USERNAME, login.USU_PASS);
            }
            catch (Exception ex)
            {
                respuesta.Resultado = false;
                respuesta.Mensaje   = ex.Message.Replace("<br/>", "\\n");
                return(respuesta);
            }

            try
            {
                if (ValidaAdmin(login) == false)
                {
                    if (user != null)
                    {
                        DTOUsuario usuario = new DTOUsuario();
                        usuario.USU_DV_RUT             = "";
                        usuario.USU_ID_USUARIO         = user.P_ID_USUARIO;
                        usuario.USU_LOGIN              = login.USU_USERNAME;
                        usuario.USU_NOMBRE_COMPLETO    = login.USU_USERNAME;
                        usuario.USU_PERF_ADMINISTRADOR = true;
                        usuario.USU_PERF_ID_PERFIL     = 0;
                        usuario.USU_RUT          = 0;
                        usuario.USU_RUT_COMPLETO = "";
                        usuario.USU_SED_ID_SEDE  = 0;
                        usuario.USU_VIGENTE      = true;

                        if (user.EstadoUsuario == Essbio.SUL.Seguridad.EstadoUsuario.Logeado)
                        {
                            respuesta.Resultado = true;
                            respuesta.Elemento  = usuario;
                        }
                        else
                        {
                            respuesta.Resultado = false;
                            respuesta.Mensaje   = "La cuenta de usuario esta no vigente, comuníquese con el administrador del sistema";
                        }
                    }
                    else
                    {
                        respuesta.Resultado = false;
                        respuesta.Mensaje   = "Las credenciales ingresadas no son correctas, reingrese nuevamente";
                    }
                }
                else
                {
                    DTOUsuario usuario = new DTOUsuario();

                    if (usuario.USU_ID_USUARIO > 0)
                    {
                        respuesta.Resultado = true;
                        respuesta.Elemento  = usuario;
                    }
                    else
                    {
                        respuesta.Resultado = false;
                        respuesta.Mensaje   = "La cuenta de usuario esta no vigente, comuníquese con el administrador del sistema";
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(respuesta);
        }