/// <summary> /// Sends a DELETE request to the server /// Returns the parsed content of the response /// </summary> /// <typeparam name="TResponse">Expected type of the response</typeparam> /// <param name="path">path of the deletable resource</param> /// <param name="id">Identification of the deletable resource</param> /// <returns>Content of the server's response</returns> public async Task <TResponse> DeleteAsync <TResponse>(string path, int id) { _loggingService.LogDebug(new { action = nameof(DeleteAsync), path, id }); using (var client = new HttpClient()) { client.BaseAddress = baseAddress; client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Add("sessiontoken", MainWindowViewModel.SessionToken); var response = await client.DeleteAsync(path + "/" + id.ToString()); if (!response.IsSuccessStatusCode) { throw new Exception("Error during DELETE request!"); } var apiResponse = await response.Content.ReadAsAsync <AlpApiResponse <TResponse> >(); if (!apiResponse.Success) { throw new Exception(apiResponse.Message); } return(apiResponse.Value); } }
/// <summary> /// requests password change /// </summary> /// <param name="changePasswordRequest"></param> /// <returns></returns> public async Task ChangePassword(ChangePasswordRequest changePasswordRequest) { _loggingService.LogDebug(new { action = nameof(ChangePassword) }); await _apiService.PostAsync("Account/ChangePassword", changePasswordRequest); }
/// <summary> /// creates a new item /// </summary> /// <param name="dto"></param> /// <returns></returns> public async Task <bool> AddNewInventoryItem(ItemDto dto) { _loggingService.LogDebug(new { action = nameof(AddNewInventoryItem), dto = dto.ToString() }); return(await _apiService.PostAsync("Item/AddNewItem", dto)); }
/// <summary> /// Returns the mainFrame to the previous page /// </summary> public void GoBack() { _loggingService.LogDebug(new { action = nameof(GoBack) }); backStack.Pop(); if (backStack.Count > 0) { NavigateTo(CurrentPageKey); } else { NavigateTo(ViewModelLocator.SystemWelcomeScreen); } }
/// <summary> /// requests the change of departemnt on the ids /// </summary> /// <param name="itemIds"></param> /// <param name="departmentId"></param> /// <param name="priority"></param> /// <returns></returns> public async Task <List <ItemDto> > ChangeDepartment(List <int> itemIds, int departmentId, bool priority) { _loggingService.LogDebug(new { action = nameof(ChangeDepartment), itemIds, departmentId, priority }); var operations = itemIds.Select(itemId => new OperationDto { ItemId = itemId, OperationType = OperationType.ChangeDepartment, PayLoadId = departmentId, Priority = priority }).ToList(); return(await _apiService.PostAsync <List <OperationDto>, List <ItemDto> >("Operation/QueueOperations", operations)); }
/// <summary> /// shows the editor window of the given dto /// </summary> /// <typeparam name="T"></typeparam> /// <param name="dto"></param> /// <returns></returns> public DialogResult <T> ShowDtoEditorWindow <T>(T dto) where T : LookupDtoBase, new() { _loggingService.LogDebug(new { action = nameof(ShowDtoEditorWindow), dto = dto?.ToString() }); var window = GetLookupWindowByDto(dto); ((LookupEditorWindowViewModel <T>)window.DataContext).Parameter = (T)dto.Copy(); if (window.ShowDialog() == true) { return(new DialogResult <T>() { Value = ((LookupEditorWindowViewModel <T>)window.DataContext).ReturnParameter, Accepted = true }); } return(new DialogResult <T> { Accepted = false, }); }
/// <summary> /// sends employee data towards the server /// if it is already in the database, it updates /// </summary> /// <param name="dto"></param> /// <returns></returns> public async Task AddOrEditEmployee(EmployeeDto dto) { _loggingService.LogDebug(new { action = nameof(AddOrEditEmployee), dto = dto.ToString() }); await _apiService.PostAsync("Employee/AddOrEditEmployee", dto); }
/// <summary> /// Export /// </summary> /// <param name="itemList"></param> /// <param name="itemTypes"></param> public void ExportToExcel(List <ItemDto> itemList, List <ItemPropertyType> itemTypes) { _loggingService.LogDebug(new { action = nameof(ExportToExcel) }); // Configure save file dialog box var dlg = new Microsoft.Win32.SaveFileDialog { FileName = $"Leltár export {DateTime.Now.ToString("yyyyMMdd_HHmmss")}", // Default file name DefaultExt = ".xlsx", // Default file extension Filter = "Excel Sheet (.xlsx)|*.xlsx" // Filter files by extension }; // Show save file dialog box var result = dlg.ShowDialog(); // Process save file dialog box results if (result != true) { return; } using (var excelPackage = new ExcelPackage()) { excelPackage.Workbook.Worksheets.Add(DateTime.Today.ToShortDateString()); var workSheet = excelPackage.Workbook.Worksheets.First(); var range = workSheet.Cells[1, 1, 1, itemTypes.Count]; range.Merge = true; range.Value = $"Leltár export {DateTime.Now.ToString()}"; range.Style.Font.Italic = true; for (int i = 0; i < itemTypes.Count; i++) { var cell = workSheet.Cells[2, i + 1]; cell.Value = itemTypes[i].GetDescription(); cell.Style.Border.BorderAround(ExcelBorderStyle.Thin); cell.Style.Border.Bottom.Style = ExcelBorderStyle.Thick; cell.Style.Font.Bold = true; cell.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; } for (int i = 0; i < itemList.Count; i++) { for (int j = 0; j < itemTypes.Count; j++) { var cell = workSheet.Cells[i + HeaderOffset + 1, j + 1]; cell.Value = GetItemDataByItemPropertyType(itemList[i], itemTypes[j]); cell.Style.Border.BorderAround(ExcelBorderStyle.Thin); } } workSheet.Cells.AutoFitColumns(); // Save document var excelFile = new FileInfo(dlg.FileName); excelPackage.SaveAs(excelFile); //Open in excel var isExcelInstalled = Type.GetTypeFromProgID("Excel.Application") != null ? true : false; if (isExcelInstalled) { System.Diagnostics.Process.Start(excelFile.ToString()); } } }