コード例 #1
0
        public ActionResult CloseConfirmed(int id)
        {
            if (!_customAuthentication.CheckUserInRoles(UserViewModel.ToUserEntity(), "Admin,Moderator"))
            {
                return(new HttpStatusCodeResult(403));
            }
            var lot = _lotService.GetLotEntity(id);

            lot.LotClosed = true;
            _lotService.UpdateLot(lot);
            return(RedirectToAction("Details", new { id = lot.Id }));
        }
コード例 #2
0
ファイル: LotController.cs プロジェクト: KaplinSergey/Auction
        public ActionResult GetBidsList(BidListViewModel model)
        {
            LotEntity currentLot       = _lotService.GetLotEntity((int)model.LotId);
            string    currentUserEmail = currentLot.User.Email;
            decimal   currentPrice     = currentLot.LastPrice ?? currentLot.StartPrice;

            if (currentUserEmail == User.Identity.Name)
            {
                ModelState.AddModelError("", "You can not add bid for your own lot");
            }
            else if ((model.Price <= currentPrice))
            {
                ModelState.AddModelError("", string.Format("Your bid must be higher than the last bet {0} byn ", currentPrice));
            }
            else if (ModelState.IsValid)
            {
                BidEntity newBid = new BidEntity {
                    Price = model.Price, LotId = model.LotId, UserId = _userService.GetUserByEmail(User.Identity.Name).Id, Date = DateTime.Now
                };
                if (_bidService.TryCreateBid(newBid, currentLot))
                {
                    currentLot.LastPrice = newBid.Price;
                    _lotService.UpdateLot(currentLot);
                }
                if (!Request.IsAjaxRequest())
                {
                    return(RedirectToAction("LotDetails", new { id = model.LotId }));
                }
                else
                {
                    model.Bids = _bidService.GetAllBidEntitiesByLotId(model.LotId).Select(b => b.ToMvcBid()).OrderByDescending(b => b.Price);
                    return(PartialView(model));
                }
            }
            if (!Request.IsAjaxRequest())
            {
                return(RedirectToAction("LotDetails", new { id = model.LotId }));
            }
            else
            {
                model.Bids = _bidService.GetAllBidEntitiesByLotId(model.LotId).Select(b => b.ToMvcBid()).OrderByDescending(b => b.Price);
                return(PartialView(model));
            }
        }
コード例 #3
0
        public async Task <ActionResult> Put(int id, [FromBody] UpdateLotResource lot)
        {
            if (!(await _authorizationService.AuthorizeAsync(User, id, "EditLot")).Succeeded)
            {
                return(Forbid());
            }

            await _lotService.UpdateLot(id, lot);

            return(NoContent());
        }
コード例 #4
0
        public void Execute(IJobExecutionContext context)
        {
            var lots = _lotService.GetAllLotEntities().Where(l => !l.IsSold && l.EndDate <= DateTime.Now).ToList();

            if (lots != null)
            {
                for (var i = 0; i < lots.Count(); i++)
                {
                    lots[i].IsSold = true;
                    _lotService.UpdateLot(lots[i]);
                }
            }
        }
コード例 #5
0
        public ActionResult EditLot(int id, [FromForm] LotDTO lot)
        {
            if (id != lot.Id)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }



            if (lot.Image != null)
            {
                if (!lot.Image.ContentType.Contains("image"))
                {
                    return(BadRequest("Invalid image format."));
                }

                try
                {
                    lot.ImageUrl = ImageHandler.SaveImage(lot.Image, _environment);
                }
                catch (Exception)
                {
                    return(BadRequest("Image upload error."));
                }
            }


            try
            {
                _lotService.UpdateLot(lot);
            }
            catch (Exception ex)
            {
                if (_lotService.GetLot(id) == null)
                {
                    return(NotFound());
                }
                else
                {
                    return(BadRequest(ex.Message));
                }
            }
            return(NoContent());
        }
コード例 #6
0
        public ActionResult ManageLotStatus(LotDetailsViewModel viewModel)
        {
            var lot = _lotService.GetLotEntity(viewModel.Id);

            if (!viewModel.IsConfirm)
            {
                lot.IsConfirm = true;
            }
            if (viewModel.IsBlocked)
            {
                lot.IsBlocked   = true;
                lot.BlockReason = viewModel.BlockReason;
            }
            else
            {
                lot.IsBlocked = false;
            }
            _lotService.UpdateLot(lot);

            return(RedirectToAction("LotDetails", "Lot", new { id = lot.Id }));
        }
コード例 #7
0
 public ActionResult EditLot(LotCreateViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         var lot      = _lotService.GetLotEntity(viewModel.Id);
         var category =
             _categoryService.GetAllCategoryEntities()
             .FirstOrDefault(c => c.CategoryName == viewModel.SettedCategoryName);
         if (category != null)
         {
             lot.CategoryRefId = category.Id;
         }
         lot.LotName     = viewModel.Name;
         lot.Discription = viewModel.Discription;
         lot.EndDate     = viewModel.EndDate;
         lot.IsConfirm   = false;
         _lotService.UpdateLot(lot);
         StartSchedulerJob(lot.EndDate);
         return(RedirectToAction("LotDetails", "Lot", new { id = viewModel.Id }));
     }
     return(View(viewModel));
 }