Beispiel #1
0
        /// <summary>
        /// Gets lots with active lot state by the category name.
        /// </summary>
        /// <param name="category"></param>
        /// <returns>
        /// If parameters is null, returns all available lots.
        /// </returns>
        public IEnumerable <Lot> GetActiveLotsByCategory(string category)
        {
            if (category == null)
            {
                return(_lotRepository.Find(l => l.LotState.LotStateName == "Active"));
            }
            else
            {
                var categoryID = _categoryRepository
                                 .Find(c => c.CategoryName == category)
                                 .FirstOrDefault()
                                 .CategoryID;

                return(_lotRepository.Find(l => l.CategoryID == categoryID && l.LotState.LotStateName == "Active"));
            }
        }
Beispiel #2
0
        public async Task Find_Rates_Test()
        {
            var lot = await repository.Find(1);

            Assert.Equal(Lots[0], lot);
            Assert.Equal(Lots[0].Id, lot.Id);

            await repository.LoadRates(lot);

            Assert.Equal(Rates, lot.Rates);
            Assert.Equal(Rates.Count, lot.Rates.Count);
        }
Beispiel #3
0
        public async Task <IActionResult> Update(int lotId)
        {
            var lot = await _repository.Find(lotId, HttpContext.UserId(), HttpContext.User.IsInRole(Constants.AdminRole), this.GetTimezoneOffset());

            if (lot != null)
            {
                var categories = await _categoryRepository.GetAll();

                ViewBag.Categories = new SelectList(categories, "Id", "Name");
                ViewData["Id"]     = lotId;
                return(View(new CreateLotModel(lot)));
            }

            return(RedirectToAction("index", "Home"));
        }
Beispiel #4
0
        private async Task <Rate> SaveBet(int lotId, decimal bet)
        {
            var lot = await _lotRepository.Find(lotId);

            if (lot != null)
            {
                await _lotRepository.LoadRates(lot);

                if ((lot.Rates.Count == 0 || bet > lot.Rates.Max(i => i.Amount)) && bet >= lot.MinPrice)
                {
                    var rate = new Rate
                    {
                        Amount    = bet,
                        CreatedAt = DateTime.UtcNow,
                        LotId     = lotId,
                        AppUserId = Context.UserIdentifier
                    };

                    return(await _repository.Add(rate));
                }
            }

            return(null);
        }