Ejemplo n.º 1
0
 public ActionResult CreateContact(Contact contact)
 {
     if (ModelState.IsValid)
     {
         Book.AddContact(contact);
         SaveChanges();
         return(Json(new { success = true }));
     }
     return(View(contact));
 }
Ejemplo n.º 2
0
    static void Main()
    {
        Book b = new Book();
        int  choise;

        b.Entry();
        do
        {
            Console.Clear();
            Console.WriteLine("What option you want to use?\n");
            Console.WriteLine("1 - Add contact \n" + "2 - Delete contact \n" + "3 - Show your contacts\n" + "4 - Exit\n");
            b.ChangeColor();
            Console.Write("Option №: ");
            choise = int.Parse(Console.ReadLine());
            b.ResetColor();
            Console.Clear();

            switch (choise)
            {
            case 1:
            {
                b.ChangeColor();
                Console.WriteLine("Enter contact name:");
                b.ResetColor();
                string name = Console.ReadLine();
                b.ChangeColor();
                Console.WriteLine("\nEnter phone number:");
                b.ResetColor();
                string phone = Console.ReadLine();
                b.AddContact(name, phone);
            }
            break;

            case 2:
            {
                b.ChangeColor();
                Console.WriteLine("Enter contact name:");
                string name = Console.ReadLine();
                b.DelContact(name);
            }
            break;

            case 3:
            {
                b.Show();
                System.Threading.Thread.Sleep(10000);
            }
            break;

            case 4:
            {
                Environment.Exit(0);
            }
            break;

            default:
                Console.WriteLine("You chose the wrong option. Please, try again.");
                break;
            }
        }while (choise != 4);
    }