コード例 #1
0
        public IActionResult UpdateContact(Guid id, [FromBody] ContactPutDto contact)
        {
            if (contact == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var originalContact = contactService.GetContact(id);

            if (originalContact == null)
            {
                return(NotFound());
            }

            if (originalContact.Id != contact.Id)
            {
                return(BadRequest());
            }

            mapper.Map(contact, originalContact);

            contactService.UpdateContact(originalContact);
            return(NoContent());
        }
コード例 #2
0
        public async Task <bool> UpdateAsync(ContactPutDto entity)
        {
            ContactPutDtoValidator validator = new ContactPutDtoValidator();
            ValidationResult       results   = validator.Validate(entity);

            if (!results.IsValid)
            {
                throw new ValidationException("ContactPutDTO", string.Join(". ", results.Errors));
            }

            var exists = await userRoleRepository.GetByIdAsync(entity.User1ID, entity.User2ID);

            if (exists == null)
            {
                return(false);
            }

            await userRoleRepository.UpdateAsync(mapper.Map <Contact>(entity));

            return(true);
        }
コード例 #3
0
        public async Task <IActionResult> Edit([FromQuery] Guid user1Id, [FromQuery] Guid user2Id, [FromBody] ContactPutDto contactPutDto)
        {
            if (user1Id != contactPutDto.User1ID || user2Id != contactPutDto.User2ID)
            {
                return(BadRequest());
            }

            await contactService.UpdateAsync(contactPutDto);

            return(NoContent());
        }