Пример #1
0
        public async Task <IMerchantsSupervisorMembership> GetWithMerchantsAsync(string employeeId)
        {
            ISupervisorMembership membership = await _supervisorMembershipRepository.GetAsync(employeeId);

            if (membership != null)
            {
                var merchants = new List <string>();

                foreach (string merchantGroupId in membership.MerchantGroups)
                {
                    MerchantGroupResponse merchantGroup = await _payMerchantClient.Groups.GetGroupAsync(merchantGroupId);

                    if (merchantGroup != null)
                    {
                        merchants.AddRange(merchantGroup.Merchants);
                    }
                }

                return(new MerchantsSupervisorMembership
                {
                    MerchantId = membership.MerchantId,
                    EmployeeId = membership.EmployeeId,
                    Merchants = merchants.Distinct()
                });
            }

            return(null);
        }
Пример #2
0
        public async Task <IMerchantsSupervisorMembership> AddAsync(IMerchantsSupervisorMembership src)
        {
            MerchantGroupResponse merchantGroup =
                await _payMerchantClient.Groups.AddGroupAsync(Mapper.Map <AddMerchantGroupRequest>(src));

            try
            {
                ISupervisorMembership membership = await _supervisorMembershipRepository.AddAsync(
                    new SupervisorMembership
                {
                    MerchantId     = src.MerchantId,
                    EmployeeId     = src.EmployeeId,
                    MerchantGroups = new[] { merchantGroup.Id }
                });

                return(new MerchantsSupervisorMembership
                {
                    MerchantId = membership.MerchantId,
                    EmployeeId = membership.EmployeeId,
                    Merchants = merchantGroup.Merchants
                });
            }
            catch (DuplicateKeyException ex)
            {
                _log.ErrorWithDetails(ex, src);

                if (merchantGroup != null)
                {
                    await _payMerchantClient.Groups.DeleteGroupAsync(merchantGroup.Id);
                }

                throw new SupervisorMembershipAlreadyExistsException(src.EmployeeId);
            }
        }
            public static SupervisorMembershipEntity Create(ISupervisorMembership src)
            {
                var entity = new SupervisorMembershipEntity
                {
                    PartitionKey = GeneratePartitionKey(src.MerchantId),
                    RowKey       = GenerateRowKey(src.EmployeeId)
                };

                return(Mapper.Map(src, entity));
            }
        public async Task <ISupervisorMembership> AddAsync(ISupervisorMembership src)
        {
            SupervisorMembershipEntity entity = SupervisorMembershipEntity.ByMerchant.Create(src);

            await _tableStorage.InsertThrowConflict(entity);

            AzureIndex index = SupervisorMembershipEntity.IndexByEmployee.Create(entity);

            await _employeeIndexStorage.InsertThrowConflict(index);

            return(Mapper.Map <Core.Domain.SupervisorMembership.SupervisorMembership>(entity));
        }
Пример #5
0
        public async Task <ISupervisorMembership> AddAsync(ISupervisorMembership src)
        {
            try
            {
                return(await _supervisorMembershipRepository.AddAsync(src));
            }
            catch (DuplicateKeyException ex)
            {
                _log.ErrorWithDetails(ex, src);

                throw new SupervisorMembershipAlreadyExistsException(src.EmployeeId);
            }
        }
Пример #6
0
        public async Task UpdateAsync(ISupervisorMembership src)
        {
            try
            {
                await _supervisorMembershipRepository.UpdateAsync(src);
            }
            catch (KeyNotFoundException ex)
            {
                _log.ErrorWithDetails(ex, src);

                throw new SupervisorMembershipNotFoundException(src.EmployeeId);
            }
        }
Пример #7
0
        public async Task <IActionResult> Add([FromBody] AddSupervisorMembershipModel request)
        {
            try
            {
                ISupervisorMembership membership =
                    await _supervisorMembershipService.AddAsync(Mapper.Map <SupervisorMembership>(request));

                return(Ok(Mapper.Map <SupervisorMembershipResponse>(membership)));
            }
            catch (SupervisorMembershipAlreadyExistsException e)
            {
                _log.ErrorWithDetails(e, new { e.EmployeeId });

                return(BadRequest(ErrorResponse.Create(e.Message)));
            }
        }
Пример #8
0
        public async Task <IActionResult> Get(string employeeId)
        {
            try
            {
                ISupervisorMembership membership =
                    await _supervisorMembershipService.GetAsync(Uri.UnescapeDataString(employeeId));

                return(Ok(Mapper.Map <SupervisorMembershipResponse>(membership)));
            }
            catch (InvalidRowKeyValueException e)
            {
                _log.ErrorWithDetails(e, new
                {
                    e.Variable,
                    e.Value
                });

                return(NotFound(ErrorResponse.Create("Employee not found")));
            }
        }
        public async Task UpdateAsync(ISupervisorMembership src)
        {
            SupervisorMembershipEntity updatedEntity = await _tableStorage.MergeAsync(
                SupervisorMembershipEntity.ByMerchant.GeneratePartitionKey(src.MerchantId),
                SupervisorMembershipEntity.ByMerchant.GenerateRowKey(src.EmployeeId),
                entity =>
            {
                if (src.MerchantGroups.Any())
                {
                    entity.MerchantGroups = string.Join(Constants.Separator, src.MerchantGroups);
                }

                return(entity);
            });

            if (updatedEntity == null)
            {
                throw new KeyNotFoundException();
            }
        }