public int New_(string p_descripcion, int p_tema, string p_usuario, Nullable <DateTime> p_fecha) { RespuestaEN respuestaEN = null; int oid; //Initialized RespuestaEN respuestaEN = new RespuestaEN(); respuestaEN.Descripcion = p_descripcion; if (p_tema != -1) { // El argumento p_tema -> Property tema es oid = false // Lista de oids id respuestaEN.Tema = new DSMGitGenNHibernate.EN.DSMGit.TemaEN(); respuestaEN.Tema.Id = p_tema; } if (p_usuario != null) { // El argumento p_usuario -> Property usuario es oid = false // Lista de oids id respuestaEN.Usuario = new DSMGitGenNHibernate.EN.DSMGit.UsuarioEN(); respuestaEN.Usuario.Email = p_usuario; } respuestaEN.Fecha = p_fecha; //Call to RespuestaCAD oid = _IRespuestaCAD.New_(respuestaEN); return(oid); }
public void Borrar(int id ) { try { SessionInitializeTransaction(); RespuestaEN respuestaEN = (RespuestaEN)session.Load(typeof(RespuestaEN), id); session.Delete(respuestaEN); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is ReciclaUAGenNHibernate.Exceptions.ModelException) { throw ex; } throw new ReciclaUAGenNHibernate.Exceptions.DataLayerException("Error in RespuestaCAD.", ex); } finally { SessionClose(); } }
public RespuestaEN ReadOIDDefault(int id ) { RespuestaEN respuestaEN = null; try { SessionInitializeTransaction(); respuestaEN = (RespuestaEN)session.Get(typeof(RespuestaEN), id); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is ReciclaUAGenNHibernate.Exceptions.ModelException) { throw ex; } throw new ReciclaUAGenNHibernate.Exceptions.DataLayerException("Error in RespuestaCAD.", ex); } finally { SessionClose(); } return(respuestaEN); }
public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here SessionInitialize(); RespuestaCAD respuestaCAD = new RespuestaCAD(session); RespuestaCEN respuestaCEN = new RespuestaCEN(respuestaCAD); RespuestaEN respuestaEN = respuestaCEN.ReadOID(id); RespuestaModel respuesta = RespuestaAssembler.ConvertENToModelUI(respuestaEN); TemaModel tem = new TemaModel(); TemaEN temEN = new TemaCAD(session).ReadOIDDefault(respuestaEN.Tema.Id); tem = TemaAssembler.ConvertENToModelUI(temEN); SessionClose(); new RespuestaCEN().Destroy(id); return(RedirectToRoute(new { controller = "Tema", action = "Details", id = tem.Id, })); } catch { return(View()); } }
// Modify default (Update all attributes of the class) public void ModifyDefault(RespuestaEN respuesta) { try { SessionInitializeTransaction(); RespuestaEN respuestaEN = (RespuestaEN)session.Load(typeof(RespuestaEN), respuesta.Id); respuestaEN.Descripcion = respuesta.Descripcion; respuestaEN.Fecha = respuesta.Fecha; session.Update(respuestaEN); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is DSMGitGenNHibernate.Exceptions.ModelException) { throw ex; } throw new DSMGitGenNHibernate.Exceptions.DataLayerException("Error in RespuestaCAD.", ex); } finally { SessionClose(); } }
public RespuestaEN ReadOID(int id ) { RespuestaEN respuestaEN = null; respuestaEN = _IRespuestaCAD.ReadOID(id); return(respuestaEN); }
public RespuestaEN BuscarPorId(int id ) { RespuestaEN respuestaEN = null; respuestaEN = _IRespuestaCAD.BuscarPorId(id); return(respuestaEN); }
// GET: Respuesta/Details/5 public ActionResult Details(int id) { SessionInitialize(); RespuestaCAD respuestaCAD = new RespuestaCAD(session); RespuestaEN respuestas = respuestaCAD.ReadOIDDefault(id); RespuestaModel respuestaModel = RespuestaAssembler.ConvertENToModelUI(respuestas); SessionClose(); return(View(respuestaModel)); }
public void IndicarRespuestaUtil(int p_oid) { /*PROTECTED REGION ID(ReciclaUAGenNHibernate.CEN.ReciclaUA_Respuesta_indicarRespuestaUtil) ENABLED START*/ RespuestaEN resp = _IRespuestaCAD.BuscarPorId(p_oid); resp.Util++; _IRespuestaCAD.Modificar(resp); /*PROTECTED REGION END*/ }
public void CrearAccionRespuesta(int p_oid) { /*PROTECTED REGION ID(ReciclaUAGenNHibernate.CP.ReciclaUA_Respuesta_crearAccionRespuesta) ENABLED START*/ IRespuestaCAD respuestaCAD = null; RespuestaCEN respuestaCEN = null; AccionWebCEN accionWebCEN = null; ITipoAccionCAD tipoAccionCAD = null; TipoAccionCEN tipoAccionCEN = null; TipoAccionEN tipoAccion = null; IUsuarioWebCAD usuarioWebCAD = null; UsuarioWebCEN usuarioWebCEN = null; RespuestaEN respuesta = null; try { SessionInitializeTransaction(); respuestaCAD = new RespuestaCAD(session); respuestaCEN = new RespuestaCEN(respuestaCAD); tipoAccionCAD = new TipoAccionCAD(session); tipoAccionCEN = new TipoAccionCEN(tipoAccionCAD); usuarioWebCAD = new UsuarioWebCAD(session); usuarioWebCEN = new UsuarioWebCEN(usuarioWebCAD); accionWebCEN = new AccionWebCEN(); respuesta = respuestaCEN.BuscarPorId(p_oid); if (respuesta.Usuario != null && usuarioWebCEN.BuscarPorId(respuesta.Usuario.Id) != null) { tipoAccion = tipoAccionCEN.BuscarTodos(0, -1).Where(t => t.Nombre.Equals("Respuesta")).FirstOrDefault(); if (tipoAccion == null) { var id = tipoAccionCEN.Crear(5, "Respuesta"); tipoAccion = tipoAccionCEN.BuscarPorId(id); } accionWebCEN.Crear(respuesta.Usuario.Id, tipoAccion.Id); } SessionCommit(); } catch (Exception ex) { SessionRollBack(); throw ex; } finally { SessionClose(); } /*PROTECTED REGION END*/ }
public void Modify(int p_Respuesta_OID, string p_descripcion, Nullable <DateTime> p_fecha) { RespuestaEN respuestaEN = null; //Initialized RespuestaEN respuestaEN = new RespuestaEN(); respuestaEN.Id = p_Respuesta_OID; respuestaEN.Descripcion = p_descripcion; respuestaEN.Fecha = p_fecha; //Call to RespuestaCAD _IRespuestaCAD.Modify(respuestaEN); }
public void GivenTengoUnaDudaConRespuestaCorrecta() { int id = 0; for (int i = 0; i < 5; i++) { id = respuestaCEN.Crear("Respuesta Test", id_duda, -1); ids.Add(id); } RespuestaEN r = respuestaCEN.BuscarPorId(id); respuestaCEN.Modificar(id, r.Cuerpo, r.Fecha, true, r.Util); }
public void Modificar(int p_Respuesta_OID, string p_cuerpo, Nullable <DateTime> p_fecha, bool p_esCorrecta, int p_util) { RespuestaEN respuestaEN = null; //Initialized RespuestaEN respuestaEN = new RespuestaEN(); respuestaEN.Id = p_Respuesta_OID; respuestaEN.Cuerpo = p_cuerpo; respuestaEN.Fecha = p_fecha; respuestaEN.EsCorrecta = p_esCorrecta; respuestaEN.Util = p_util; //Call to RespuestaCAD _IRespuestaCAD.Modificar(respuestaEN); }
public static RespuestaDTOA Convert(RespuestaEN en, NHibernate.ISession session = null) { RespuestaDTOA dto = null; RespuestaRESTCAD respuestaRESTCAD = null; RespuestaCEN respuestaCEN = null; RespuestaCP respuestaCP = null; if (en != null) { dto = new RespuestaDTOA(); respuestaRESTCAD = new RespuestaRESTCAD(session); respuestaCEN = new RespuestaCEN(respuestaRESTCAD); respuestaCP = new RespuestaCP(session); // // Attributes dto.Id = en.Id; dto.Cuerpo = en.Cuerpo; dto.Fecha = en.Fecha; dto.EsCorrecta = en.EsCorrecta; dto.Util = en.Util; // // TravesalLink /* Rol: Respuesta o--> UsuarioAdminAutenticado */ dto.UsuarioRespuesta = UsuarioAdminAutenticadoAssembler.Convert((UsuarioEN)en.Usuario, session); // // Service } return(dto); }
public ReciclaUAGenNHibernate.EN.ReciclaUA.RespuestaEN ObtenerUltimaRespuesta(int p_oid) { /*PROTECTED REGION ID(ReciclaUAGenNHibernate.CP.ReciclaUA_Duda_obtenerUltimaRespuesta) ENABLED START*/ IDudaCAD dudaCAD = null; DudaCEN dudaCEN = null; RespuestaEN respuesta = null; try { SessionInitializeTransaction(); dudaCAD = new DudaCAD(session); dudaCEN = new DudaCEN(dudaCAD); // Write here your custom transaction ... DudaEN duda = dudaCAD.ReadOIDDefault(p_oid); if (duda.Respuestas.Count > 0) { respuesta = duda.Respuestas [0]; for (int i = 1; i < duda.Respuestas.Count; i++) { if (respuesta.Fecha <= duda.Respuestas [i].Fecha) { respuesta = duda.Respuestas [i]; } } } SessionCommit(); } catch (Exception ex) { SessionRollBack(); throw ex; } finally { SessionClose(); } return(respuesta); /*PROTECTED REGION END*/ }
public void ConfirmacionRespuestaCorrecta(int p_oid) { /*PROTECTED REGION ID(ReciclaUAGenNHibernate.CEN.ReciclaUA_Respuesta_confirmacionRespuestaCorrecta) ENABLED START*/ RespuestaEN resp = _IRespuestaCAD.BuscarPorId(p_oid); if (resp.EsCorrecta) { throw new ModelException("El estado de la respuesta ya es correcta"); } resp.EsCorrecta = true; _IRespuestaCAD.Modificar(resp); /*PROTECTED REGION END*/ }
public bool DescartarRespuestaCorrecta(int p_oid) { /*PROTECTED REGION ID(ReciclaUAGenNHibernate.CEN.ReciclaUA_Respuesta_descartarRespuestaCorrecta) ENABLED START*/ RespuestaEN resp = _IRespuestaCAD.BuscarPorId(p_oid); if (!resp.EsCorrecta) { throw new ModelException("El estado de la respuesta no es correcta"); } resp.EsCorrecta = false; _IRespuestaCAD.Modificar(resp); return(true); /*PROTECTED REGION END*/ }
public int Crear(RespuestaEN respuesta) { try { SessionInitializeTransaction(); if (respuesta.Duda != null) { // Argumento OID y no colección. respuesta.Duda = (ReciclaUAGenNHibernate.EN.ReciclaUA.DudaEN)session.Load(typeof(ReciclaUAGenNHibernate.EN.ReciclaUA.DudaEN), respuesta.Duda.Id); respuesta.Duda.Respuestas .Add(respuesta); } if (respuesta.Usuario != null) { // Argumento OID y no colección. respuesta.Usuario = (ReciclaUAGenNHibernate.EN.ReciclaUA.UsuarioEN)session.Load(typeof(ReciclaUAGenNHibernate.EN.ReciclaUA.UsuarioEN), respuesta.Usuario.Id); respuesta.Usuario.Respuestas .Add(respuesta); } session.Save(respuesta); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is ReciclaUAGenNHibernate.Exceptions.ModelException) { throw ex; } throw new ReciclaUAGenNHibernate.Exceptions.DataLayerException("Error in RespuestaCAD.", ex); } finally { SessionClose(); } return(respuesta.Id); }
public int New_(RespuestaEN respuesta) { try { SessionInitializeTransaction(); if (respuesta.Tema != null) { // Argumento OID y no colección. respuesta.Tema = (DSMGitGenNHibernate.EN.DSMGit.TemaEN)session.Load(typeof(DSMGitGenNHibernate.EN.DSMGit.TemaEN), respuesta.Tema.Id); respuesta.Tema.Respuestas .Add(respuesta); } if (respuesta.Usuario != null) { // Argumento OID y no colección. respuesta.Usuario = (DSMGitGenNHibernate.EN.DSMGit.UsuarioEN)session.Load(typeof(DSMGitGenNHibernate.EN.DSMGit.UsuarioEN), respuesta.Usuario.Email); respuesta.Usuario.Respuestas .Add(respuesta); } session.Save(respuesta); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is DSMGitGenNHibernate.Exceptions.ModelException) { throw ex; } throw new DSMGitGenNHibernate.Exceptions.DataLayerException("Error in RespuestaCAD.", ex); } finally { SessionClose(); } return(respuesta.Id); }
public int Crear(string p_cuerpo, int p_duda, int p_usuario) { /*PROTECTED REGION ID(ReciclaUAGenNHibernate.CEN.ReciclaUA_Respuesta_crear_customized) ENABLED START*/ RespuestaEN respuestaEN = null; int oid; //Initialized RespuestaEN respuestaEN = new RespuestaEN(); respuestaEN.Cuerpo = p_cuerpo; respuestaEN.Util = 0; respuestaEN.EsCorrecta = false; respuestaEN.Fecha = DateTime.Now; if (p_usuario != -1) { respuestaEN.Usuario = new ReciclaUAGenNHibernate.EN.ReciclaUA.UsuarioEN(); respuestaEN.Usuario.Id = p_usuario; } if (p_duda != -1) { respuestaEN.Duda = new ReciclaUAGenNHibernate.EN.ReciclaUA.DudaEN(); respuestaEN.Duda.Id = p_duda; } //Call to RespuestaCAD oid = _IRespuestaCAD.Crear(respuestaEN); // RespuestaCP cp = new RespuestaCP (((RespuestaCAD)_IRespuestaCAD).GetSession ()); // cp.CrearAccionRespuesta (oid); return(oid); /*PROTECTED REGION END*/ }
// Modify default (Update all attributes of the class) public void ModifyDefault(RespuestaEN respuesta) { try { SessionInitializeTransaction(); RespuestaEN respuestaEN = (RespuestaEN)session.Load(typeof(RespuestaEN), respuesta.Id); respuestaEN.Cuerpo = respuesta.Cuerpo; respuestaEN.Fecha = respuesta.Fecha; respuestaEN.EsCorrecta = respuesta.EsCorrecta; respuestaEN.Util = respuesta.Util; session.Update(respuestaEN); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is ReciclaUAGenNHibernate.Exceptions.ModelException) { throw ex; } throw new ReciclaUAGenNHibernate.Exceptions.DataLayerException("Error in RespuestaCAD.", ex); } finally { SessionClose(); } }
public static RespuestaEN Convert(RespuestaDTO dto) { RespuestaEN newinstance = null; try { if (dto != null) { newinstance = new RespuestaEN(); newinstance.Id = dto.Id; newinstance.Cuerpo = dto.Cuerpo; if (dto.Duda_oid != -1) { ReciclaUAGenNHibernate.CAD.ReciclaUA.IDudaCAD dudaCAD = new ReciclaUAGenNHibernate.CAD.ReciclaUA.DudaCAD(); newinstance.Duda = dudaCAD.ReadOIDDefault(dto.Duda_oid); } if (dto.Usuario_oid != -1) { ReciclaUAGenNHibernate.CAD.ReciclaUA.IUsuarioCAD usuarioCAD = new ReciclaUAGenNHibernate.CAD.ReciclaUA.UsuarioCAD(); newinstance.Usuario = usuarioCAD.ReadOIDDefault(dto.Usuario_oid); } newinstance.Fecha = dto.Fecha; newinstance.EsCorrecta = dto.EsCorrecta; newinstance.Util = dto.Util; } } catch (Exception ex) { throw ex; } return(newinstance); }
public static RespuestaModel ConvertENToModelUI(RespuestaEN respuestaEN) { RespuestaModel r = new RespuestaModel(); r.Id = respuestaEN.Id; r.Descripcion = respuestaEN.Descripcion; r.Tema = respuestaEN.Tema.Titulo; r.Usuario = respuestaEN.Usuario.Nick; r.Email = respuestaEN.Usuario.Email; r.TemaID = respuestaEN.Tema.Id; try { string parseDate = respuestaEN.Fecha.ToString(); string[] fecha = parseDate.Split(' '); r.Fecha = fecha[0]; } catch { r.Fecha = "Fecha desconocida"; } return(r); }
public HttpResponseMessage BuscarPorId(int idRespuesta) { // CAD, CEN, EN, returnValue RespuestaRESTCAD respuestaRESTCAD = null; RespuestaCEN respuestaCEN = null; RespuestaEN respuestaEN = null; RespuestaDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } int id = new UsuarioCEN().CheckToken(token); respuestaRESTCAD = new RespuestaRESTCAD(session); respuestaCEN = new RespuestaCEN(respuestaRESTCAD); // Data respuestaEN = respuestaCEN.BuscarPorId(idRespuesta); // Convert return if (respuestaEN != null) { returnValue = RespuestaAssembler.Convert(respuestaEN, session); } } catch (Exception e) { if (e.GetType() == typeof(HttpResponseException)) { throw e; } else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto")) { throw new HttpResponseException(HttpStatusCode.Forbidden); } else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.DataLayerException)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } else { throw new HttpResponseException(HttpStatusCode.InternalServerError); } } finally { SessionClose(); } // Return 404 - Not found if (returnValue == null) { return(this.Request.CreateResponse(HttpStatusCode.NotFound)); } // Return 200 - OK else { return(this.Request.CreateResponse(HttpStatusCode.OK, returnValue)); } }
public void ThenLaRespuestaEsNoCorrecta() { respuesta = respuestaCEN.BuscarPorId(id); Assert.AreEqual(false, respuesta.EsCorrecta); }
public static void InitializeData() { id = respuestaCEN.Crear("Respuesta Test", -1, -1); respuesta = respuestaCEN.BuscarPorId(id); }
public void WhenObtengoLaUltimaRespuesta() { respuesta = new RespuestaCP().ObtenerUltimaRespuesta(id_duda); }
public HttpResponseMessage DudaRespuesta(int idRespuesta) { // CAD, EN RespuestaRESTCAD respuestaRESTCAD = null; RespuestaEN respuestaEN = null; // returnValue DudaEN en = null; DudaDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } new UsuarioCEN().CheckToken(token); respuestaRESTCAD = new RespuestaRESTCAD(session); // Exists Respuesta respuestaEN = respuestaRESTCAD.ReadOIDDefault(idRespuesta); if (respuestaEN == null) { throw new HttpResponseException(this.Request.CreateResponse(HttpStatusCode.NotFound, "Respuesta#" + idRespuesta + " not found")); } // Rol // TODO: paginación en = respuestaRESTCAD.DudaRespuesta(idRespuesta); // Convert return if (en != null) { returnValue = DudaAssembler.Convert(en, session); } } catch (Exception e) { if (e.GetType() == typeof(HttpResponseException)) { throw e; } else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto")) { throw new HttpResponseException(HttpStatusCode.Forbidden); } else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.DataLayerException)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } else { throw new HttpResponseException(HttpStatusCode.InternalServerError); } } finally { SessionClose(); } // Return 204 - Empty if (returnValue == null) { return(this.Request.CreateResponse(HttpStatusCode.NoContent)); } // Return 200 - OK else { return(this.Request.CreateResponse(HttpStatusCode.OK, returnValue)); } }