public JObject Generate() { try { var userData = SessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY); if (userData == null) { Logger.Debug("User session data is null"); return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED)); } DBQuery query = new DBQuery() { Filters = new FilterQuery() { new Filter(CommonConst.CommonField.USER_ID, userData.user_id) } }; if (DBProxy.GetCount(ModuleAppConsts.Collection.AUTH_TOKEN_COLLECTION, query.Filters) >= MAX_KEYS) { return(ResponseBuilder.CreateReponse(ApiKeyResponseCode._MAX_AUTH_TOKEN_REACHED)); } var apikey = GenerateApiKey(); var data = GenerateApiKeyData(userData, apikey); if (DBProxy.WriteData(ModuleAppConsts.Collection.AUTH_TOKEN_COLLECTION, data, false)) { data[ModuleAppConsts.Field.AUTH_TOKEN] = apikey; return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, data)); } else { Logger.Error("Error in writing data"); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } } catch (Exception ex) { Logger.Error(ex.Message, ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
protected JObject GetPagedData(string collection, string query, List <string> fields = null, Dictionary <string, int> sortColumns = null, int pageSize = 10, int currentPage = 1) { int?top = null; int?skip = null; top = pageSize; skip = (pageSize * (currentPage - 1)); Logger.Debug(string.Format("GetPageData. Top:{0} Skip:{1} Query:{2}", top, skip, query)); var dbArrData = DBProxy.Get(collection, query, fields, sortColumns, top, skip); JObject extraData = new JObject(); long count = DBProxy.GetCount(collection, query); extraData[CommonConst.CommonField.TOTAL_RECORD_COUNT_KEY] = count; extraData[CommonConst.CommonField.TOTAL_PAGES_KEY] = Math.Ceiling(((double)count / pageSize)); extraData[CommonConst.CommonField.PAGE_SIZE_KEY] = pageSize; extraData[CommonConst.CommonField.CURRENT_PAGE_KEY] = currentPage; return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, dbArrData, extraData)); }