Ejemplo n.º 1
0
        /// <summary>
        /// Store or update ticket entity in table storage.
        /// </summary>
        /// <param name="expert">Represents expert entity used for storage and retrieval.</param>
        /// <returns><see cref="Task"/> that represents configuration entity is saved or updated.</returns>
        public Task UpserExpertAsync(ExpertEntity expert)
        {
            expert.PartitionKey = PartitionKey;
            expert.RowKey       = expert.ID;

            return(this.StoreOrUpdateExpertEntityAsync(expert));
        }
Ejemplo n.º 2
0
        internal static Expert Read(this ExpertEntity entity, ReadConversionCollector collector)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            if (collector == null)
            {
                throw new ArgumentNullException(nameof(collector));
            }

            if (collector.Contains(entity))
            {
                return(collector.Get(entity));
            }

            var person = entity.PersonEntity.Read(collector);
            var expert = new Expert
            {
                Name         = person.Name,
                Email        = person.Email,
                Telephone    = person.Telephone,
                Expertise    = entity.Expertise,
                Organisation = entity.Organisation
            };

            collector.Collect(entity, expert);
            return(expert);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Store or update ticket entity in table storage.
        /// </summary>
        /// <param name="expert">Represents expert entity used for storage and retrieval.</param>
        /// <returns><see cref="Task"/> that represents configuration entity is saved or updated.</returns>
        private async Task <TableResult> StoreOrUpdateExpertEntityAsync(ExpertEntity expert)
        {
            await this.EnsureInitializedAsync().ConfigureAwait(false);

            TableOperation addOrUpdateOperation = TableOperation.InsertOrReplace(expert);

            return(await this.expertCloudTable.ExecuteAsync(addOrUpdateOperation).ConfigureAwait(false));
        }
Ejemplo n.º 4
0
        public static async Task SendEmailAsync(AppointmentEntity appointment, ExpertEntity expert)
        {
            var emailMessage = BuildEmailMessageFor(appointment, expert);
            var queueClient  = new QueueClient(Environment.GetEnvironmentVariable("SERVICE_BUS_CONNECTION_STRING"), "email");
            var message      = new Message(Encoding.UTF8.GetBytes(JsonSerializer.Serialize <EmailMessage>(emailMessage)));
            await queueClient.SendAsync(message);

            await queueClient.CloseAsync();
        }
Ejemplo n.º 5
0
        internal static ExpertEntity Create(this Expert model, PersistenceRegistry registry)
        {
            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }

            if (registry.Contains(model))
            {
                return(registry.Get(model));
            }

            var entity = new ExpertEntity
            {
                PersonEntity = ((Person)model).Create(registry),
                Expertise    = model.Expertise.DeepClone(),
                Organisation = model.Organisation.DeepClone()
            };

            registry.Register(model, entity);

            return(entity);
        }
 internal Expert Get(ExpertEntity entity)
 {
     return(Get(experts, entity));
 }
 internal bool Contains(ExpertEntity entity)
 {
     return(Contains(experts, entity));
 }
 internal void Collect(ExpertEntity entity, Expert model)
 {
     Collect(experts, entity, model);
 }
Ejemplo n.º 9
0
 internal void Register(Expert model, ExpertEntity entity)
 {
     Register(experts, model, entity);
 }
Ejemplo n.º 10
0
        private static EmailMessage BuildEmailMessageFor(AppointmentEntity appointment, ExpertEntity expert)
        {
            var template = string.Empty;
            var toAddr   = string.Empty;
            var link     = string.Empty;

            if (appointment.Status == "requested")
            {
                template = "request";
                toAddr   = expert.Email;
                link     = $"https://{Environment.GetEnvironmentVariable("BACKEND_HOSTNAME")}/site/scheduler/{expert.Handle}/{appointment.Repo}";
            }
            else if (appointment.Status == "accepted")
            {
                template = "confirmation";
                toAddr   = appointment.Requestor;
                link     = $"https://{Environment.GetEnvironmentVariable("BACKEND_HOSTNAME")}/site/videocall/{appointment.Id}";
            }

            /* TODO template conversions for 'completed' and 'rejected' */

            var placeholders = new Dictionary <string, string>();

            placeholders.Add("name", appointment.Requestor);
            placeholders.Add("date", appointment.DateTime.ToString("dddd, MMMM dd yyyy"));
            placeholders.Add("time", appointment.DateTime.ToString("h:mm tt"));
            placeholders.Add("repo name here", appointment.Repo);
            placeholders.Add("link", link);
            return(new EmailMessage
            {
                To = toAddr,
                Template = template,
                Placeholders = placeholders,
            });
        }