public void UpdateDBEntry(PhonebookEntry entry, PhonebookEntryViewModel entryViewModel)
 {
     entry.FirstName = entryViewModel.FirstName;
     entry.LastName = entryViewModel.LastName;
     entry.Type = entryViewModel.Type;
     this.data.PhonebookEntries.Update(entry);
     this.data.SaveChanges();
 }
 public IHttpActionResult Create(PhonebookEntryViewModel entryViewModel)
 {
     if (!this.ModelState.IsValid)
     {
         return BadRequest(this.ModelState);
     }
     var entry = Mapper.Map<PhonebookEntry>(entryViewModel);
     services.CreateDBEntry(entry);
     return Ok(entryViewModel);
 }
        public IHttpActionResult Delete(PhonebookEntryViewModel entryViewModel)
        {
            var entry = this.data.PhonebookEntries.All().FirstOrDefault(p => p.Number == entryViewModel.Number);

            if (entry == null)
            {
                return BadRequest("No such entry found!");
            }
            services.DeleteDBEntry(entry);

            return Ok("Entry deleted!");
        }
        public IHttpActionResult Update(string number, PhonebookEntryViewModel entryViewModel)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(this.ModelState);
            }

            var entry = this.data.PhonebookEntries.All().FirstOrDefault(p => p.Number == number);

            if (entry == null)
            {
                return BadRequest("No such entry found!");
            }

            services.UpdateDBEntry(entry, entryViewModel);

            return Ok("Entry updated!");
        }