public async Task <HttpResponseMessage> GetProfile(int UserID) { try { ProfileDAL dal = new ProfileDAL(); Profile data = await dal.GetProfile(UserID); if (data != null) { return(Request.CreateResponse <Profile>(HttpStatusCode.OK, data)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, Constants.ErrorNotFound)); } } catch (DbEntityValidationException ex) { var controllerName = ControllerContext.RouteData.Values["controller"].ToString(); var actionName = ControllerContext.RouteData.Values["action"].ToString(); Logger log = new Logger(); log.ErrorLog(ex, controllerName, actionName); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, Constants.ErrorSysError)); } }
public ProfileEN GetProfile(int pProfileID) { ProfileEN userProfile = new ProfileEN(); try { userProfile = profileDAL.GetProfile(pProfileID); } catch (Exception ex) { Console.WriteLine(ex.InnerException); EventViewerLoggerBL.LogError(ex.Message); } return(userProfile); }
public async Task <Profile> GenerateUserPass(string email) { var getProf = await prodDal.GetProfile(email); Profile p = new Profile(); User u = new User(); string Username; string Password; if (getProf != null) { if (getProf.type_account == "Application") { Username = email; Password = GeneratePassword(); u.user = Username; u.pwd = Password; } else if (getProf.type_account == "Exam") { Username = GenerateUserFOrExam(); Password = GeneratePassword(); u.user = Username; u.pwd = Password; } u.email = email; u.type_account = getProf.type_account; var user = userDal.InsertUser(u); p.id = getProf.id; p.name = getProf.name; p.email = email; p.type_account = getProf.type_account; } return(p); }
/// <summary> /// Recupera un perfil en base a su id. /// </summary> /// <param name="profileId"></param> /// <returns></returns> public ResultBM GetProfile(string profileId) { try { List <PermissionDTO> permissions; ProfileDAL profileDal = new ProfileDAL(); ProfileBM result; string fatherCode; string code; string description; bool excluded; bool moreItemsToAdd = true; int maxIterations = 0; //Condición de corte del while en caso de una eventualidad log.AddLogInfo("Recuperando perfil", "Recuperando perfil " + profileId + ".", this); permissions = profileDal.GetProfile(profileId); if (permissions == null) { throw new Exception(SessionHelper.GetTranslation("NO_PERMISSION_FOUND_ERROR")); } else if (permissions.Count == 1) { //En caso de obtener sólo un permiso, debe crearse como hijo. fatherCode = permissions[0].fatherCode; code = permissions[0].code; description = permissions[0].description; excluded = permissions[0].excluded; result = new PermissionMDL(fatherCode, code, description, excluded); } else { //La estrategia consiste en obtener el primer elemento y considerarlo root (garantizado por la base de dato). //Luego, recorrer la lista de los permisos y asignarlos al root hasta que la lista de permisos esté vacía. //Para vaciar la lista, considerar la siguiente estrategia: si se agregó, se borra de la lista. fatherCode = permissions[0].fatherCode; code = permissions[0].code; description = permissions[0].description; excluded = permissions[0].excluded; result = new PermissionsMDL(fatherCode, code, description, excluded); while (moreItemsToAdd) { for (int i = permissions.Count - 1; i > 0; --i) { fatherCode = permissions[i].fatherCode; code = permissions[i].code; description = permissions[i].description; excluded = permissions[i].excluded; if (result.AddPermissionSorted(new PermissionMDL(fatherCode, code, description, excluded))) { permissions.RemoveAt(i); } } maxIterations += 1; moreItemsToAdd = (permissions.Count > 0 && maxIterations < 100); } } log.AddLogInfo("Recuperando perfil", "Perfil " + profileId + " recuperado.", this); return(new ResultBM(ResultBM.Type.OK, "Permiso recuperado.", result)); } catch (Exception exception) { log.AddLogCritical("Recuperando perfil", exception.Message, this); return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("RETRIEVING_ERROR") + " " + exception.Message, exception)); } }