// [Authorize] public async Task <ApiResponse <object> > GetPacketByUserId(ApiPacketRequest apr) { ApiResponse <object> apiResponse = new ApiResponse <object>(); try { switch (apr.TableName) { case "UserGeo": apiResponse = await rf.Api.ProcessFetchAsync(apr, null, new FetchGeolocationHandler()); break; default: apiResponse = await rf.Api.ProcessFetchAsync(apr, null, null); break; } } catch (System.Exception ex) { throw ex; } //CallerId and Command Bindings ---------- Start //apiResponse.CallerId = apr.CallerId; apiResponse.Command = apr.Command; //CallerId and Command Bindings ---------- End return(apiResponse); }
private ForApiResponse QueryFromAPIPacketRequest(ApiPacketRequest apr) { return(new ForApiResponse() { PageNo = apr.PageNo, PageSize = apr.PageSize, UserId = apr.UserId }); }
public ApiResponse ProcessSync(ApiPacketRequest apr, DbContext dbContext = null, object expressionOrSql = null, params IApiHandler[] apiHandlers) { dbContext = dbContext ?? Config.DB.DefaultDbContext; object model = dynamic.GetInstance(dynamic.GetFullyQualifiedPath(apr.TableName)); object modelData = JsonConvert.DeserializeObject(apr.ApiPacket.Packet.ToString(), model.GetType()); if (apiHandlers != null) { for (int i = 0; i < apiHandlers.Count(); i++) { modelData = apiHandlers[i].Handle(Mode.Pre, (ProcessType)Array.IndexOf(operation, apr.Command), modelData, db); } } try { ApiResponse apiResponse = new ApiResponse() { Success = false, Message = "Table is not registered", Status = 400 }; ; if (apr.Command.ToUpper().Equals("ADD")) { apiResponse = ResultToApiResponse(ProcessOperation(modelData, dbContext, expressionOrSql)); } else if (apr.Command.ToUpper().Equals("UPDATE")) { apiResponse = ResultToApiResponse(ProcessOperation(modelData, dbContext, expressionOrSql)); } else if (apr.Command.ToUpper().Equals("DELETE")) { apiResponse = ResultToApiResponse(db.Delete(modelData, dbContext)); } //Error Log To a File db.Commit(); if (apiHandlers != null) { for (int i = 0; i < apiHandlers.Count(); i++) { modelData = apiHandlers[i].Handle(Mode.Post, (ProcessType)Array.IndexOf(operation, apr.Command), model, db); } } return(apiResponse); } catch (Exception ex) { return(new ApiResponse() { Success = false, Message = ex.Message, Status = 400 }); } }
private string GetUUIDBasedSQL(ApiPacketRequest apr) { var dictionary = JsonConvert.DeserializeObject(apr.ApiPacket.Packet.ToString()); var value = dictionary.GetPropertyValue("UUID"); return(value != null ? $"SELECT * from {apr.TableName} where UUID = '{value.ToString()}'" : ""); }
public ActionResult <ApiResponse> SyncData(ApiPacketRequest apr) { ApiResponse apiResponse = new ApiResponse(); RapidFire rf = new RapidFire(new AppConfig(), false); switch (apr.TableName) { default: var sqlString = GetUUIDBasedSQL(apr); apiResponse = rf.Api.ProcessSync(apr, null, string.IsNullOrEmpty(sqlString) ? null : sqlString, new SyncHandler()); break; } apiResponse.Command = apr.Command; return(apiResponse); }
public ApiResponse <Object> GetPacketByUserId(ApiPacketRequest apr) { ApiResponse <Object> returnObject = new ApiResponse <Object>(); List <object> obj = new List <object>(); switch (apr.Command) { case "GetData": { if (apr.TableName == "SpinnerData") { var spinnerRequest = JsonConvert.DeserializeObject <SpinnerRequest>(apr.ApiPacket.Packet.ToString()); SpinnerData spinner = new SpinnerData(); var result = spinner.APIGetSpinnerData(QueryFromAPIPacketRequest(apr), spinnerRequest); obj.AddRange(result); returnObject = GetApiResponse(apr, obj, apr.TotalRecord != 0 ? spinner.APIGetTotalRecord(QueryFromAPIPacketRequest(apr), spinnerRequest) : apr.TotalRecord); break; } else { var dynamicModelType = Dynamic.GetObjectType(apr.TableName); var selectObj = Activator.CreateInstance(dynamicModelType); var data = JsonConvert.DeserializeObject <GetDataPacket>(apr.ApiPacket.Packet.ToString()); var result = Dynamic.DynamicSelectWithPaging(selectObj, data, apr.PageNo, apr.PageSize); obj.AddRange(result); returnObject = GetApiResponse(apr, obj, apr.TotalRecord != 0 ? Dynamic.DynamicSelectTotalRecortCount(selectObj, data) : apr.TotalRecord); break; } } default: { ApiResponse <object> response = new ApiResponse <object>() { Success = false, ApiPacket = null, PageNo = apr.PageNo, PageSize = apr.PageSize, TotalRecord = 0, Message = "Table is not registered to System", Status = 400 }; return(response); } } return(returnObject); }
private ApiResponse <object> GetApiResponseForPacket(ApiPacketRequest apr, object packet, long totalRecord) { ApiResponse <object> returnObject = new ApiResponse <object>(); //ApiPacket<object> fp = new ApiPacket<object>() {PacketList = list.ToList()}; ApiResponse <object> response = new ApiResponse <object>() { Success = packet != null ? true : false, ApiPacket = new ApiPacket <object>() { Packet = packet }, PageNo = apr.PageNo, PageSize = apr.PageSize, TotalRecord = totalRecord, Message = packet != null ? "Record Fetched successfully." : "Record Fetched fail.", Status = packet != null ? 200 : 400 }; Tools.CopyClass(returnObject, response); returnObject.ApiPacket.PacketList = new List <object>(); returnObject.ApiPacket.Packet = packet; return(returnObject); }
private ApiResponse <object> GetApiResponse(ApiPacketRequest apr, List <object> list, long totalRecord) { ApiResponse <object> returnObject = new ApiResponse <object>(); ApiPacket <object> fp = new ApiPacket <object>() { PacketList = list }; ApiResponse <object> response = new ApiResponse <object>() { Success = list != null ? true : false, ApiPacket = fp, PageNo = apr.PageNo, PageSize = apr.PageSize, TotalRecord = totalRecord, Message = list != null ? "Record Fetched successfully." : "Record Fetched fail.", Status = list != null ? 200 : 400 }; Tools.CopyClass(returnObject.ApiPacket, fp); Tools.CopyClass(returnObject, response); returnObject.ApiPacket.PacketList = new List <object>(); returnObject.ApiPacket.PacketList.AddRange(list); return(returnObject); }
public ApiResponse SyncData(ApiPacketRequest apr) { ApiResponse returnObject = new ApiResponse(); CommandResult commandResult = new CommandResult(); try { /* * switch (apr.TableName) * { * case "MemberInfo": * { * MemberInfo command = new MemberInfo(); * var memberInfo = JsonConvert.DeserializeObject<MemberInfo>(apr.ApiPacket.Packet.ToString()); * commandResult = command.SaveOrUpdate(memberInfo); * break; * } * //case "Admission": * // { * // Admission command = new Admission(); * // var admisson = JsonConvert.DeserializeObject<Admission>(apr.ApiPacket.Packet.ToString()); * // commandResult = command.SaveOrUpdate(admisson); * // break; * // } * case "HomeVisit": * { * HomeVisit command = new HomeVisit(); * var homeVisit = JsonConvert.DeserializeObject<HomeVisit>(apr.ApiPacket.Packet.ToString()); * commandResult = command.SaveOrUpdate(homeVisit); * break; * } * case "Distribution": * { * Distribution command = new Distribution(); * var distribution = JsonConvert.DeserializeObject<Distribution>(apr.ApiPacket.Packet.ToString()); * commandResult = command.SaveOrUpdate(distribution); * break; * } * case "SessionInfo": * { * SessionInfo command = new SessionInfo(); * command = JsonConvert.DeserializeObject<SessionInfo>(apr.ApiPacket.Packet.ToString()); * commandResult = command.Save(command); * break; * } * case "Gmp": * { * Gmp command = new Gmp(); * command = JsonConvert.DeserializeObject<Gmp>(apr.ApiPacket.Packet.ToString()); * commandResult = command.Save(command); * break; * } * case "UnUsedUIdAndHHId": * { * UnusedUId command = new UnusedUId(); * var obj = JsonConvert.DeserializeObject<UnusedUIdAndHHIdViewModel>(apr.ApiPacket.Packet.ToString()); * commandResult = command.SaveUIdAndHHId(obj); * break; * } * case "UniqueId": * { * UniqueId command = new UniqueId(); * var obj = JsonConvert.DeserializeObject<List<UniqueId>>(JsonConvert.SerializeObject(apr.ApiPacket.PacketList)); * commandResult = command.Save(obj.ToList(),apr.UserId); * break; * } * case "Discharge": * { * Discharge command = new Discharge(); * command = JsonConvert.DeserializeObject<Discharge>(apr.ApiPacket.Packet.ToString()); * commandResult = command.Save(command); * break; * } * default: * { * return new ApiResponse() * { * Success = false, * Message = "Table is not registered", * Status = 400 * }; * } * }*/ Tools.CopyClass(returnObject, commandResult); return(returnObject); } catch (Exception ex) { return(new ApiResponse() { Success = false, Message = ex.Message, Status = 400 }); } }
public ApiResponse <Object> GetPacketByUserId(ApiPacketRequest apr) { ApiResponse <Object> returnObject = new ApiResponse <Object>(); List <object> obj = new List <object>(); switch (apr.TableName) { case "Login": { UsersLogin query = JsonConvert.DeserializeObject <UsersLogin>(apr.ApiPacket.Packet.ToString()); var result = new AspNetUsers().Login(query); ApiPacket <LoginResponse> fp = new ApiPacket <LoginResponse>() { Packet = new LoginResponse() }; if (result != null) { returnObject.ApiPacket.Packet = new LoginResponse() { UserInfo = result.UserInfo /*, BlockInfo = result.BlockInfo ServicePoint = result.ServicePoint, GeoLocation = result.GeoLocation*/ }; } ApiResponse <LoginResponse> response = new ApiResponse <LoginResponse>() { Success = result != null ? true : false, ApiPacket = fp, PageNo = apr.PageNo, PageSize = apr.PageSize, TotalRecord = 0, Message = result != null ? "Login successfully." : "Invalid Username or Password", Status = result != null ? 200 : 400 }; Tools.CopyClass(returnObject, response); break; //return returnObject; } case "UserGeo": { var result = new PermittedGeoLocation().GetPermittedGeoLocation(new PermittedGeoLocationRM { UserId = apr.UserId });; ApiPacket <PermittedGeoLocationViewModels> fp = new ApiPacket <PermittedGeoLocationViewModels>() { Packet = new PermittedGeoLocationViewModels() }; if (result != null) { returnObject.ApiPacket.Packet = new PermittedGeoLocationViewModels() { District = result.District, Upazila = result.Upazila, Unions = result.Unions, Village = result.Village, CenterInfo = result.CenterInfo, CampInfo = result.CampInfo }; } ApiResponse <PermittedGeoLocationViewModels> response = new ApiResponse <PermittedGeoLocationViewModels>() { Success = result != null ? true : false, ApiPacket = fp, PageNo = apr.PageNo, PageSize = apr.PageSize, TotalRecord = 0, Message = result != null ? "Record Fetched successfully." : "Record Fetched fail.", Status = result != null ? 200 : 400 }; Tools.CopyClass(returnObject, response); break; } case "UniqueId": { var requestObject = JsonConvert.DeserializeObject <RequestForUniqueId>(apr.ApiPacket.Packet.ToString()); var result = new UniqueId().SaveAndGet(requestObject ?? new RequestForUniqueId(), apr.UserId); returnObject = GetApiResponse(apr, result.ToList <object>(), result.Count); break; } case "SpinnerData": { var spinnerRequest = JsonConvert.DeserializeObject <SpinnerRequest>(apr.ApiPacket.Packet.ToString()); SpinnerData spinner = new SpinnerData(); var result = spinner.APIGetSpinnerData(QueryFromAPIPacketRequest(apr), spinnerRequest); obj.AddRange(result); returnObject = GetApiResponse(apr, obj, apr.TotalRecord != 0 ? spinner.APIGetTotalRecord(QueryFromAPIPacketRequest(apr), spinnerRequest) : apr.TotalRecord); break; } case "BlockInfo": { var requestObject = new ForApiResponse() { UserId = apr.UserId }; BlockInfo blockinfo = new BlockInfo(); var result = blockinfo.APIGetBlockList(requestObject); obj.AddRange(result); returnObject = GetApiResponse(apr, result.ToList <object>(), result.Count); break; } default: { ApiResponse <object> response = new ApiResponse <object>() { Success = false, ApiPacket = null, PageNo = apr.PageNo, PageSize = apr.PageSize, TotalRecord = 0, Message = "Table is not registered to System", Status = 400 }; return(response); } } return(returnObject); }
public ApiResponse <Object> GetPacketByUserId(ApiPacketRequest apr) { return(null); }
public ApiResponse <object> ProcessFetch(ApiPacketRequest apr, DbContext dbContext = null, params IApiHandler[] attachApiHandler) { //declartation part ApiResponse <Object> returnObject; List <object> obj = new List <object>(); bool ispageSizeOrPageNoZeo = false; object model = dynamic.GetInstance(dynamic.GetFullyQualifiedPath(apr.TableName)); object modelData = JsonConvert.DeserializeObject(apr.ApiPacket.Packet.ToString(), model.GetType()); //Page Size & Page No 0 ispageSizeOrPageNoZeo = apr.PageNo == 0 && apr.PageSize == 0; apr.PageNo = apr.PageNo == 0 ? 1 : apr.PageNo; apr.PageSize = apr.PageSize == 0 ? int.MaxValue : apr.PageSize; List <object> result2 = new List <object>(); switch (apr.Command) { case "GetData": { if (apr.TableName == "SpinnerData") { var spinnerRequest = JsonConvert.DeserializeObject <SpinnerRequest>(apr.ApiPacket.Packet.ToString()); SpinnerData spinner = new SpinnerData(_config); List <SpinnerValue> result = new List <SpinnerValue>(); Tuple <int, List <SpinnerValue> > tupleResult = new Tuple <int, List <SpinnerValue> >(0, new List <SpinnerValue>()); if (!string.IsNullOrEmpty(spinnerRequest.Sql)) { tupleResult = spinner.APIGetSpinnerDataFromSP(spinnerRequest.Sql, spinnerRequest.DisplayText, spinnerRequest.ValueText, apr.PageSize, apr.PageNo); result = tupleResult.Item2; } else { result = spinner.APIGetSpinnerData(QueryFromAPIPacketRequest(apr), spinnerRequest); } obj.AddRange(result); returnObject = GetApiResponse(apr, obj, tupleResult.Item1 == 0 ? result.Count() : tupleResult.Item1); break; } else if (apr.TableName == "SingleValue") { var spinnerRequest = JsonConvert.DeserializeObject <SqlPacket>(apr.ApiPacket.Packet.ToString()); var singleValue = db.GetSingleValue(spinnerRequest.Select, spinnerRequest.Where, spinnerRequest.OrderBy); obj.Add(singleValue); returnObject = GetApiResponse(apr, obj, 1); break; } else { var packet = JsonConvert.DeserializeObject <SqlPacket>(apr.ApiPacket.Packet.ToString()); var select = packet.Select; var where = packet.Where; var orderBy = packet.OrderBy; var includedChild = packet.IncludeChild; model = dynamic.GetInstance(dynamic.GetFullyQualifiedPath(packet.ModelName)); var result = db.SelectWithPaging(model, select, where, orderBy, includedChild, apr.PageNo, apr.PageSize, dbContext).ToList(); object handlerResult = result; if (attachApiHandler != null) { for (int i = 0; i < attachApiHandler.Count(); i++) { handlerResult = attachApiHandler[i].Handle(Mode.Pre, ProcessType.Get, handlerResult, db); } } if (handlerResult.GetType().GenericTypeArguments.Length == 0) { if (ispageSizeOrPageNoZeo) { apr.PageNo = 0; apr.PageSize = 0; } returnObject = GetApiResponseForPacket(apr, handlerResult, apr.TotalRecord != 0 ? db.SelectTotalRecordCount( model, packet.Select, packet.Where, packet.OrderBy, dbContext) : apr.TotalRecord); } else { obj.AddRange((List <object>)handlerResult); if (ispageSizeOrPageNoZeo) { apr.PageNo = 0; apr.PageSize = 0; } returnObject = GetApiResponse(apr, obj, apr.TotalRecord != 0 ? db.SelectTotalRecordCount(model, packet.Select, packet.Where, packet.OrderBy, dbContext) : apr.TotalRecord); } break; } } default: { ApiResponse <object> response = new ApiResponse <object>() { Success = false, ApiPacket = null, PageNo = apr.PageNo, PageSize = apr.PageSize, TotalRecord = 0, Message = "Table is not registered", Status = 400 }; return(response); } } if (attachApiHandler != null) { for (int i = 0; i < attachApiHandler.Count(); i++) { attachApiHandler[i].Handle(Mode.Post, ProcessType.Get, returnObject.ApiPacket, db); } } if (returnObject.ApiPacket.Packet != null) { returnObject.ApiPacket.PacketList = null; } return(returnObject); }
public Task <ApiResponse <object> > ProcessFetchAsync(ApiPacketRequest apr, DbContext dbContext = null, params IApiHandler[] attachApiHandler) { return(Task.Run(() => ProcessFetch(apr, dbContext, attachApiHandler))); }
public ApiResponse SyncData(ApiPacketRequest apr) { ApiResponse returnObject = new ApiResponse(); CommandResult commandResult = new CommandResult(); UnitOfWork unitOfWork = new UnitOfWork(); try { string result = ""; switch (apr.Command) { case "add": { var dynamicModelType = Dynamic.GetObjectType(apr.TableName); var addObj = JsonConvert.DeserializeObject(apr.ApiPacket.Packet.ToString(), dynamicModelType); Dynamic.DynamicRepo(addObj, unitOfWork.context, DBOperations.INSERT); result = unitOfWork.SaveChange(); break; } case "update": { var dynamicModelType = Dynamic.GetObjectType(apr.TableName); var updateObj = Activator.CreateInstance(dynamicModelType); Tools.CopyJsonData(updateObj, apr.ApiPacket.Packet.ToString()); Dynamic.DynamicRepo(updateObj, unitOfWork.context, DBOperations.UPDATE); result = unitOfWork.SaveChange(); break; } case "delete": { var dynamicModelType = Dynamic.GetObjectType(apr.TableName); var updateObj = Activator.CreateInstance(dynamicModelType); Tools.CopyJsonData(updateObj, apr.ApiPacket.Packet.ToString()); Dynamic.DynamicRepo(updateObj, unitOfWork.context, DBOperations.DELETE); result = unitOfWork.SaveChange(); break; } default: { return(new ApiResponse() { Success = false, Message = "Table is not registered", Status = 400 }); } } commandResult = new CommandResult() { Success = result != "" ? false : true, Status = result != "" ? 400 : 200, Message = result != "" ? result : string.Format(@"Record {0} successfully.", apr.Command == "add" ? "saved" : apr.Command == "update" ? "updated" : apr.Command == "delete" ? "deleted" : "") }; Tools.CopyClass(returnObject, commandResult); return(returnObject); } catch (Exception ex) { return(new ApiResponse() { Success = false, Message = ex.Message, Status = 400 }); } }