Exemple #1
0
        public ActionResult Edit(int id)
        {
            Contact contact = null;

            contact = ContactDbRepository.GetContact(id);  // a private method which we have created previously

            if (contact == null)
            {
                return(HttpNotFound("Contact Not Found"));
            }

            //fetching States and Countries for dropdownlist
            var allCounteries = new List <Country>();
            var allStates     = new List <State>();

            using (var dbContext = new ContactDbContext())
            {
                allCounteries = dbContext.Countries.OrderBy(c => c.CountryName).ToList();
                allStates     = dbContext.States.Where(s => s.CountryId.Equals(contact.CountryId)).OrderBy(s => s.StateName).ToList();
            }
            ViewBag.Countries = new SelectList(allCounteries, "CountryId", "CountryName", contact.CountryId);
            ViewBag.States    = new SelectList(allStates, "StateId", "StateName", contact.StateId);

            return(View(contact));
        }
Exemple #2
0
        public ActionResult View(int id) //details
        {
            // before this we have used view model , now we need to extend the contact class to add countryName & stateName fields..
            Contact selecedContact = null;

            selecedContact = ContactDbRepository.GetContact(id);
            return(View(selecedContact));
        }
Exemple #3
0
        public ActionResult Delete(int id)
        {
            Contact contact = null;

            contact = ContactDbRepository.GetContact(id);
            if (contact != null)
            {
                return(View(contact));
            }
            else
            {
                return(HttpNotFound("Contact Not Found"));
            }
        }