示例#1
0
        public IActionResult Get([FromBody] Handyman handyman)
        {
            Dictionary <string, object> res;

            try
            {
                res = Service.createSuccessRes();
                if (handyman.Id != 0)
                {
                    res.Add("Handyman", HandymanData.GetHandyman(handyman));
                    res.Add("Businesses", HandymanData.GetHandymanBusinesses(handyman.Id));
                    res.Add("Categories", HandymanData.GetHandymanCategories(handyman.Id));
                    res.Add("Areas", HandymanData.GetHandymanAreas(handyman.Id));
                }
                else
                {
                    res.Add("Handymen", HandymanData.GetAll());
                }
                return(Ok(res));
            }
            catch (System.Exception ex)
            {
                res = Service.createErrorRes(ex.Message);
                return(BadRequest(res));
            }
        }
示例#2
0
        public IActionResult Delete([FromBody] Handyman handyman)
        {
            Dictionary <string, object> res;

            try
            {
                res = HandymanData.Delete(handyman);
                return(Ok(res));
            }
            catch (System.Exception ex)
            {
                res = Service.createErrorRes(ex.Message);
                return(BadRequest(res));
            }
        }
        //Handles menu after successfull login
        public void LoginMenu()
        {
            while (true)
            {
                Console.Clear();
                ILogger logger = new ConsoleLogger();
                string  menu   =
                    currentUser.ToString() +
                    "\n1 - Find closest handyman\n" +
                    "2 - Find handymen in radius\n" +
                    "3 - Search handyman by username\n" +
                    "4 - Search handyman by specialization\n" +
                    "5 - Top up balance\n" +
                    "6 - Update account information\n" +
                    "7 - Back to main menu";
                Console.WriteLine(menu);
                Console.Write("Enter a number to navigate the menu: ");
                int userChocie = int.Parse(Console.ReadLine());


                // Calls functions based on user choice
                switch (userChocie)
                {
                case 1:
                    Dictionary <Handyman, double> ClosestHandyman = handymanProcessor.GetClosestHandyman(distanceProcess);
                    foreach (KeyValuePair <Handyman, double> kvp in ClosestHandyman)
                    {
                        Console.WriteLine($"{kvp.Key.Username} is {kvp.Value/1000} km away from you. Working fee: {kvp.Key.WorkingFee}");
                        Console.Write($"Do you want to work with {kvp.Key.Username} ? ");
                        string wantToWorkClosest = Console.ReadLine();
                        if (wantToWorkClosest.ToLower() == "yes")
                        {
                            kvp.Key.Work(currentUser);
                            logger.Info("Work done! Transaction complete.  Press ENTER to proceed!");
                        }
                    }
                    Console.ReadLine();
                    break;

                case 2:
                    Console.Write("Enter radius to search for handymen: ");
                    bool isRadius = double.TryParse(Console.ReadLine(), out double radius);
                    if (isRadius)
                    {
                        Dictionary <Handyman, double> ClosestHandymanInRadius = handymanProcessor.GetHandymanInRadius(distanceProcess, radius);
                        WriteHandymanInRadiusToFile(ClosestHandymanInRadius);
                        logger.Info("Done! Press ENTER to proceed!");
                        Console.ReadLine();
                    }
                    else
                    {
                        throw new ArgumentException("Not a valid input");
                    }

                    break;

                case 3:
                    Console.Write("Enter username of handymen: ");
                    string   handymanUsername   = Console.ReadLine();
                    Handyman handymanByUsername = handymanProcessor.GetHandymanByUsername(distanceProcess, handymanUsername);
                    Console.Write($"Do you want to work with {handymanByUsername.Username} for working fee: {handymanByUsername.WorkingFee}? ");
                    string wantToWorkName = Console.ReadLine();
                    if (wantToWorkName.ToLower() == "yes")
                    {
                        handymanByUsername.Work(currentUser);
                        logger.Info("Work done! Transaction complete.  Press ENTER to proceed!");
                    }
                    Console.ReadLine();
                    break;

                case 4:
                    Console.Write("Enter specialization of handymen: ");
                    string handymanSpecialization = Console.ReadLine();
                    Dictionary <Handyman, double> handymanBySpecialization = handymanProcessor.GetHandymanBySpecialization(distanceProcess, handymanSpecialization);
                    foreach (KeyValuePair <Handyman, double> kvp in handymanBySpecialization)
                    {
                        Console.WriteLine($"{kvp.Key.Username} - {kvp.Key.Specialization}");
                    }

                    logger.Info("Press ENTER to proceed!");
                    Console.ReadLine();
                    break;

                case 5:
                    Console.Write("Enter amount to upload to your balance: ");
                    bool topUp = int.TryParse(Console.ReadLine(), out int topup);
                    if (topUp)
                    {
                        currentUser.AddMoney(topup);
                    }
                    else
                    {
                        throw new ArgumentException("Not a valid input");
                    }

                    serializer.SaveData();
                    break;

                case 6:
                    UpdateAccountInformation(currentUser);
                    break;

                case 7:
                    HandleMenu();
                    break;

                case 8:
                    foreach (KeyValuePair <Handyman, double> kvp in distanceProcess.handymenWithRadius)
                    {
                        Console.WriteLine($"{kvp.Key.Username} is {kvp.Value} km away from you");
                    }
                    Console.ReadLine();
                    break;

                default:
                    logger.Error("Not a valid input. Press ENTER to proceed");
                    Console.ReadLine();
                    break;
                }
            }
        }
示例#4
0
 public void Setup()
 {
     user      = new User("Turi", "Turcsány", "Ádám", 25, "*****@*****.**", "Jósika+M+43");
     handyman1 = new Handyman("laci01", "Kovács", "László", 30, "*****@*****.**", "Gyõri+Kapu+160", "electrician");
     handyman2 = new Handyman("laci02", "Kovács", "László", 31, "*****@*****.**", "Gyõri+Kapu+161", "engineer");
 }