예제 #1
0
        public async Task <IActionResult> SetSystemSettings([FromBody] AgentAccommodationBookingSettingsInfo settings, [FromRoute] int agentId,
                                                            [FromRoute] int agencyId)
        {
            var(_, isFailure, error) = await _systemSettingsManagementService.SetAvailabilitySearchSettings(agentId, agencyId, settings);

            if (isFailure)
            {
                return(BadRequest(ProblemDetailsBuilder.Build(error)));
            }

            return(Ok());
        }
예제 #2
0
 public AgentSystemSettingsCreateOrEditEventData(int agentId, int agencyId, AgentAccommodationBookingSettingsInfo newSettings)
 {
     AgentId     = agentId;
     AgencyId    = agencyId;
     NewSettings = newSettings;
 }
예제 #3
0
 public static AgentAccommodationBookingSettings ToAgentAccommodationBookingSettings(this AgentAccommodationBookingSettingsInfo settings)
 => new ()
        public Task <Result> SetAvailabilitySearchSettings(int agentId, int agencyId, AgentAccommodationBookingSettingsInfo settings)
        {
            return(CheckRelationExists(agentId, agencyId)
                   .BindWithTransaction(_context, () => Result.Success()
                                        .Map(() => GetOrDefault(agentId, agencyId))
                                        .Tap(Update)
                                        .Bind(WriteAuditLog)));


            Task Update(AgentSystemSettings existingSettings)
            {
                if (existingSettings is null)
                {
                    var newSettings = new AgentSystemSettings
                    {
                        AgencyId = agencyId,
                        AgentId  = agentId,
                        AccommodationBookingSettings = settings.ToAgentAccommodationBookingSettings()
                    };
                    _context.Add(newSettings);
                }
                else
                {
                    existingSettings.AccommodationBookingSettings = settings.ToAgentAccommodationBookingSettings();
                    _context.Update(existingSettings);
                }

                return(_context.SaveChangesAsync());
            }

            Task <Result> WriteAuditLog(AgentSystemSettings _)
            => _managementAuditService.Write(ManagementEventType.AgentSystemSettingsCreateOrEdit,
                                             new AgentSystemSettingsCreateOrEditEventData(agentId, agencyId, settings));
        }