Exemple #1
0
        // GET: Explore
        public ActionResult Index()
        {
            ExploreViewModel model = new ExploreViewModel();

            var categories = this.aimCategoryService.GetAimCategories();

            model.AimCategories = mapper.Map <IEnumerable <AimCategoryViewModel> >(categories);

            return(View(model));
        }
Exemple #2
0
 public IResponse Get(Guid key)
 {
     try
     {
         var citezen = _citezenService.Get(key);
         return(_mapperAdapter.Map <Citezen, CitezenOkResponseModel>(citezen));
     }
     catch (NotFoundException ex)
     {
         return(new NotFoundResponseModel(ex.Message));
     }
 }
Exemple #3
0
        public async Task <LotModel> CreateLot(LotModel filter)
        {
            Data.Contracts.Entities.Lot lot = _mapperAdapter.Map <Lot>(filter);

            Lot result = await _lotRepository.Add(lot);

            SentMessageToQueue(result.Id);

            var savedLot = _mapperAdapter.Map <LotModel>(result);

            return(savedLot);
        }
Exemple #4
0
        public IResponse Authentication(AuthenticationRequestModel authentication)
        {
            var auth  = _mapperAdapter.Map <AuthenticationRequestModel, Authentication>(authentication);
            var token = _authService.Authentication(auth);

            if (token == Guid.Empty)
            {
                return(new AuthenticationOkResponseModel("Email/Cpf or Senha invalid."));
            }

            return(_mapperAdapter.Map <Guid, AuthenticationOkResponseModel>(token));
        }
        public async Task <IList <CustomerDto> > GetAllCustomers()
        {
            _logger.LogInformation("Method GetAllCustomers Invoked.");
            try
            {
                var result = await _getAllCustomersQuery.Get();

                var mappedResult = _mapperAdapter.Map <IList <CustomerDto> >(result);
                return(mappedResult);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Method GetAllCustomers failed.");
                throw;
            }
        }
Exemple #6
0
        public async Task <IActionResult> Post(LotViewModel lotToCreate)
        {
            LotModel domainLot = _mapperAdapter.Map <LotModel>(lotToCreate);

            LotModel result;

            try
            {
                result = await _lotsLogic.CreateLot(domainLot);
            }
            catch (Exception ex)
            {
                Log.Error($"{LotCreationError}. Error: {ex.Message}");
                return(BadRequest($"{LotCreationError}"));
            }

            var createdLot = _mapperAdapter.Map <LotViewModel>(result);

            return(CreatedAtRoute(nameof(Get), new { id = createdLot.Id }, createdLot));
        }
 public async Task <IList <ActivityLogDto> > GetAllActivityLogs()
 {
     _logger.LogInformation("Method GetAllActivityLogs Invoked.");
     try
     {
         return(_mapperAdapter.Map <IList <ActivityLogDto> >(await _allActivityLogsQuery.Get()));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "Method GetAllActivityLogs failed.");
         throw;
     }
 }
        public PartialViewResult SearchPlayers(SearchSubmitModel submitModel, int?page)
        {
            int actualPage     = page ?? 1;
            int playersPerPage = 3;

            var result = this.playerService.SearchPlayers(submitModel.SearchWord, submitModel.ChosenTeamIds, submitModel.SortBy, actualPage, playersPerPage);
            var count  = this.playerService.GetPlayersCount(submitModel.SearchWord, submitModel.ChosenTeamIds);

            var resultViewModel = new SearchResultsViewModel();

            resultViewModel.PlayersCount = count;
            resultViewModel.SubmitModel  = submitModel;
            resultViewModel.Pages        = (int)Math.Ceiling((double)count / playersPerPage);

            resultViewModel.Players = mapper.Map <IEnumerable <PlayerViewModel> >(result);

            return(this.PartialView("_ResultsPartial", resultViewModel));
        }
Exemple #9
0
        public IResponse Get(Guid key)
        {
            try
            {
                var token = Context.Request.Headers["Token"];

                if (!_authAppService.IsTokenValid(Guid.Parse(token)))
                {
                    return(new UnauthorizedResponseModel("Citezen not authenticated"));
                }

                var address = _addressService.Get(key);
                return(_mapperAdapter.Map <Address, AddressOkResponseModel>(address));
            }
            catch (NotFoundException ex)
            {
                return(new NotFoundResponseModel(ex.Message));
            }
            catch (Exception ex)
            {
                return(new InternoServerErrorResponseModel(ex.Message));
            }
        }
        public Task AddPhoto(PhotoModel domainPhoto)
        {
            Photo photo = _mapperAdapter.Map <Photo>(domainPhoto);

            return(_photosRepository.Add(photo));
        }
Exemple #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <IResponse> Handle(RedisAddBasketItemCommand request, CancellationToken cancellationToken)
        {
            var productId = request.Product.Product.Id;
            var stock     = await _stockProvider.GetStockForProduct(productId);

            var quantity = request.Quantity;

            if (quantity > stock)
            {
                return(new ErrorResponse(HttpStatusCode.BadRequest,
                                         _localized.GetString("CannotGreaterThanTheStock")));
            }

            var basketExpiryDate = TimeSpan.FromDays(_basketRules.ExpirationDurationInDays);
            var basketItems      = await _cacheService.GetAsync <List <BasketItemDto> >(request.CustomerId);

            if (basketItems != null && basketItems.Any())
            {
                var basketQuantity =
                    basketItems.Where(x => x.Product.Product.Id.Equals(productId))
                    .Sum(x => x.Quantity) + quantity;

                if (basketQuantity > stock)
                {
                    return(new ErrorResponse(HttpStatusCode.BadRequest,
                                             _localized.GetString("CannotGreaterThanTheStock")));
                }

                var existItem = basketItems.SingleOrDefault(x => x.Product.Product.Id.Equals(productId));
                if (existItem != null)
                {
                    existItem.Quantity += quantity;
                }
                else
                {
                    var productInfo = _mapper.Map <ProductInfoDto>(request.Product);
                    var item        = new BasketItemDto
                    {
                        Product  = productInfo,
                        Quantity = quantity
                    };
                    basketItems.Add(item);
                }

                var set = _cacheService.Set(request.CustomerId, basketItems, basketExpiryDate);
                if (set)
                {
                    return(new SuccessResponse(HttpStatusCode.OK, _localized.GetString("SuccessfullyAdded")));
                }

                return(new ErrorResponse(HttpStatusCode.BadRequest, _localized.GetString("NotAdded")));
            }

            var basketItem = _mapper.Map <BasketItemDto>(request.Product);

            basketItem.Quantity = quantity;
            var setItem = _cacheService.Set(request.CustomerId, basketItem, basketExpiryDate);

            if (setItem)
            {
                return(new SuccessResponse(HttpStatusCode.OK, _localized.GetString("SuccessfullyAdded")));
            }

            return(new ErrorResponse(HttpStatusCode.BadRequest, _localized.GetString("NotAdded")));
        }