Exemplo n.º 1
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.º 2
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.º 3
0
        public async Task <List <PromotionDTO> > GetPromotionsFromAbonnees()
        {
            var user         = (await _userManager.GetUserAsync(HttpContext.User));
            var lastLogin    = user.LastLogin;
            var userBusiness = await _userBusinessRepository.FindByUserId(user.Id);

            var allBusinesses = await _businessRepository.All();

            List <PromotionDTO> promotions = new List <PromotionDTO>();

            foreach (var ub in userBusiness)
            {
                foreach (var ab in allBusinesses)
                {
                    if (ub.BusinessId == ab.Id)
                    {
                        foreach (var promotion in ab.Promotions)
                        {
                            if (promotion.Creation >= lastLogin)
                            {
                                promotions.Add(new PromotionDTO
                                {
                                    Name          = promotion.Name, Description = promotion.Description,
                                    PromotionType = promotion.PromotionType,
                                    StartDate     = promotion.StartDate,
                                    EndDate       = promotion.EndDate
                                });
                            }
                        }
                    }
                }
            }

            user.LastLogin = DateTime.UtcNow;
            _userRepository.SaveChanges();
            return(promotions);
        }
Exemplo n.º 4
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.º 5
0
 public string Resolve(object source, object destination, Guid sourceMember, string destMember, ResolutionContext context)
 {
     return(_businessRepository.All().Where(s => s.Id == sourceMember).SingleOrDefault()?.Name);
 }
        public async Task <List <Business> > Index()
        {
            var b = await _businessRepository.All();

            return(b);
        }