public async Task HandleAsync(BusinessCreated message, IRequestInfo requestInfo) { var business = new Business().Create(message.Id); await _repository.AddAsync(business); _logger.LogInformation("Business added to Site Service with id:" + business.Id); }
public async Task <UseCaseResult <UserModel> > Handle(CreateUser request, CancellationToken cancellationToken) { try { var user = await _userService.CreateUserAsync( new OvertureUser { Email = request.Email, AccountType = request.AccountType }, request.Password); if (request.AccountType == AccountType.Business) { // create the business profile record await _businessRepository.AddAsync(new Business { UserId = user.UserId, IsTrading = false }); } return(new UseCaseResult <UserModel> { ResultCode = "Ok", ResultText = "CreateUser", Data = _mapper.Map <UserModel>(user), }); } catch (Exception e) { return(new UseCaseResult <UserModel> { ResultCode = "Error", ResultText = e.Message, Data = null }); } }
public async Task <UseCaseResult <BusinessModel> > Handle(CreateBusiness request, CancellationToken cancellationToken) { try { return(new UseCaseResult <BusinessModel> { ResultCode = "Ok", ResultText = "CreateBusiness", Data = _mapper.Map <BusinessModel>(await _repository.AddAsync(new Business { Name = request.Name, Owner = request.Owner, Description = request.Description, BusinessServices = _businessServiceRepository.All().Where(s => request.Services.Contains(s.Name)).ToList() })) }); } catch (Exception e) { return(new UseCaseResult <BusinessModel> { ResultCode = "Error", ResultText = e.Message, Data = null }); } }
private async Task <int> PopulateSampleBusinesses(InitializeData request) { var counter = 0; if (request.PopulateSampleBusinesses) { var csv = GetEmbeddedResourceAsString("Overture.Core.Domain.InitialData.sample_businesses.csv"); using (var reader = new CsvReader(new StringReader(csv))) { while (reader.Read()) { var record = reader.GetRecord <dynamic>(); var services = new List <BusinessService>(); foreach (var service in ((string[])record.BusinessServices.Split("|")).ToList()) { var found = _businessServiceRepository.All().Where(s => s.Name == service).FirstOrDefault(); if (found != null) { services.Add(found); } } var areas = new List <ServiceArea>(); foreach (var area in ((string[])record.ServiceAreas.Split("|")).ToList()) { if (!string.IsNullOrEmpty(area)) { areas.Add(new ServiceArea { Name = area }); } } string name = record.Name.ToString().TrimEnd(Environment.NewLine.ToCharArray()); await _businessRepository.AddAsync(new Business { Name = name, //AltReference = name.ToLower().Replace(" ", "-"), AltReference = Regex.Replace(name.ToLower(), @"[^A-Za-z0-9_\.~]+", "-"), Owner = record.Owner, Tagline = record.Tagline, Description = record.Description, IsTrading = true, Address = new Address(), ContactMethods = new List <ContactMethod>(), BusinessServices = services, ServiceAreas = areas, StoredFiles = new List <StoredFile>() }); counter++; } } } return(counter); }
public async Task <UseCaseResult <BusinessModel> > Handle(UpdateBusiness request, CancellationToken cancellationToken) { try { var business = _repository.All().Where(b => b.Id == request.Id).SingleOrDefault(); if (business == null) { business = new Business(); business.UserId = request.Context.UserId; } business.Name = request.Name; //business.AltReference = request.Name.ToLower()..Replace(" ", "-"); business.AltReference = Regex.Replace(request.Name.ToLower(), @"[^A-Za-z0-9_\.~]+", "-"); business.Owner = request.Owner; business.Tagline = request.Tagline; business.Description = request.Description; business.Picture = request.Picture; business.IsTrading = request.IsTrading; business.Address = request.Address; business.ServiceAreas = request.ServiceAreas; business.BusinessServices = request.BusinessServices; business.ContactMethods = request.ContactMethods; business.StoredFiles = request.StoredFiles; if (business.Id == Guid.Empty) { await _repository.AddAsync(business); return(UseCaseResult <BusinessModel> .Create(_mapper.Map <BusinessModel>(business), resultText : "Update Business")); } else { await _repository.UpdateAsync(business); return(UseCaseResult <BusinessModel> .Create(_mapper.Map <BusinessModel>(business), resultText : "Update Business")); } } catch (Exception e) { return(UseCaseResult <BusinessModel> .CreateError(resultText : e.Message)); } }