Exemplo n.º 1
0
 public async Task <UseCaseResult <StoredFileModel> > Handle(UploadFile request, CancellationToken cancellationToken)
 {
     try
     {
         if (!string.IsNullOrEmpty(request.FileName))
         {
             if (request.Contents.Length > 0)
             {
                 return(UseCaseResult <StoredFileModel> .Create(_mapper.Map <IFileProperties, StoredFileModel>(await _fileStoreService.PostAsync(request.FileName, request.Contents, request.ContentType))));
             }
             else
             {
                 return(UseCaseResult <StoredFileModel> .CreateError(resultText : "File Contents are empty"));
             }
         }
         else
         {
             return(UseCaseResult <StoredFileModel> .CreateError(resultText : "No File Name Specified"));
         }
     }
     catch (Exception e)
     {
         return(UseCaseResult <StoredFileModel> .CreateError(resultText : e.Message));
     }
 }
Exemplo n.º 2
0
        public async Task <UseCaseResult <BusinessModel> > Handle(GetBusiness request, CancellationToken cancellationToken)
        {
            try
            {
                var query = _businessRepository.All();
                if (!string.IsNullOrEmpty(request.Name))
                {
                    query = query.Where(b => b.Name == request.Name);
                }
                else if (!string.IsNullOrEmpty(request.AltReference))
                {
                    query = query.Where(b => b.AltReference == request.AltReference);
                }
                else if (!string.IsNullOrEmpty(request.UserId))
                {
                    query = query.Where(b => b.UserId == request.UserId);
                }
                else
                {
                    return(UseCaseResult <BusinessModel> .CreateError(resultText : "No User Id"));
                }

                return(await Task.Run(() =>
                {
                    return UseCaseResult <BusinessModel> .Create(_mapper.Map <BusinessModel>(query.SingleOrDefault()), resultText: "GetBusiness");
                }));
            }
            catch (Exception e)
            {
                return(UseCaseResult <BusinessModel> .CreateError(resultText : e.Message));
            }
        }
Exemplo n.º 3
0
        public async Task <UseCaseResult <IEnumerable <BusinessModel> > > Handle(GetBusinesses request, CancellationToken cancellationToken)
        {
            try
            {
                return(await Task.Run(() =>
                {
                    var query = _businessRepository.All();
                    if (request.Services != null)
                    {
                        query = query.Where(b => b.BusinessServices.Any(s => request.Services.Contains(s.Name) || request.Services.Contains(s.CategoryName)));                        // this works
                    }
                    if (request.Areas != null)
                    {
                        query = query.Where(b => b.ServiceAreas.Any(s => request.Areas.Contains(s.Name)));
                    }
                    if (request.Page.HasValue && request.Size.HasValue)
                    {
                        query = query.Skip(request.Page.Value *request.Size.Value).Take(request.Size.Value);
                    }
                    else
                    {
                        // limit results to 500
                        query.Take(500);
                    }

                    return UseCaseResult <IEnumerable <BusinessModel> > .Create(_mapper.Map <IEnumerable <BusinessModel> >(query.ToList()), resultText: "GetBusinesses");
                }));
            }
            catch (Exception e)
            {
                return(UseCaseResult <IEnumerable <BusinessModel> > .CreateError(resultText : e.Message));
            }
        }
Exemplo n.º 4
0
        public async Task <UseCaseResult <IEnumerable <JobModel> > > Handle(GetJobs request, CancellationToken cancellationToken)
        {
            try
            {
                return(await Task.Run(() =>
                {
                    var query = _jobRepository.All();
                    if (!string.IsNullOrEmpty(request.UserId))
                    {
                        query = query.Where(j => j.UserId == request.UserId);
                    }
                    else if (!string.IsNullOrEmpty(request.BusinessId))
                    {
                        query = query.Where(b => b.Quotes.Any(q => q.QuotedByBusinessId == Guid.Parse(request.BusinessId)));
                    }
                    if (request.Page.HasValue && request.Size.HasValue)
                    {
                        query = query.Skip(request.Page.Value *request.Size.Value).Take(request.Size.Value);
                    }
                    else
                    {
                        // limit results to 500
                        query.Take(500);
                    }

                    return UseCaseResult <IEnumerable <JobModel> > .Create(_mapper.Map <IEnumerable <JobModel> >(query.ToList()), resultText: "GetBusinesses");
                }));
            }
            catch (Exception e)
            {
                _logger.LogError(e, "");
                return(UseCaseResult <IEnumerable <JobModel> > .CreateError(resultText : e.Message));
            }
        }
Exemplo n.º 5
0
        public async Task <UseCaseResult <IEnumerable <ReviewModel> > > Handle(GetReviews request, CancellationToken cancellationToken)
        {
            try
            {
                return(await Task.Run(() =>
                {
                    var query = _reviewRepository.All();
                    if (request.BusinessId != Guid.Empty)
                    {
                        query = query.Where(r => r.BusinessId == request.BusinessId);                       // this works
                    }
                    if (request.Page.HasValue && request.Size.HasValue)
                    {
                        query = query.Skip(request.Page.Value *request.Size.Value).Take(request.Size.Value);
                    }
                    else
                    {
                        // limit results to 500
                        query.Take(500);
                    }

                    return UseCaseResult <IEnumerable <ReviewModel> > .Create(_mapper.Map <IEnumerable <ReviewModel> >(query.ToList()), resultText: "Get Reviews");
                }));
            }
            catch (Exception e)
            {
                return(new UseCaseResult <IEnumerable <ReviewModel> >
                {
                    ResultCode = "Error",
                    ResultText = e.Message,
                    Data = null
                });
            }
        }
Exemplo n.º 6
0
 public async Task <UseCaseResult <IEnumerable <ServiceArea> > > Handle(GetServiceAreas request, CancellationToken cancellationToken)
 {
     try
     {
         return(await Task.Run(() =>
         {
             return UseCaseResult <IEnumerable <ServiceArea> > .Create(_metaInformationService.ServiceAreas, resultText: "Get Service Areas");
         }));
     }
     catch (Exception e)
     {
         return(UseCaseResult <IEnumerable <ServiceArea> > .CreateError(resultText : e.Message));
     }
 }
Exemplo n.º 7
0
 public async Task <UseCaseResult <bool> > Handle(DeleteFile request, CancellationToken cancellationToken)
 {
     try
     {
         if (!string.IsNullOrEmpty(request.FileReference))
         {
             return(UseCaseResult <bool> .Create(await _fileStoreService.DeleteAsync(request.FileReference)));
         }
         else
         {
             return(UseCaseResult <bool> .CreateError(resultText : "File Reference not provided"));
         }
     }
     catch (Exception e)
     {
         return(UseCaseResult <bool> .CreateError(resultText : e.Message));
     }
 }
Exemplo n.º 8
0
        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));
            }
        }
Exemplo n.º 9
0
        public async Task <UseCaseResult <UserModel> > Handle(UpdateUser request, CancellationToken cancellationToken)
        {
            try
            {
                var user = await _userService.GetUserAsync(request.UserId);

                if (user != null)
                {
                    user.Name        = request.Name;
                    user.Picture     = request.Picture;
                    user.AccountType = request.AccountType;
                }

                return(UseCaseResult <UserModel> .Create(_mapper.Map <UserModel>(await _userService.UpdateUserAsync(user))));
            }
            catch (Exception e)
            {
                return(UseCaseResult <UserModel> .CreateError(e.Message));
            }
        }
Exemplo n.º 10
0
        public async Task <UseCaseResult <AuthenticatedUserModel> > Handle(AuthenticateUser request, CancellationToken cancellationToken)
        {
            var result = await _authenticationService.AuthenticateAsync(request.Email, request.Password);

            if (result != null)
            {
                var user = await _userService.GetUserByEmailAsync(request.Email);

                // current signin info
                if (user != null)
                {
                    var model = _mapper.Map <AuthenticatedUserModel>(user);
                    model.AccessToken    = result.AccessToken;
                    model.IdToken        = result.IdToken;
                    model.ExpiresIn      = result.ExpiresIn;
                    model.LastSigninDate = DateTime.UtcNow;
                    return(UseCaseResult <AuthenticatedUserModel> .Create(model));
                }
            }
            return(UseCaseResult <AuthenticatedUserModel> .CreateError());
        }
Exemplo n.º 11
0
        public async Task <UseCaseResult <JobModel> > Handle(GetJob request, CancellationToken cancellationToken)
        {
            try
            {
                return(await Task.Run(() =>
                {
                    var job = _jobRepository.All().Where(j => j.Id == request.Id).SingleOrDefault();

                    if (job != null)
                    {
                        return UseCaseResult <JobModel> .Create(_mapper.Map <JobModel>(job), resultText: "Get Business");
                    }

                    // else
                    throw new Exception("Record not found.");
                }));
            }
            catch (Exception e)
            {
                return(UseCaseResult <JobModel> .CreateError(resultText : e.Message));
            }
        }
Exemplo n.º 12
0
 public async Task <UseCaseResult <DownloadFileModel> > Handle(DownloadFile request, CancellationToken cancellationToken)
 {
     try
     {
         if (!string.IsNullOrEmpty(request.FileReference))
         {
             var props = _fileStoreService.GetProperties(request.FileReference);
             var model = new DownloadFileModel
             {
                 ContentType = props.ContentType,
                 Contents    = await _fileStoreService.GetAsync(request.FileReference)
             };
             return(UseCaseResult <DownloadFileModel> .Create(model));
         }
         else
         {
             return(UseCaseResult <DownloadFileModel> .CreateError(resultText : "File Reference not found"));
         }
     }
     catch (Exception e)
     {
         return(UseCaseResult <DownloadFileModel> .CreateError(resultText : e.Message));
     }
 }