public async Task <ServiceResponseResult> Get(long locationId, AccessHistorySearchReqModel searchReqModel) { Logger.WriteInformation("Geting access history data."); var result = await _apiService.GetAccessHistory(locationId, searchReqModel); if (result.StatusCode == System.Net.HttpStatusCode.OK) { var searchResult = ((AccessHistorySearchResult)result.Result); result.Result = new AccessHistoryRespModel { TotalItems = searchResult.TotalRecords, Items = searchResult.Data.Select(x => new AccessHistorySearchRespModel { DeviceName = x.DeviceName, DeviceNameId = x.DeviceNameId, KeyHolderName = x.KeyName, KeySerialNumber = x.KeySerial, OperationCode = x.OperationCode, OperationDescription = x.OperationDescription, TransDate = x.TransDate, DeviceSerialNumber = x.DeviceSerial, OperationState = x.KeyboxErrorCode, OperationErrorCode = x.KeyboxErrorCode, ErrorCodeText = x.KeyboxErrorCode != "0" ? x.OperationDescription : "", ErrorSolutionText = "" }).ToList() }; } Logger.WriteInformation("Geting access history data completed."); return(result); }
public async Task <ServiceResponseResult> GetAccessHistory(long locationId, AccessHistorySearchReqModel searchReqModel) { return(await Task.FromResult(new ServiceResponseResult { StatusCode = System.Net.HttpStatusCode.BadRequest })); }
public async Task <ServiceResponseResult> GetAccessHistory(long locationId, AccessHistorySearchReqModel searchReqModel) { return(await Task.FromResult(new ServiceResponseResult { StatusCode = System.Net.HttpStatusCode.OK, Result = new Mock <AccessHistorySearchResult>().Object }));; }
public async Task <ServiceResponseResult> GetAccessHistory(long locationId, AccessHistorySearchReqModel searchReqModel) { return(await Task.FromResult(new ServiceResponseResult { StatusCode = System.Net.HttpStatusCode.OK, Result = JsonConvert.DeserializeObject <AccessHistorySearchResult>( File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "../../../", "ApiFakeResponseFiles", "GetAccessHistory.json"))) })); }
public async Task <ServiceResponseResult> GetAccessHistory(long locationId, AccessHistorySearchReqModel searchReqModel) { var builder = new UriBuilder(_appSettings.RemoteServer.BasePath + $"/api/ver7/KeyDeviceActivity"); var query = HttpUtility.ParseQueryString(builder.Query); query["deviceOwnerId"] = locationId.ToString(); PropertyInfo[] props = typeof(AccessHistorySearchReqModel).GetProperties(); foreach (var prop in props) { var attr = prop.GetCustomAttributes(true).Where(x => x is FromQueryAttribute).FirstOrDefault(); var val = prop.GetValue(searchReqModel); if (val != null && attr != null) { query.Add((attr as FromQueryAttribute).Name, val.ToString()); } } builder.Query = query.ToString(); string url = builder.ToString(); var request = GetRequest(new Uri(url), HttpMethod.Get); var response = await _httpClient.SendAsync(request); var responseContent = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { return(new ServiceResponseResult { StatusCode = System.Net.HttpStatusCode.OK, Result = JsonConvert.DeserializeObject <AccessHistorySearchResult>(responseContent) }); } else { return(new ServiceResponseResult { StatusCode = response.StatusCode, Result = JsonConvert.DeserializeObject(responseContent) }); } }
public async Task <ActionResult> Export([FromRoute][Required] long locationId, [FromQuery] AccessHistorySearchReqModel model, [FromQuery][Required] string type) { if (type != "excel") { return(BadRequest(new ErrorModel { Message = "Not supported type" })); } var res = await _accessHistoryService.Get(locationId, model); if (res.StatusCode != System.Net.HttpStatusCode.OK) { return(StatusCode(res.GetStatusCode(), res.Result)); } ExcelPackage.LicenseContext = LicenseContext.NonCommercial; ExcelPackage excel = new ExcelPackage(); var workSheet = excel.Workbook.Worksheets.Add("Sheet1"); workSheet.Cells[1, 1].LoadFromCollection(((AccessHistoryRespModel)res.Result).Items, true); return(File(excel.GetAsByteArray(), "application/vnd.ms-excel", "data.xlsx")); }
public async Task <ActionResult> Get([FromRoute][Required] long locationId, [FromQuery] AccessHistorySearchReqModel model) { var res = await _accessHistoryService.Get(locationId, model); return(StatusCode(res.GetStatusCode(), res.Result)); }