public async Task <ActionResult <ContactListDto> > CreateListAsync([FromBody] AddContactListDto contactDto)
        {
            var result = await _contactsAppService.CreateContactListAsync(contactDto);

            if (!result.Ok)
            {
                return(BadRequest(result));
            }
            return(result.Data);
        }
示例#2
0
        public async Task <EntityResponse <ContactListDto> > CreateContactListAsync(AddContactListDto newContactListDto)
        {
            var result = ModelValidator.ValidateAsEntityValidation(newContactListDto, "E0002").As <ContactListDto>();

            if (!result.Ok)
            {
                return(result);
            }

            List <Contact> contacts = await _contactRepository.AsQueryable().Where(e => newContactListDto.ContactIds.Contains(e.Id)).ToListAsync();

            ContactList list = new ContactList
            {
                Name     = newContactListDto.Name,
                Contacts = contacts
            };

            await unitOfWork.GetRepository <ContactList>().AddAsync(list);

            await unitOfWork.SaveChangesAsync();

            return(EntityResponse.CreateOk().As(mapper.Map <ContactListDto>(list)));
        }