Exemple #1
0
        static void Main(string[] args)
        {
            SortedList <string, Entry> phoneBook;

            phoneBook = loadPhonebook();
            PhoneBookClass pb1 = new PhoneBookClass();
            string         answer;

            do
            {
                showMenu();
                answer = Console.ReadLine();
                Console.WriteLine();

                switch (answer)
                {
                case "1":
                    pb1.showPhoneBook(phoneBook);
                    break;

                case "2":
                    (string new_Name, Entry new_Entry) = creatingEntry();
                    pb1.addEntry(new_Name, new_Entry, phoneBook);
                    break;

                case "3":
                    Console.WriteLine("Which entry would you like to edit ?");
                    //Console.WriteLine(phoneBook.GetKey(0));

                    break;

                case "4":
                    deleteEntry(phoneBook);
                    break;

                case "5":

                    savePhonebook(phoneBook);
                    Console.WriteLine("File is saved");
                    break;

                default:
                    Console.WriteLine("Wrong answer type something of the following");
                    Console.WriteLine();
                    showMenu();
                    answer = Console.ReadLine();
                    Console.WriteLine();
                    break;
                }
            } while (answer.Equals("5") == false);
        }
        public IHttpActionResult Put(PhoneBookClass pbc)
        {
            var updateentry = db.PhoneBooks.Where(x => x.Id == pbc.Id).FirstOrDefault <PhoneBook>();

            if (updateentry != null)
            {
                updateentry.Id          = pbc.Id;
                updateentry.Name        = pbc.Name;
                updateentry.PhoneNumber = pbc.PhoneNumber;
                db.SaveChanges();
            }
            else
            {
                return(NotFound());
            }
            return(Ok());
        }
        public IHttpActionResult getEntryId(int id)
        {
            PhoneBookClass entrydetail = null;

            entrydetail = db.PhoneBooks.Where(x => x.Id == id).Select(x => new PhoneBookClass()
            {
                Id          = x.Id,
                Name        = x.Name,
                PhoneNumber = x.PhoneNumber,
            }).FirstOrDefault <PhoneBookClass>();

            if (entrydetail == null)
            {
                return(NotFound());
            }
            return(Ok(entrydetail));
        }
Exemple #4
0
        public ActionResult Edit(int id)
        {
            PhoneBookClass pbobj = null;

            HttpClient hc = new HttpClient();

            hc.BaseAddress = new Uri("http://localhost:62805/api/");

            var consumeapi = hc.GetAsync("PhoneBookCrud?id=" + id.ToString());

            consumeapi.Wait();

            var readdata = consumeapi.Result;

            if (readdata.IsSuccessStatusCode)
            {
                var displaydata = readdata.Content.ReadAsAsync <PhoneBookClass>();
                displaydata.Wait();
                pbobj = displaydata.Result;
            }
            return(View(pbobj));
        }
Exemple #5
0
        public ActionResult Edit(PhoneBookClass pbc)
        {
            HttpClient hc = new HttpClient();

            hc.BaseAddress = new Uri("http://localhost:62805/api/PhoneBookCrud");

            var insertrecord = hc.PutAsJsonAsync <PhoneBookClass>("PhoneBookCrud", pbc);

            insertrecord.Wait();

            var savedata = insertrecord.Result;

            if (savedata.IsSuccessStatusCode)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.message = "Entry Not Updated...!";
            }

            return(View(pbc));
        }