internal static async void ValidateData(IEnumerable <Sales> sales) { // manager check try { var managerActiveTask = managerService.FindAsync(sales.First().CreatedByUserId); var managerActive = await managerActiveTask; MessageUtility.ShowInformationMessage("Manager found:" + managerActive.Name); } catch (Exception e) { Console.WriteLine($"Exception Handler: {e}"); MessageUtility.ShowErrorMessage("This manager is not in the database"); throw new Exception("This manager is not in the database"); } #region validate clients & products //// customer check //try //{ // var clients = sales.Select(s => s.ClientName).ToList(); // bool check = clientService.Check(clients).Result; // if (check == false) // { // MessageUtility.ShowErrorMessage("Одного или нескольких клиентов нет в БД"); // throw new Exception("Одного или нескольких клиентов нет в БД"); // } //} //catch (Exception e) //{ // Console.WriteLine($"Exception Handler: {e}"); // MessageUtility.ShowErrorMessage("ERROR IN CLIENTS CHECKING"); //} //// check products //try //{ // var products = sales.Select(s => s.ProductName).ToList(); // bool check = productService.Check(products).Result; // if (check == false) // { // MessageUtility.ShowErrorMessage("Одного или нескольких продуктов нет в БД"); // throw new Exception("Одного или нескольких продуктов нет в БД"); // } //} //catch (Exception e) //{ // Console.WriteLine($"Exception Handler: {e}"); // MessageUtility.ShowErrorMessage("ERROR IN PRODUCTS CHECKING"); //} #endregion }
// Define the event handlers. internal static void OnChanged(object source, FileSystemEventArgs e) => // actions when adding a new file // file processing Task.Run(() => { using (StreamReader streamReader = new StreamReader(e.FullPath, Encoding.Default)) { byte[] bytes = streamReader.CurrentEncoding.GetBytes(streamReader.ReadToEnd()); FileInfo fileInfo = new FileInfo(e.FullPath); // Check the format of the file name 1 if (ValidateFileName(fileInfo.Name)) { WorkWithFile(bytes); MessageUtility.ShowInformationMessage("OK"); } else { MessageUtility.ShowValidationMessage("Invalid file format!"); } } });