public Task Handle(ServiceCategoryCreatedEvent message) { Console.WriteLine("ServiceCategoryCreatedEvent handled."); // save to ReadDB ServiceCategory serviceCategory = new ServiceCategory( message.Id, message.Name, message.Description, message.AllowOnlineScheduling, message.ScheduleTypeValue, message.SiteId ); //_mapper.Map<LocationRM>(message); try { _serviceCategoryRepository.Add(serviceCategory); _serviceCategoryRepository.SaveChanges(); return(Task.CompletedTask); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.InnerException.Message); throw e; } }
public async Task <ServiceCategoryViewModel> AddServiceCategory(ServiceCategoryViewModel serviceCategory) { var domainServiceCategory = new ServiceCategory( serviceCategory.SiteId, serviceCategory.Name, serviceCategory.Description, serviceCategory.AllowOnlineScheduling, serviceCategory.ScheduleTypeId ); _serviceCategoryRepository.Add(domainServiceCategory); //_session.Add<ServiceCategory>(domainServiceCategory); //_session.Commit(); var serviceCategoryCreatedEvent = new ServiceCategoryCreatedEvent( domainServiceCategory.SiteId, domainServiceCategory.Id, domainServiceCategory.Name, domainServiceCategory.Description, domainServiceCategory.AllowOnlineScheduling, domainServiceCategory.ScheduleTypeId ); await _businessIntegrationEventService.PublishThroughEventBusAsync(serviceCategoryCreatedEvent); serviceCategory.Id = domainServiceCategory.Id; return(serviceCategory); }
public async Task <IActionResult> CreateServiceCategory([FromBody] SaveServiceCategoryResource resource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var serviceCategory = _mapper.Map <SaveServiceCategoryResource, ServiceCategory>(resource); _repository.Add(serviceCategory); await _unitOfWork.CompleteAsync(); var result = _mapper.Map(serviceCategory, resource); return(Ok(result)); }