/// <summary>
        ///     Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="response">The response.</param>
        protected override void Handle(AddDtoRequest <OrganizationPhoneDto> request, AddDtoResponse <OrganizationPhoneDto> response)
        {
            var organization          = _organizationRepository.GetByKey(UserContext.IsSystemAdmin ? request.AggregateKey : UserContext.OrganizationKey);
            var originalPhone         = organization.OrganizationPhones.FirstOrDefault(p => p.Key == request.DataTransferObject.OriginalHash);
            var organizationPhoneType = Lookup.Find <OrganizationPhoneType>(request.DataTransferObject.OrganizationPhoneType.Code);
            var phone = new Phone(request.DataTransferObject.Phone.Number, request.DataTransferObject.Phone.Extension);

            var organizationPhone = new OrganizationPhone(organizationPhoneType, phone, request.DataTransferObject.IsPrimary);

            if (originalPhone != organizationPhone)
            {
                if (originalPhone != null)
                {
                    organization.RemovePhone(originalPhone);
                }
                organization.AddPhone(organizationPhone);
            }
            else if (organizationPhone.IsPrimary)
            {
                organization.MakePrimary(organizationPhone);
            }

            response.AggregateKey           = organization.Key;
            response.DataTransferObject     = Mapper.Map <OrganizationPhone, OrganizationPhoneDto>(organizationPhone);
            response.DataTransferObject.Key = organization.Key;
        }
 public void UpdateOrganizationPhone(OrganizationPhone data)
 {
     try
     {
         _db.Update(data);
     }
     catch (Exception ex)
     {
         //throw;
     }
 }
        public async Task <bool> AddOrganizationPhone(OrganizationPhone data)
        {
            try
            {
                await _db.AddAsync(data);

                return(true);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public async Task <string> GetAsync()
        {
            List <OrganizationPhone> phoneSummary = new List <OrganizationPhone>();

            APICalls.OrganizationAPI organizationAPI = new APICalls.OrganizationAPI(_logger, _config);

            //Make the 3 api calls.
            List <Model.Organization> organizations = await organizationAPI.GetOrganizationsAsync();

            foreach (var organization in organizations)
            {
                OrganizationPhone summary = new OrganizationPhone();
                summary.Id   = organization.Id;
                summary.Name = organization.Name;

                //Get all users for the organization.
                List <Model.User> users = await organizationAPI.GetUsersAsync(organization.Id);

                foreach (var user in users)
                {
                    List <Model.UserPhone> userPhones = await organizationAPI.GetUserPhonesAsync(organization.Id, user.Id);

                    summary.AddUserSummary(new UserSummary {
                        Id = user.Id, Email = user.Email, PhoneCount = userPhones.Count()
                    });
                    summary.TotalCount     += userPhones.Count();
                    summary.BlacklistTotal += userPhones.Where(p => p.Blacklist).Count();
                }

                phoneSummary.Add(summary);
            }

            //Ensure the output is in json.
            string phoneSummaryString = JsonConvert.SerializeObject(phoneSummary);

            _logger.LogInformation(phoneSummaryString);

            return(phoneSummaryString);
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="OrganizationPhoneRemovedEvent" /> class.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="version">The version.</param>
 /// <param name="organizationPhone">The organization phone.</param>
 public OrganizationPhoneRemovedEvent(Guid key, int version, OrganizationPhone organizationPhone)
     : base(key, version)
 {
     OrganizationPhone = organizationPhone;
 }
 public override V4VmOpenApiPhone TranslateEntityToVm(OrganizationPhone entity)
 {
     return(base.TranslateEntityToVm(entity));
 }
        protected ITranslationDefinitions <OrganizationPhone, TModel> CreateBaseEntityVmDefinitions(OrganizationPhone entity)
        {
            if (entity?.Phone == null)
            {
                return(null);
            }

            return(CreateEntityViewModelDefinition <TModel>(entity)
                   .AddPartial(i => i.Phone));
        }
 public override TModel TranslateEntityToVm(OrganizationPhone entity)
 {
     return(CreateBaseEntityVmDefinitions(entity).GetFinal());
 }