public void CreateContact(ChatContact contact)
 {
     Debug.WriteLine($"AddContact({contact.ID}, {contact.Name}");
     ContactsMap.Add(contact.ID, contact);
     DatabaseController.Insert(contact);
     SortContacts();
 }
        public void Delete(int id)
        {
            ContactBO contact = ContactsMap.Map(this.Contactrepository.GetContactById(id));

            if (contact == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            Contactrepository.Delete(id);
        }
        public HttpResponseMessage Put(int id, ContactBO contact)
        {
            contact.Id = id;
            var entity = ContactsMap.Map(contact);

            if (!Contactrepository.Update(entity))
            {
                throw new HttpResponseException(HttpStatusCode.NotModified);
            }
            else
            {
                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
        }
        public void AddMessage(ChatMessage msg)
        {
            var other = (Me == msg.RecipientID ? msg.SenderID : msg.RecipientID);

            ChatConversation conversation;

            if (!ConversationsMap.TryGetValue(other, out conversation))
            {
                ChatContact contact;
                if (!ContactsMap.TryGetValue(other, out contact))
                {
                    contact = new ChatContact(other, "no name");
                    ContactsMap.Add(other, contact);
                }
                conversation = new ChatConversation(contact);
                ConversationsMap.Add(other, conversation);
            }

            conversation.Messages.Add(msg);
        }
        public HttpResponseMessage Post(ContactBO request)
        {
            var data = ContactsMap.Map(request);

            var entity   = Contactrepository.Insert(data);
            var response = Request.CreateResponse(HttpStatusCode.Created, entity);

            try
            {
                string uri = Url.Link("DefaultApi", new { id = entity.ID });
                response.Headers.Location = new Uri(uri);
            }
            catch (Exception e)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = new StringContent("An error occurred, please try again"),
                    ReasonPhrase = "Critical exception"
                });
            }

            return(response);
        }
        protected ContactsMap ToModel(MapViewModel vm)
        {
            ContactsMap model = Mapper.Map <ContactsMap>(vm);

            return(model);
        }
        protected MapViewModel ToViewModel(ContactsMap model)
        {
            MapViewModel vm = Mapper.Map <MapViewModel>(model);

            return(vm);
        }