public async Task <UseCaseResult <bool> > Handle(DeleteBusinessService request, CancellationToken cancellationToken) { try { if (request.Id == Guid.Empty) { var businessService = _repository.All().Where(s => s.Name == request.Name).SingleOrDefault(); if (businessService != null) { request.Id = businessService.Id; } } if (request.Id == Guid.Empty) { throw new ArgumentNullException($"Request Id is null"); } return(new UseCaseResult <bool> { ResultCode = "Ok", ResultText = "DeleteBusinessServiceUseCase", Data = await _repository.DeleteAsync(new BusinessService { Id = request.Id }) }); } catch (Exception e) { return(new UseCaseResult <bool> { ResultCode = "Error", ResultText = e.Message, Data = false }); } }
public async Task <UseCaseResult <Models.BusinessServiceModel> > Handle(UpdateBusinessService request, CancellationToken cancellationToken) { try { if (_repository.All().Where(s => s.Name == request.Name).Any()) { throw new ArgumentException($"Request.Name {request.Name} is in use."); } return(new UseCaseResult <Models.BusinessServiceModel> { ResultCode = "Ok", ResultText = "UpdateBusinessService", Data = _mapper.Map <Models.BusinessServiceModel>(await _repository.UpdateAsync(new Domain.Entities.BusinessService { Id = request.Id, Name = request.Name })) }); } catch (Exception e) { return(new UseCaseResult <Models.BusinessServiceModel> { 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 <IEnumerable <BusinessServiceModel> > > Handle(GetBusinessServicesList request, CancellationToken cancellationToken) { try { return(await Task.Run(() => { return new UseCaseResult <IEnumerable <BusinessServiceModel> > { ResultCode = "Ok", ResultText = "GetBusinessSevices", Data = _mapper.Map <List <BusinessServiceModel> >(_repository.All().ToList()) }; })); } catch (Exception e) { return(new UseCaseResult <IEnumerable <BusinessServiceModel> > { ResultCode = "Error", ResultText = e.Message }); } }
public async Task <UseCaseResult <IEnumerable <BusinessServiceCategoryModel> > > Handle(GetBusinessServiceCategoriesList request, CancellationToken cancellationToken) { try { return(await Task.Run(() => { //var services = _businessRepository.All().GroupBy(b => b.BusinessServices.GroupBy(s => s.CategoryName).Select(s => s.Key)).ToList(); var query = _businessServiceRepository.All() .GroupBy(s => s.CategoryName) .Select(g => new BusinessServiceCategoryModel { Name = g.Key, CountOfServices = g.Count(), //CountOfBusinesses = _businessRepository.All().Where(b=>b.BusinessServices.Any(ss=>ss.CategoryName==g.Key)).Count() //CountOfBusinesses = services.Where(s=>s.Key.Where(p=>p.)) }); if (request.Top10) { query = query.Take(10); } return new UseCaseResult <IEnumerable <BusinessServiceCategoryModel> > { ResultCode = "Ok", ResultText = "GetBusinessSeviceCategories", Data = query.ToList() }; })); } catch (Exception e) { return(new UseCaseResult <IEnumerable <BusinessServiceCategoryModel> > { ResultCode = "Error", ResultText = e.Message }); } }
public int Resolve(BusinessServiceCategory source, BusinessServiceCategoryModel destination, int destMember, ResolutionContext context) { return(_businessServiceRepository.All().Where(s => s.CategoryName == source.Name).Count()); }
public string Resolve(BusinessServiceCategory source, BusinessServiceCategoryModel destination, string destMember, ResolutionContext context) { var services = _businessServiceRepository.All().Where(s => s.CategoryName == source.Name).Take(3).Select(s => s.Name).ToList(); return($"{string.Join(", ", services) }..."); }
public IEnumerable <BusinessServiceModel> Resolve(BusinessServiceCategory source, BusinessServiceCategoryModel destination, IEnumerable <BusinessServiceModel> destMember, ResolutionContext context) { return(_mapper.Map <IEnumerable <BusinessServiceModel> >(_businessServiceRepository.All().Where(s => s.CategoryName == source.Name).ToList())); }