Exemplo n.º 1
0
        public IActionResult GetById(int id)
        {
            var item    = _itemService.GetById(id);
            var itemDto = _mapper.Map <ItemDto>(item);

            return(Ok(itemDto));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetById(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ValidationApiException(ApiErrorCode.MissingInformation, $"Parameter {nameof(id)} must be provided.");
            }

            var item = await _itemsService.GetById(id);

            if (item == null)
            {
                throw new ResourceNotFoundApiException(ApiErrorCode.ItemNotFound, $"Cannot find item with id='{id}'.");
            }

            var itemDto = _mapper.Map <ItemDto>(item);

            return(Ok(itemDto));
        }
Exemplo n.º 3
0
        public IActionResult Details(string id)
        {
            var serviceModel = _itemsService.GetById(id);

            var viewModel = new ItemDetailsViewModel
            {
                Description = serviceModel.Description,
                EndTime     = serviceModel.EndTime,
                Id          = serviceModel.Id,
                Price       = serviceModel.Price,
                StartTime   = serviceModel.StartTime,
                PicturePath = string.Concat("../../", serviceModel.PicturePath),
                ReturnUrl   = HttpContext.Request.Path.ToString(),
                Title       = serviceModel.Title
            };

            return(View(viewModel));
        }
Exemplo n.º 4
0
        public async Task CreateBidAsync(string bidAmount, string consoleId)
        {
            if (bidAmount == null || consoleId == null)
            {
                return;
            }

            var isParsed = decimal.TryParse(bidAmount, out var parsedBidAmount);

            if (!isParsed)
            {
                return;
            }

            var item = _itemsService.GetById(consoleId);

            if (item == null)
            {
                return;
            }

            if (item.Price >= parsedBidAmount)
            {
                return;
            }

            var userId       = Context.UserIdentifier;
            var serviceModel = new BidCreateServiceModel
            {
                Amount = parsedBidAmount,
                MadeOn = DateTime.UtcNow,
                ItemId = item.Id,
                UserId = userId
            };

            var succeeded = _bidService.CreateBid(serviceModel);

            if (!succeeded)
            {
                return;
            }

            await Clients.Groups(consoleId).SendAsync("ReceivedMessage", parsedBidAmount, userId);
        }