public static UserAnonimousDTOA Convert(UserEN en, NHibernate.ISession session = null) { UserAnonimousDTOA dto = null; UserAnonimousRESTCAD userAnonimousRESTCAD = null; UserCEN userCEN = null; UserCP userCP = null; if (en != null) { dto = new UserAnonimousDTOA(); userAnonimousRESTCAD = new UserAnonimousRESTCAD(session); userCEN = new UserCEN(userAnonimousRESTCAD); userCP = new UserCP(session); // // Attributes dto.Id = en.Id; // // TravesalLink // // Service } return(dto); }
public HttpResponseMessage Login([FromBody] UserDTO dto) { // CAD, CEN, returnValue UserAnonimousRESTCAD userAnonimousRESTCAD = null; UserCEN userCEN = null; string token = null; try { SessionInitializeTransaction(); userAnonimousRESTCAD = new UserAnonimousRESTCAD(session); userCEN = new UserCEN(userAnonimousRESTCAD); // Operation token = userCEN.Login( dto.Id , dto.Pass ); SessionCommit(); } catch (Exception e) { SessionRollBack(); if (e.GetType() == typeof(HttpResponseException)) { throw e; } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto")) { throw new HttpResponseException(HttpStatusCode.Forbidden); } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } else { throw new HttpResponseException(HttpStatusCode.InternalServerError); } } finally { SessionClose(); } // Return 200 - OK if (token != null) { return(this.Request.CreateResponse(HttpStatusCode.OK, token)); } else { return(this.Request.CreateResponse(HttpStatusCode.Unauthorized, "")); } }