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 })); }
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)); } }
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()); }
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]); } } }
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()); }
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 })); }
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)); }