public static ARContact ToARContactEntity(this CreateContactDto dto, int?userId)
 {
     return(new ARContact
     {
         ARContactContributor = dto.Contributor,
         ARContactTitleContribute = dto.TitleContribute,
         FK_ARContactTypeID = dto.ContactTypeID,
         ARContactName = dto.ContactName,
         ARContactAcronymName = dto.AcronymName,
         ARContactUserContact = dto.UserContact,
         ARContactPhone1 = dto.Phone1,
         ARContactPhone2 = dto.Phone2,
         ARContactEmail = dto.Email,
         ARContactWebsite = dto.Website,
         ARContactNote = dto.Note,
         ARContactImage = dto.Images.JoinNotEmpty(";"),
         FK_GEStateProvinceID = dto.StateProvinceID,
         FK_GEDistrictID = dto.DistrictID,
         FK_GECommuneID = dto.CommuneID,
         ARUserHouseNumber = dto.HouseNumber,
         ARUserAddress = dto.Address,
         ARContactStatus = ContactStatus.ChuaDuyet,
         FK_CreatedUserID = userId
     });
 }
Beispiel #2
0
 public async Task <IActionResult> PostContact([FromBody] CreateContactDto contact)
 {
     if (ModelState.IsValid)
     {
         return(buildResponse(await _service.CreateContact(contact)));
     }
     return(null);
 }
        public async Task <ClientResponse <ContactDto> > CreateContact(CreateContactDto contactDto)
        {
            var response = new ClientResponse <ContactDto>();

            try
            {
                if (contactDto.BirthDate > DateTime.Now)
                {
                    response.Message = E.ErrHigherBirthDate;
                    response.Status  = System.Net.HttpStatusCode.BadRequest;
                    return(response);
                }
                if (await validateContactNotExists(contactDto.Email, contactDto.Name))
                {
                    response.Message = E.ErrContactAlreadyExists;
                    response.Status  = System.Net.HttpStatusCode.BadRequest;
                    return(response);
                }
                if (await validateCityAndCompany(contactDto.CityID, contactDto.CompanyID))
                {
                    var contact = new Mo.Contact
                    {
                        Name         = H.UppercaseFirst(contactDto.Name),
                        BirthDate    = contactDto.BirthDate,
                        StreetName   = H.UppercaseFirst(contactDto.StreetName),
                        StreetNumber = contactDto.StreetNumber,
                        CompanyID    = contactDto.CompanyID,
                        CityID       = contactDto.CityID,
                        ProfileImage = contactDto.ProfileImage,
                        Email        = contactDto.Email.ToLower(),
                        Phones       = new List <Mo.Phone>(),
                        Active       = true
                    };

                    contact.CreatedAt = DateTime.Now;
                    foreach (PhoneDto p in contactDto.Phones)
                    {
                        contact.Phones.Add(_mapper.Map <Mo.Phone>(p));
                    }
                    _repository.Contacts.Add(contact);

                    await _repository.SaveChangesAsync();

                    return(await GetContactById(contact.ID));
                }
                response.Message = E.ErrGeneric;
                response.Status  = System.Net.HttpStatusCode.InternalServerError;
                return(response);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Status  = System.Net.HttpStatusCode.InternalServerError;
                return(response);
            }
        }
Beispiel #4
0
        public async Task <ContactResultDto> CreateAsync(CreateContactDto model)
        {
            var entity = await _factory.MakeAsync(model);

            await _repository.AddAndSaveAsync(entity);

            var result = entity.Adapt <ContactResultDto>();

            return(await Task.FromResult(result));
        }
        public async Task <IActionResult> CreateAsync([FromBody] CreateContactDto request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            await _contactService.CreateAsync(request);

            return(ApiResponseOk());
        }
Beispiel #6
0
        public async Task <Contact> MakeAsync(CreateContactDto model)
        {
            model.CheckArgumentIsNull(nameof(model));
            var result = model.Adapt <Contact>();

            result.WebsiteId = _websiteInfo.Id;
            result.Ip        = AppHttpContext.IpAddress; //AppHttpContext.Current.Connection.RemoteIpAddress?.ToString();
            result.UserAgent = AppHttpContext.UserAgent; //AppHttpContext.Request.Headers["User-Agent"][0];
            result.SessionId = AppHttpContext.SessionId; //AppHttpContext.Current.Session.Id;
            result.SentDate  = _dateService.UtcNow();
            result.Status    = ContactMessageStatus.Sent;

            return(await Task.FromResult(result));
        }
        public async Task <ServiceResponse <List <GetContactDto> > > CreateContact(CreateContactDto newContact)
        {
            ServiceResponse <List <GetContactDto> > serviceResponse = new ServiceResponse <List <GetContactDto> >();
            Contact record = _mapper.Map <Contact>(newContact);

            record.UserId = GetUserId();// = await _context.Users.FirstOrDefaultAsync(u => u.Id == GetUserId());

            await _context.Contacts.AddAsync(record);

            await _context.SaveChangesAsync();

            serviceResponse.Data = await GetAllRecords();

            return(serviceResponse);
        }
Beispiel #8
0
        public async Task CreateAsync(CreateContactDto dto)
        {
            Contact existingContact = await _contactRepository.FindByNameOrAddressAsync(dto.Name, dto.Address);

            if (existingContact != null)
            {
                if (existingContact.Name.ToUpper() == dto.Name.ToUpper())
                {
                    throw new BusinessException("Contact already exist with name " + dto.Name);
                }

                if (existingContact.Address.ToUpper() == dto.Address.ToUpper())
                {
                    throw new BusinessException("Contact already exist with address " + dto.Address);
                }
            }

            var contact = Map <CreateContactDto, Contact>(dto);
            await _contactRepository.CreateAsync(contact);
        }
        public async Task <ActionResult <ContactDto> > PostAsync(CreateContactDto createContactDto)
        {
            var contact = new Contact
            {
                First     = createContactDto.first,
                Middle    = createContactDto.middle,
                Last      = createContactDto.last,
                Addresses = createContactDto.address,
                Phones    = new List <Phone> {
                    createContactDto.phone
                },
                Email = createContactDto.email
            };

            await contactsRepository.Insert(contact);

            return(CreatedAtAction(nameof(GetByIdAsync), new
            {
                id = contact.Id
            }, contact));
        }
Beispiel #10
0
        public async Task <ActionResult <ContactDto> > CreateContact(int userId, CreateContactDto createContactDto)
        {
            var contact = new Contact
            {
                Email             = createContactDto.Email,
                Name              = createContactDto.Name,
                PhotoId           = createContactDto.PhotoId,
                TelephoneNumber   = createContactDto.TelephoneNumber,
                Uri               = createContactDto.Uri,
                UseEmergencyCall  = createContactDto.UseEmergencyCall,
                UseEmergencyEmail = createContactDto.UseEmergencyEmail,
                UseEmergencySms   = createContactDto.UseEmergencySms,
                User              = await _unitOfWork.UserRepository.GetUserByIdAsync(userId)
            };

            _unitOfWork.ContactRepository.AddItem(contact);
            if (await _unitOfWork.Complete())
            {
                return(Ok(_mapper.Map <ContactDto>(contact)));
            }

            return(BadRequest("Unable to create Contact"));
        }
Beispiel #11
0
        public async Task <ContactDto> CreateContactAsync(CreateContactDto dto)
        {
            if (!await ValidateLocationInCharges(dto.LocationInCharges))
            {
                throw new BusinessException("Giá trị không hợp lệ.");
            }

            var contactToCreate = dto.ToARContactEntity(_bysSession.GetUserId());
            var contact         = await _unitOfWork.GetRepository <ARContact>().InsertAsync(contactToCreate);

            foreach (var locationInCharge in dto.LocationInCharges)
            {
                await _unitOfWork.GetRepository <ARContactForestCommuneGroup>()
                .InsertAsync(
                    new ARContactForestCommuneGroup
                {
                    FK_ARContactID       = contact.Id,
                    FK_GECommuneID       = locationInCharge.ForestCommuneID,
                    FK_GEStateProvinceID = locationInCharge.ForestStateProvinceID,
                    FK_GEDistrictID      = locationInCharge.ForestDistrictID
                });
            }

            await _unitOfWork.CompleteAsync();

            await _notificationService.CreateNotificationAsync(
                new CreateNotificationDto
            {
                UserId                 = _bysSession.UserId,
                NotificationType       = NotificationType.AddedContact,
                NotificationObjectType = "ARContacts",
                NotificationObjectId   = contact.Id,
                NotificationContent    = _unitOfWork.GetRepository <ADUser>().Get(_bysSession.UserId)?.ADUserOrganizationName + " đã đóng góp 1 liên hệ " + dto.ContactName
            });

            return(await GetContactAsync(contact.Id));
        }
Beispiel #12
0
        public async Task <IActionResult> Create([FromBody] CreateContactDto dto)
        {
            var result = await _contactService.CreateContactAsync(dto);

            return(Success(result));
        }
Beispiel #13
0
 public async Task <IActionResult> CreateContact(CreateContactDto newContact)
 {
     return(Ok(await _ContactService.CreateContact(newContact)));
 }