public static AccionWebEN Convert(AccionWebDTO dto) { AccionWebEN newinstance = null; try { if (dto != null) { newinstance = new AccionWebEN(); if (dto.Tipo_oid != -1) { ReciclaUAGenNHibernate.CAD.ReciclaUA.ITipoAccionCAD tipoAccionCAD = new ReciclaUAGenNHibernate.CAD.ReciclaUA.TipoAccionCAD(); newinstance.Tipo = tipoAccionCAD.ReadOIDDefault(dto.Tipo_oid); } newinstance.Id = dto.Id; if (dto.Usuario_oid != -1) { ReciclaUAGenNHibernate.CAD.ReciclaUA.IUsuarioWebCAD usuarioWebCAD = new ReciclaUAGenNHibernate.CAD.ReciclaUA.UsuarioWebCAD(); newinstance.Usuario = usuarioWebCAD.ReadOIDDefault(dto.Usuario_oid); } newinstance.Fecha = dto.Fecha; } } catch (Exception ex) { throw ex; } return(newinstance); }
public HttpResponseMessage Modificar(int idAccionWeb, [FromBody] AccionWebDTO dto) { // CAD, CEN, returnValue AccionWebRESTCAD accionWebRESTCAD = null; AccionWebCEN accionWebCEN = null; AccionWebDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } int id = new UsuarioCEN().CheckToken(token); accionWebRESTCAD = new AccionWebRESTCAD(session); accionWebCEN = new AccionWebCEN(accionWebRESTCAD); // Modify accionWebCEN.Modificar(idAccionWeb, dto.Fecha ); // Return modified object returnValue = AccionWebAssembler.Convert(accionWebRESTCAD.ReadOIDDefault(idAccionWeb), session); SessionCommit(); } catch (Exception e) { SessionRollBack(); 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 { response = this.Request.CreateResponse(HttpStatusCode.OK, returnValue); return(response); } }