Esempio n. 1
0
        public IQueryable <ContactApiModel> Search(Guid communityId)
        {
            var contacts = _contactService.SearchContacts(communityId)
                           .Select(e => _contactMapper.Map(e));

            return(contacts);
        }
Esempio n. 2
0
        public IActionResult Edit(int id)
        {
            var contact   = _contactsService.GetById(id).Result;
            var viewModel = _contactMapper.Map(contact);

            viewModel.Heading = "Edit a contact";
            return(PartialView("_ContactForm", viewModel));
        }
Esempio n. 3
0
        /// <summary>
        /// Updates a contact.
        /// </summary>
        /// <param name="contactId">Contact identifier.</param>
        /// <param name="contactResource">New contact information</param>
        /// <returns>Contact information.</returns>
        public async Task <DataResponse <ContactResource> > UpdateAsync(int contactId,
                                                                        SaveContactResource contactResource)
        {
            try
            {
                if (contactResource == null)
                {
                    throw new ArgumentNullException(nameof(contactResource));
                }

                var contact = await _contactRepository.FindByIdAsync(contactId);

                if (contact == null)
                {
                    throw new NotFoundException(nameof(Contact), contactId);
                }

                ContactMapper.Map(contact, contactResource);
                _contactRepository.Update(contact);
                await _unitOfWork.SaveChangesAsync();

                var resource = _mapper.Map <Contact, ContactResource>(contact);
                return(new DataResponse <ContactResource>(resource));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(new DataResponse <ContactResource>(ex.Message));
            }
        }
        public static async Task Run(
            [QueueTrigger("contacts", Connection = "AzureWebJobsStorage")] string contactJson,
            ILogger log,
            ExecutionContext context)
        {
            var logPrefix = GetLogPrefix();

            log.LogInformation($"{logPrefix}: {contactJson}");

            var contactFromFile = JsonConvert.DeserializeObject <FileUploadContact>(contactJson);

            var config = new ConfigurationBuilder()
                         .SetBasePath(context.FunctionAppDirectory)
                         .AddJsonFile("local.settings.json", true, true)
                         .AddEnvironmentVariables()
                         .Build();
            var sqlConnectionString = config.GetConnectionString("Sql");
            var fileUploadContext   = new FileUploadContext(sqlConnectionString);

            var getEmployerQuery = new GetEmployerQuery(fileUploadContext);
            var employerInSql    = await getEmployerQuery.Execute(contactFromFile.CompanyName, contactFromFile.CreatedOnCompany);

            if (employerInSql == null)
            {
                // TODO Employer has to exist
            }

            var getContactQuery = new GetContactQuery(fileUploadContext);
            var contactInSql    = await getContactQuery.Execute(contactFromFile.CompanyName, contactFromFile.CreatedOnCompany);

            var contact = ContactMapper.Map(contactFromFile, contactInSql, employerInSql.Id);

            if (contactInSql == null)
            {
                log.LogInformation($"{logPrefix} Creating Contact: {contactFromFile.Contact}");

                var createEmployerCommand = new CreateContactCommand(fileUploadContext);
                await createEmployerCommand.Execute(contact);

                log.LogInformation($"{logPrefix} Created Contact: {contactFromFile.Contact}");
            }
            else
            {
                var areEqual = contactInSql.Equals(contact);
                if (!areEqual)
                {
                    log.LogInformation($"{logPrefix} Updating Contact: {contactFromFile.Contact}");

                    var updateContactCommand = new UpdateContactCommand(fileUploadContext);
                    await updateContactCommand.Execute(contact);

                    log.LogInformation($"{logPrefix} Updated Contact: {contactFromFile.Contact}");
                }
            }

            log.LogInformation($"{logPrefix} Processed Contact: {contactFromFile.Contact}");
        }
Esempio n. 5
0
        /// <summary>
        /// Updates a reservation.
        /// </summary>
        /// <param name="reservationId">Reservation identifier.</param>
        /// <param name="reservationResource">New reservation information</param>
        /// <returns>Reservation information.</returns>
        public async Task <DataResponse <ReservationResource> > UpdateAsync(int reservationId,
                                                                            SaveReservationResource reservationResource)
        {
            try
            {
                if (reservationResource == null)
                {
                    throw new ArgumentNullException(nameof(reservationResource));
                }

                var reservation = await _reservationRepository.FindByIdAsync(reservationId);

                if (reservation == null)
                {
                    throw new NotFoundException(nameof(Reservation), reservationId);
                }

                var place = await _placeRepository.FindByIdAsync(reservationResource.PlaceId);

                reservation.Place = place
                                    ?? throw new NotFoundException(nameof(Place), reservationResource.PlaceId);

                if (reservationResource.Contact != null)
                {
                    var contact = await _contactRepository.FirstOrDefaultAsync(
                        new ContactsByNameSpec(reservationResource.Contact.Name));

                    if (contact != null)
                    {
                        ContactMapper.Map(contact, reservationResource.Contact);
                        reservation.Contact = contact;
                    }
                    else
                    {
                        reservation.Contact = _mapper.Map <Contact>(reservationResource.Contact);
                    }
                }

                ReservationMapper.Map(reservation, reservationResource);
                _reservationRepository.Update(reservation);
                await _unitOfWork.SaveChangesAsync();

                var resource = _mapper.Map <ReservationResource>(reservation);
                return(new DataResponse <ReservationResource>(resource));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(new DataResponse <ReservationResource>(ex.Message));
            }
        }
Esempio n. 6
0
 public IActionResult CreateEmail(ContactViewModel contact)
 {
     try
     {
         _contact.SendEmail(ContactMapper.Map(contact));
         return(RedirectToAction("Index"));
     }
     catch (Exception)
     {
         ErrorViewModel model = new ErrorViewModel {
             RequestId = "Kunne ikke Sende Email"
         };
         return(View("Error", model));
     }
 }
Esempio n. 7
0
        public ContactContract Process(GetContactRequest input)
        {
            var parameter = new GetContact
            {
                OrganizationId = input.OrganizationId,
                Id             = input.Id
            };

            _query.BuildQuery(parameter);

            using (DapperUnitOfWork.Begin())
            {
                var contact = _runner.Run(_query);

                var result = ContactMapper.Map(contact);

                return(result);
            }
        }
Esempio n. 8
0
        public List <ContactDTO> GetAllContacts(DateTime modifiedOnOrAfter)
        {
            _getMessage?.Invoke("Loading contacts started");
            ContactsController contactController = new ContactsController(_apiKey, _baseURL);

            ListRequestOptions opts = new ListRequestOptions {
                PropertiesToInclude = new List <string> {
                    "firstname", "lastname", "lifecyclestage", "associatedcompanyid"
                }
            };

            opts.Limit      = 100;
            opts.timeOffset = new DateTimeOffset(DateTime.Now).ToUnixTimeMilliseconds();

            List <ContactDTO> contactList = new List <ContactDTO>();

            bool hasMore = true;

            while (hasMore)
            {
                ContactListResponse pageContacts = contactController.GetPageContacts(opts);
                ContactMapper.ToContactList(pageContacts, ref contactList, modifiedOnOrAfter, out hasMore);

                _getMessage?.Invoke($"Loaded {contactList.Count} contacts");

                hasMore = hasMore & pageContacts.HasMore;
                if (hasMore)
                {
                    opts.timeOffset = pageContacts.TimeOffset;
                }
            }

            List <CompanyResponse> companyResponseList = GetAllCompanies(contactList);

            ContactMapper.Map(ref contactList, companyResponseList);

            return(contactList);
        }
 public override ContactContract Map(Contact source)
 {
     return(ContactMapper.Map(source));
 }