Ejemplo n.º 1
0
        public async Task <IActionResult> CreateRecord([FromBody] SaveRecordResource saveRecordResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var record = mapper.Map <SaveRecordResource, Record>(saveRecordResource);

            record.LastUpdate = DateTime.Now;

            repository.Add(record);

            await unitOfWork.CompleteAsync();

            return(Ok());
        }
Ejemplo n.º 2
0
        public void CreateOrUpdatePhoneBook(Domain.Models.PhoneBook phoneBook)
        {
            var existingPhoneBook = GetPhoneBookById(phoneBook.Id);

            if (existingPhoneBook == null)
            {
                _phoneBookRepository.Add(phoneBook);
            }
            else
            {
                _phoneBookRepository.Detach(existingPhoneBook);
                existingPhoneBook.Name    = phoneBook.Name;
                existingPhoneBook.Entries = phoneBook.Entries;
                _phoneBookRepository.Edit(existingPhoneBook);
            }

            _phoneBookRepository.Save();
        }
Ejemplo n.º 3
0
        public PhoneBookDTO SaveEntry(PhoneBookDTO dto)
        {
            PhoneBook phoneBook = dto.ToEntity();

            if (phoneBook.id != 0)
            {
                var book = repo.FindByID(phoneBook.id);
                if (book != null)
                {
                    repo.Update(phoneBook);
                    return(phoneBook.ToDTO());
                }
            }
            var entity = repo.Add(phoneBook);

            KafkaMessage message = new KafkaMessage("phonebookCreated", JsonConvert.SerializeObject(entity.ToDTO()));

            producer.PublishAsync("phonebook-incoming", message);

            return(entity.ToDTO());
        }
Ejemplo n.º 4
0
        public int Add(PhoneBookModel model)
        {
            var phoneBook = ToData.ToPhoneBookData(model);

            return(_phoneBookRepo.Add(phoneBook, _context).Id);
        }