public HttpResponseMessage GetUserAllDevices(string userID) { string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); InsightLogger.TrackEvent("PersonalizationAPIController :: Get method endpoint - api/personalizationapi/users/{userID}/devices"); //check if userid is null if (!string.IsNullOrEmpty(userID)) { UserDevice userdevices = new UserDevice(); InsightLogger.TrackEvent("PersonalizationAPIController :: Get all Associated devices to user"); IEnumerable <UserDeviceDTO> alluserdevices = userdevices.GetUserAllDevices(userID); //if user as devices associated returns response otherwise not found if (alluserdevices != null) { //adding userdevice dto to responsedto var ResponseUserDevices = new PersonalizationResponseListDTO <UserDeviceDTO>(); ResponseUserDevices.result = alluserdevices; return(Request.CreateResponse(HttpStatusCode.OK, ResponseUserDevices)); } else { return(Request.CreateResponse(HttpStatusCode.OK, DataProvider.PersonalizationResponseError <UserBackendDTO>("400", "user does not have associated devices", ""))); } } else { InsightLogger.TrackEvent("PersonalizationAPIController ::userid is null or empty"); return(Request.CreateResponse(HttpStatusCode.BadRequest, DataProvider.PersonalizationResponseError <UserBackendDTO>("400", "user does not have associated devices", ""))); } } catch (DataAccessException dalexception) { InsightLogger.Exception(dalexception.Message, dalexception, callerMethodName); return(Request.CreateResponse(HttpStatusCode.NotFound, DataProvider.PersonalizationResponseError <UserDeviceDTO>("400", dalexception.Message, dalexception.Message))); } catch (BusinessLogicException blexception) { InsightLogger.Exception(blexception.Message, blexception, callerMethodName); return(Request.CreateResponse(HttpStatusCode.NotFound, DataProvider.PersonalizationResponseError <UserDeviceDTO>("400", blexception.Message, blexception.Message))); } catch (Exception exception) { InsightLogger.Exception(exception.Message, exception, callerMethodName); //LoggerHelper.WriteToLog(exception + " - exception in controller action while retreiving all userdevcies for user : "******"400", exception.Message, exception.StackTrace))); } }
/// <summary> /// method to get all backends /// </summary> /// <returns>returns list of backends as personalization response form</returns> public PersonalizationResponseListDTO <BackendDTO> GetBackends() { string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); UserBackendDAL userbackenddal = new UserBackendDAL(); //calling data access layer method List <BackendEntity> backends = userbackenddal.GetBackends(); List <BackendDTO> backendslistdto = new List <BackendDTO>(); //if backends not available return null if (backends != null && backends.Count > 0) { //backends entity converting to data transfer object foreach (BackendEntity backend in backends) { BackendDTO backenddto = DataProvider.ResponseObjectMapper <BackendDTO, BackendEntity>(backend); backendslistdto.Add(backenddto); } } else { backendslistdto = null; } var ResponseBackends = new PersonalizationResponseListDTO <BackendDTO>(); ResponseBackends.result = backendslistdto; return(ResponseBackends); } catch (DataAccessException DALexception) { throw DALexception; } catch (Exception exception) { InsightLogger.Exception(exception.Message, exception, callerMethodName); //LoggerHelper.WriteToLog(exception + " - Error in BL while retreiving backends : " //+exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Error); throw new BusinessLogicException(); } }
public HttpResponseMessage GetBackends() { string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/backends, action : starting method"); UserBackend userBackend = new UserBackend(); PersonalizationResponseListDTO <BackendDTO> allBackends = userBackend.GetBackends(); InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/backends, action : getting backends, response: successs"); //if backends exists return result other wise return status code as NotFound if (allBackends.result != null) { return(Request.CreateResponse(HttpStatusCode.OK, allBackends)); } else { return(Request.CreateResponse(HttpStatusCode.OK, DataProvider.PersonalizationResponseError <UserBackendDTO>("400", "User does not have backends", ""))); } } catch (DataAccessException dalexception) { InsightLogger.Exception(dalexception.Message, dalexception, callerMethodName); return(Request.CreateResponse(HttpStatusCode.NotFound, DataProvider.PersonalizationResponseError <UserBackendDTO>("400", dalexception.Message, dalexception.Message))); } catch (BusinessLogicException blexception) { InsightLogger.Exception(blexception.Message, blexception, callerMethodName); return(Request.CreateResponse(HttpStatusCode.NotFound, DataProvider.PersonalizationResponseError <UserBackendDTO>("400", blexception.Message, blexception.Message))); } catch (Exception exception) { InsightLogger.Exception(exception.Message, exception, callerMethodName); //LoggerHelper.WriteToLog(exception + " - exception in controller action while retrieving all backends : " // + exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Error); return(Request.CreateResponse(HttpStatusCode.NotFound, DataProvider.PersonalizationResponseError <UserBackendDTO>("400", exception.Message, exception.StackTrace))); } }