Exemplo n.º 1
0
        public async Task <ActionResult> PostEntry(Guid phonebookId, [FromBody] PhonebookEntryDTO entry)
        {
            if (!ModelState.IsValid)
            {
                BadRequest(ModelState);
            }

            var phonebook = await phonebookRepository.GetById(phonebookId);

            if (phonebook == null)
            {
                return(NotFound());
            }
            var phonebookEntry = PhonebookEntryFactory.Create(phonebook);

            phonebookEntry.Name        = entry.Name;
            phonebookEntry.PhoneNumber = entry.PhoneNumber;
            //.NET returned empty Guid from JSON request
            //TO DO : Use Automapper

            phonebookEntryRepository.Add(phonebookEntry);
            await phonebookEntryRepository.Commit();

            return(Ok());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutEntry(Guid phonebookId, [FromBody] PhonebookEntryDTO entry)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var phonebook = await phonebookRepository.GetById(phonebookId);

            if (phonebook == null)
            {
                NotFound();
            }
            var phonebookEntry = PhonebookEntryFactory.Create(phonebook);

            entry.SetIds(phonebookEntry);
            phonebookEntry.Name        = entry.Name;
            phonebookEntry.PhoneNumber = entry.PhoneNumber;
            phonebookEntryRepository.Update(phonebookEntry);
            await phonebookEntryRepository.Commit();

            return(Ok());
        }