Exemplo n.º 1
0
        public async Task <ActionResult> DeleteAllContacts()
        {
            MyContactRepository repo = new MyContactRepository();
            await repo.DeleteAllContacts();

            return(Redirect("/Contacts"));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> AddSampleData()
        {
            MyContactRepository repo = new MyContactRepository();
            await repo.AddSampleData();

            return(Redirect("/Contacts"));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Details(string id)
        {
            MyContact           contact = null;
            MyContactRepository repo    = new MyContactRepository();

            contact = await repo.GetContact(id);

            return(View(contact));
        }
        public async Task <ActionResult> Delete(string id)
        {
            MyContactRepository contactRepository = new MyContactRepository();

            if (id != null)
            {
                await contactRepository.DeleteContact(id);
            }
            return(Redirect("/"));
        }
Exemplo n.º 5
0
        public async Task <ActionResult> Create(MyContact contact)
        {
            if (Request.HttpMethod == "POST")
            {
                MyContactRepository repo = new MyContactRepository();
                await repo.AddContact(contact);

                return(Redirect("/Contacts"));
            }
            else
            {
                return(View(contact));
            }
        }
        public async Task <ActionResult> Create(MyContact myContact)
        {
            // if a contact was submitted, create it
            if (Request.HttpMethod == "POST")
            {
                MyContactRepository contactRepository = new MyContactRepository();
                await contactRepository.AddContact(myContact);

                return(Redirect("/"));
                // else create a empty model & return to the create page view
            }
            else
            {
                return(View(myContact));
            }
        }
Exemplo n.º 7
0
        public async Task <ActionResult> Edit(string Id, MyContact contact)
        {
            MyContactRepository repo = new MyContactRepository();

            if (Request.HttpMethod == "POST")
            {
                await repo.UpdateContact(contact);

                return(Redirect("/Contacts"));
            }
            else
            {
                contact = await repo.GetContact(Id);

                return(View(contact));
            }
        }
Exemplo n.º 8
0
        public async Task <ActionResult> Index(int?pageNumber)
        {
            int pageSize  = 8;
            int pageIndex = (pageNumber != null) ? (int)pageNumber - 1 : 0;

            ViewBag.pageIndex = pageIndex;
            ViewBag.pageSize  = pageSize;

            List <MyContact>    contacts = null;
            MyContactRepository repo     = new MyContactRepository();

            ViewBag.contactCount = await repo.GetContactCount();

            contacts = await repo.GetContacts(pageIndex, pageSize);

            return(View(contacts));
        }
        public async Task <ActionResult> Index(int?pageNumber)
        {
            // setup paging control
            int pageSize  = 8;
            int pageIndex = (pageNumber != null) ? (int)pageNumber - 1 : 0;

            ViewBag.pageIndex = pageIndex;
            ViewBag.pageSize  = pageSize;

            // get a list of all contacts
            List <MyContact>    contacts          = null;
            MyContactRepository contactRepository = new MyContactRepository();

            ViewBag.ContactCount = await contactRepository.GetContactCount();

            contacts = await contactRepository.GetContacts(pageIndex, pageSize);

            // pass the collection of contacts to the view in the model
            return(View(contacts));
        }