public HttpResponseMessage Get()
 {
     Address address = new Address
     {
         Province = "江苏省",
         City = "苏州市",
         District = "工业园区",
         Street = "星湖街328号"
     };
     Contact contact = new Contact
     {
         Name = "张三",
         PhoneNo = "123456789",
         EmailAddress = "*****@*****.**",
         Address = address
     };
     IBodyModelValidator validator = new DefaultBodyModelValidator();
     HttpActionContext actionContext = new HttpActionContext
     {
         ControllerContext = this.ControllerContext
     };
     ModelMetadataProvider metadataProvider =actionContext.GetMetadataProvider();
     validator.Validate(contact, typeof(Contact), metadataProvider,actionContext, "contact");
     return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest,actionContext.ModelState);
 }
Пример #2
0
 public void Put(Contact contact)
 {
     if (string.IsNullOrEmpty(contact.Id))
     {
         contact.Id = Guid.NewGuid().ToString();
     }
     Contacts.Add(contact);
 }
 public IHttpActionResult GetAllContacts()
 {
     Contact[] contacts = new Contact[]
     {
     new Contact{ Name="张三", PhoneNo="123", EmailAddress="*****@*****.**"},
     new Contact{ Name="李四", PhoneNo="456", EmailAddress="*****@*****.**"},
     new Contact{ Name="王五", PhoneNo="789", EmailAddress="*****@*****.**"},
     };
     return Json<IEnumerable<Contact>>(contacts);
 }
 public IEnumerable<Contact> GetAllContacts()
 {
     Contact[] contacts = new Contact[]
     {
         new Contact{ Name="张三", PhoneNo="123", EmailAddress="*****@*****.**"},
         new Contact{ Name="李四", PhoneNo="456", EmailAddress="*****@*****.**"},
         new Contact{ Name="王五", PhoneNo="789", EmailAddress="*****@*****.**"},
     };
     return contacts;
 }
 public HttpResponseMessage GetAllContacts(string callback)
 {
     Contact[] contacts = new Contact[]
     {
         new Contact{ Name="张三", PhoneNo="123", EmailAddress="*****@*****.**"},
         new Contact{ Name="李四", PhoneNo="456", EmailAddress="*****@*****.**"},
         new Contact{ Name="王五", PhoneNo="789", EmailAddress="*****@*****.**"},
     };
     JavaScriptSerializer serializer = new JavaScriptSerializer();
     string content = string.Format("{0}({1})", callback, serializer.Serialize(contacts));
     return new HttpResponseMessage(HttpStatusCode.OK)
     {
         Content = new StringContent(content, Encoding.UTF8, "text/javascript")
     };
 }
Пример #6
0
        public ContactRepository()
        {
            var ctx = HttpContext.Current;

            if (ctx != null)
            {
                if (ctx.Cache[CacheKey] == null)
                {
                    var contacts = new Contact[]
                {
                new Contact
                {
                    Number = "1", Name = "aotuo zhang"
                }
               
            };

                    ctx.Cache[CacheKey] = contacts;
                }
            }
        }
Пример #7
0
        public bool SaveContact(Contact contact)
        {
            var ctx = HttpContext.Current;

            if (ctx != null)
            {
                try
                {
                    var currentData = ((Contact[])ctx.Cache[CacheKey]).ToList();
                    currentData.Add(contact);
                    ctx.Cache[CacheKey] = currentData.ToArray();

                    return true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    return false;
                }
            }

            return false;
        }
Пример #8
0
        public HttpResponseMessage Post(Contact contact, HttpRequestMessage requestMessage)
        {
            _contactRepository.SaveContact(contact);

            var response = requestMessage.CreateResponse<Contact>(System.Net.HttpStatusCode.Created, contact);
            

            //Queuestore q = new Queuestore();
            
            //string queuename = "hahaha";
            // Create or reference an existing queue 
           // CloudQueue queue = q.CreateQueueAsync(queuename).Result;
         
            int num = Convert.ToInt32(contact.Number);

           
            ITestLogHandler ilogHandler = new TestLogHandler();

      
            ilogHandler.SendQueueAsyncAll(num);

           //q.SendQueueAsyncAll(num, responselog);
            return response;
        }
Пример #9
0
 public Contact Post(Contact contact)
 {
     return contact;
 }
Пример #10
0
 public void Post(Contact contact)
 {
     Delete(contact.Id);
     Contacts.Add(contact);
 }