예제 #1
0
        public virtual HttpResponseMessage SaveContact(Contact contact, HttpRequestMessage ApiPostRequest)
        {
            var request = HttpContext.Current;

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

                    return ApiPostRequest.CreateResponse<Contact>(System.Net.HttpStatusCode.Created, contact); ;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    return null;
                }
            }

            return null;
        }
예제 #2
0
        public ContactRepository()
        {
            request = HttpContext.Current;

            if (request != null)
            {
                if (request.Cache[CacheKey] == null)
                {
                    var contacts = new Contact[]
                    {
                        new Contact
                        {
                             Id = 1, Name = "George"
                        },
                        new Contact
                        {
                            Id = 2, Name = "Dan"
                        }
                    };

                    request.Cache[CacheKey] = contacts;
                }
            }
        }
예제 #3
0
 public HttpResponseMessage Post(Contact contact)
 {
     return _contactRepository.SaveContact(contact, Request);
 }