public async Task <ActionResult <Contact> > Create([FromBody] Contact value)
 {
     try
     {
         return(StatusCode(StatusCodes.Status201Created, await repository.AddAsync(value)));
     }
     catch (Exception e)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, new { Message = $"There was an error when writing the contact to the server. {e.Message}" }));
     }
 }
Exemple #2
0
        public async Task <int> AddAsync(ContactSaveViewModel contactViewModel)
        {
            var currentUserId = int.Parse(_authClaimsService.GetUserId());

            var contactEntity = new Contact()
            {
                Firstname         = contactViewModel.Firstname,
                Lastname          = contactViewModel.Lastname,
                Address           = contactViewModel.Address,
                Email             = contactViewModel.Email,
                MobilePhoneNumber = contactViewModel.MobilePhoneNumber,
                UserId            = currentUserId
            };

            return(await _contactsRepository.AddAsync(contactEntity));
        }
Exemple #3
0
        public async Task AddToContacts(string userId, string callerId)
        {
            if (userId == callerId)
            {
                throw new InvalidDataException("Can't add yourself to contacts.");
            }

            try
            {
                await contactsRepository.AddAsync(ContactsDataModel.Create(callerId, userId));

                await unitOfWork.Commit();
            }
            catch (Exception ex)
            {
                throw new InvalidDataException("Wrong caller id or user id", ex);
            }
        }
Exemple #4
0
        public async Task <IActionResult> Post([FromBody] Contact contact)
        {
            await _contactsRepository.AddAsync(contact);

            return(CreatedAtRoute("GetContacts", new { Controller = "Contacts", id = contact.MobilePhone }, contact));
        }