private async static void Process()
        {
            //获取当前联系人列表
            HttpClient httpClient = new HttpClient();
            HttpResponseMessage response = await httpClient.GetAsync("http://localhost/selfhost/api/contacts");
            IEnumerable<Contact> contacts = await response.Content.ReadAsAsync<IEnumerable<Contact>>();
            Console.WriteLine("当前联系人列表:");
            ListContacts(contacts);

            //添加新的联系人
            Contact contact = new Contact { Name = "王五", PhoneNo = "0512-34567890", EmailAddress = "*****@*****.**" };
            await httpClient.PostAsJsonAsync<Contact>("http://localhost/selfhost/api/contacts", contact);
            Console.WriteLine("添加新联系人“王五”:");
            response = await httpClient.GetAsync("http://localhost/selfhost/api/contacts");
            contacts = await response.Content.ReadAsAsync<IEnumerable<Contact>>();
            ListContacts(contacts);

            //修改现有的某个联系人
            response = await httpClient.GetAsync("http://localhost/selfhost/api/contacts/001");
            contact = (await response.Content.ReadAsAsync<IEnumerable<Contact>>()).First();
            contact.Name = "赵六";
            contact.EmailAddress = "*****@*****.**";
            await httpClient.PutAsJsonAsync<Contact>("http://localhost/selfhost/api/contacts/001", contact);
            Console.WriteLine("修改联系人“001”信息:");
            response = await httpClient.GetAsync("http://localhost/selfhost/api/contacts");
            contacts = await response.Content.ReadAsAsync<IEnumerable<Contact>>();
            ListContacts(contacts);

            //删除现有的某个联系人
            await httpClient.DeleteAsync("http://localhost/selfhost/api/contacts/002");
            Console.WriteLine("删除联系人“002”:");
            response = await httpClient.GetAsync("http://localhost/selfhost/api/contacts");
            contacts = await response.Content.ReadAsAsync<IEnumerable<Contact>>();
            ListContacts(contacts);
        }
示例#2
0
        /// <summary>
        /// Pobiera obiekt bitmapowy z kontaktu.
        /// </summary>
        /// <param name="contact">Kontakt do przeorania.</param>
        /// <returns></returns>
        public static BitmapImage GetImageFromConcat(Contact contact)
        {
            BitmapImage image = new BitmapImage();

            if (contact.GetPicture() != null)
                image.SetSource(contact.GetPicture());
            else
            {
                // _TODO_PC: Ustawić jakiś domyślny.
            }

            return image;
        }
        public void Destroy(Contact contact)
        {
            var entity = new Contact
            {
                Id = contact.Id,
                Subject = contact.Subject,
                Email = contact.Email,
                Message = contact.Message,
                CreatedOn = contact.CreatedOn,
                ModifiedOn = contact.ModifiedOn,
                IsDeleted = contact.IsDeleted,
                DeletedOn = contact.DeletedOn
            };

            this.db.Contacts.Attach(entity);
            this.db.Contacts.Remove(entity);
            this.db.SaveChanges();
        }
        public void Update(Contact contact)
        {
            var entity = new Contact
            {
                Id = contact.Id,
                Subject = contact.Subject,
                Email = contact.Email,
                Message = contact.Message,
                CreatedOn = contact.CreatedOn,
                ModifiedOn = contact.ModifiedOn,
                IsDeleted = contact.IsDeleted,
                DeletedOn = contact.DeletedOn
            };

            this.db.Contacts.Attach(entity);
            this.db.Entry(entity).State = EntityState.Modified;
            this.db.SaveChanges();
        }
        public ActionResult Contacts_Update(Contact contact)
        {
            if (this.ModelState.IsValid)
            {
                this.contactService.Update(contact);

                RouteValueDictionary routeValues = this.GridRouteValues();
                return this.RedirectToAction("Index", routeValues);
            }

            return this.View("Index", this.contactService.Read());
        }
        public ActionResult Contacts_Destroy(Contact contact)
        {
            RouteValueDictionary routeValues;

            this.contactService.Destroy(contact);

            routeValues = this.GridRouteValues();

            return this.RedirectToAction("Index", routeValues);
        }