protected override string Remove(string input) { string output = ""; try { logger.Info($"Attempt to remove Reciept({input})..."); Reciept result = model.Remove(int.Parse(input)); logger.Info($"Reciept({input}) was removed successfully."); output = $"Reciept#({input}):\n" + "+---+---------------------+--------+---------+---------------+----------+\n" + string.Format(Reciept.OutputPattern, "Id", "Name", "Quantity", "Price", "Customer", "Date") + "+---+---------------------+--------+---------+---------------+----------+\n" + result.ToString(); } catch (FormatException fe) { logger.Error(fe, $"Cannot covert values."); output = "Wrong input format.\nTry again.\n"; } catch (RecieptException re) { logger.Error(re, $"Cannot remove Reciept({input})."); output = "Error occured while removing a reciept.\nTry again.\n"; } catch (Exception e) { logger.Fatal(e, $"Unexpected error."); output = "Unexpected error occured while removing a reciept.\nTry again.\n"; } return(output); }
protected override string Add(string input) { string output = ""; try { logger.Info($"Attempt to add Reciept({input})..."); string[] parameters = input.Split('|'); DateTime RecieptDate = DateTime.ParseExact(parameters[5], "dd-MM-yyyy", null); Reciept result = model.Add(int.Parse(parameters[0]), parameters[1], int.Parse(parameters[2]), double.Parse(parameters[3]), parameters[4], RecieptDate); logger.Info($"Reciept({input}) was created successfully."); output = "Obect was successfully created:\n" + "+---+---------------------+--------+---------+---------------+----------+\n" + string.Format(Reciept.OutputPattern, "Id", "Name", "Quantity", "Price", "Customer", "Date") + "+---+---------------------+--------+---------+---------------+----------+\n" + result.ToString(); } catch (FormatException fe) { logger.Error(fe, $"Cannot covert values."); output = "Wrong format.\nTry again.\n"; } catch (RecieptException re) { logger.Error(re, $"Cannot create Reciept({input})."); output = "Error occured while creating a reciept.\nTry again.\n"; } catch (Exception e) { logger.Fatal(e, $"Unexpected error."); output = "Unexpected error occured while creating a reciept.\nTry again later.\n"; } return(output); }