public ActionResult DoEdit([Bind(Include = "Auction,SelectedProductIds")] AuctionViewModel auctionViewModel) { if (!ModelState.IsValid) { return(View("Edit", new AuctionViewModel { Products = GetMultiselect(auctionViewModel.SelectedProductIds) })); } if (Session["UserId"] == null) { throw new Exception("Current user is null"); } int currentUser = (int)Session["UserId"]; auctionViewModel.Auction.Owner = userRepository.Find(currentUser); foreach (var product in auctionViewModel.SelectedProductIds.Select(productId => productRepository.Find(productId))) { if (product != null) { auctionViewModel.Auction.Products.Add(product); } else { return(HttpNotFound()); } } auctionViewModel.Auction.CreationDate = DateTime.Now; repository.Save(auctionViewModel.Auction); return(RedirectToAction("List")); }
public AuctionViewModel PlaceBid(string username, AuctionViewModel auctionViewModel) { if (UserSameAsSeller(username, auctionViewModel)) { throw new InvalidOperationException("Users are not allowed to bid for their own auctions"); } if (BidAmountIsLessThanMinAmount(auctionViewModel)) { throw new ArgumentException("Bid must not be less than minimum amount for auction item"); } var user = GetUser(username); if (user == null) { throw new ArgumentException($"User {username} doesn't exist"); } var seller = GetUser(auctionViewModel.Seller); if (seller == null) { throw new ArgumentException($"User {auctionViewModel.Seller} doesn't exist"); } return(_auctionRepository.PlaceBid(user, auctionViewModel.ToAuction(seller), float.Parse(auctionViewModel.BidAmount)).ToAuctionViewModel()); }
public IActionResult createAuctions(AuctionViewModel newAuct) { int? CurrentUser = HttpContext.Session.GetInt32("CurrentUser"); Users user = _context.Users.Where(x => x.idUser == CurrentUser).SingleOrDefault(); if (newAuct.EndDate < DateTime.Now) { ViewBag.DateError = "End Date must be after today"; return(View("createAuctions")); } if (ModelState.IsValid) { Auctions auction = new Auctions { Product = newAuct.Product, StartingBid = newAuct.StartingBid, Description = newAuct.Description, EndDate = newAuct.EndDate, idUser = user.idUser, }; _context.Add(auction); _context.SaveChanges(); return(Redirect("/Dashboard")); } return(Redirect("/Dashboard")); }
public ActionResult SearchAuctions([Bind(Include = "Name, Status, HighPrice, LowPrice, Page")] AuctionViewModel avm) { var result = db.Auctions.OrderByDescending(a => a.CreatedOn).Where(x => x.Status != "READY").ToList(); if (avm.Name != null) { result = result.Where(a => a.Name.Contains(avm.Name)).ToList(); } if (avm.HighPrice != 0) { result = result.Where(a => a.CurrentPrice != null && a.StartPrice <= avm.HighPrice).ToList(); } if (avm.LowPrice != 0) { result = result.Where(a => a.CurrentPrice != null && a.StartPrice >= avm.LowPrice).ToList(); } if (avm.Status != null) { result = result.Where(a => a.Status.Equals(avm.Status)).ToList(); } int AuctionNum = db.SystemParameters.FirstOrDefault().DefaultNumPageAuctions; int PageNum = 1; if (avm.Page != null) { PageNum = (int)avm.Page; } avm.AuctionList = result.ToPagedList(PageNum, AuctionNum); return(View(avm)); }
public IActionResult Bid(AuctionViewModel viewModel) { var user = userRepository.GetByUsername(User.Identity.Name); if (user.Id == viewModel.User_Sale_ID) { TempData["BidError"] = "Error! You can not bid your own product"; return(RedirectToAction("Auction", viewModel)); } Auction auction = repository.GetById(viewModel.Id); if (viewModel.ActualPrice > auction.ActualPrice) { Notification notification = new Notification(NotificationType.RaisePrice, viewModel.User_Sale_ID, user.UserName, viewModel.ProductName, viewModel.ActualPrice); notification.AuctionId = auction.Id; notificationRepository.AddEntity(notification); auction.ActualPrice = viewModel.ActualPrice; auction.ActualUser = user.Id; repository.Update(auction); var userInAuction = userInAuctionRepository.GetById(new Tuple <long, string>(auction.Id, auction.ActualUser)); userInAuction.LastActionDate = DateTime.Now; userInAuction.LastAction = $"Raise the price to {viewModel.ActualPrice}"; userInAuctionRepository.Update(userInAuction); return(RedirectToAction("Auction", viewModel)); } TempData["BidError"] = "Invalid ammount."; return(RedirectToAction("Auction", viewModel)); }
public ActionResult Create([Bind(Include = "Name,Duration,startingPrice,Image")] AuctionViewModel auctionView) { logger.Info("POST/Auction/Create action has been called"); if (Session["User"] == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (ModelState.IsValid) { Auction auction = new Auction(); auction.Name = auctionView.Name; auction.Duration = auctionView.Duration; auction.startingPrice = auctionView.startingPrice; if (auctionView.Image != null) { auction.Img = new byte[auctionView.Image.ContentLength]; auctionView.Image.InputStream.Read(auction.Img, 0, auctionView.Image.ContentLength); } auction.createdOn = DateTime.UtcNow; auction.State = "READY"; myDB.Auctions.Add(auction); myDB.SaveChanges(); return(RedirectToAction("UserPanel", "Accounts")); } return(View()); }
public ActionResult Create(AuctionViewModel auction) { if (ModelState.IsValid) { var img = auction.FileBase; var imgParams = new ImageUploadParams { File = new FileDescription(img.FileName, img.InputStream) }; var result = _cloudinary.Upload(imgParams); var entity = new Auction() { Id = Guid.NewGuid(), Description = auction.Description, EndDate = auction.EndDate, Name = auction.Name, StartDate = auction.StartDate, StartingPrice = auction.StartingPrice, ImagePath = result.Uri.ToString(), UserId = Guid.Parse(User.Identity.GetUserId()) }; db.Auctions.Add(entity); db.SaveChanges(); return(RedirectToAction("MyAuctions")); } return(View(auction)); }
public async Task <ActionResult> Auction(int id) { AuctionViewModel model = new AuctionViewModel(); model.Auction = auctionService.GetAuctionByID(id); List <String> destNames = new List <String>(); if (model.Auction.IsOpen()) { destNames.Add(openDestName); } else { destNames.Add(closedDestName); } model.FullNavList = CreateAuctionNavList(destNames); model.LoggedInUser = await auctionService.GetCurrentUser(); if (model.Auction == null) { return(RedirectToAction("Index")); } return(View(model)); }
public IActionResult NewAuction(AuctionViewModel model) { if (ModelState.IsValid) { int? loggedIn = HttpContext.Session.GetInt32("userID"); User loggedUserInstance = _context.Users.SingleOrDefault(user => user.Id == (int)loggedIn); DateTime dateValue = DateTime.Parse(model.EndDate); if (dateValue >= DateTime.Now) { Auction AuctionInstance = new Auction { Product = model.Product, Description = model.Description, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, HighestBid = model.HighestBid, EndDate = dateValue, TimeAgo = dateValue.Humanize(), Author = HttpContext.Session.GetString("userFirstName") }; _context.Auctions.Add(AuctionInstance); _context.SaveChanges(); Auction thisOne = _context.Auctions.FirstOrDefault(auc => auc.Product == model.Product); return(Redirect($"/Auction/{thisOne.Id}")); } ViewData["Error"] = "Oops, please plan for the future"; return(View("New")); } return(View("New", model)); }
public ActionResult create(AuctionViewModel model) { tbl_Auction auction = new tbl_Auction(); auction.Title = model.Title; auction.Description = model.Description; auction.ActualAmount = model.ActualAmount; auction.StartingTime = model.StartingTime; auction.EndingTime = model.EndingTime; var pictureIDs = model.tbl_AuctionPicture.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList(); auction.tbl_AuctionPicture = new List <tbl_AuctionPicture>(); foreach (var picID in pictureIDs) { var auctionPicture = new tbl_AuctionPicture(); auctionPicture.PicID = picID; auction.tbl_AuctionPicture.Add(auctionPicture); } service.SaveAuction(auction); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "IdAuction,Name,ImageToUpload,Duration,StartingPrice")] AuctionViewModel auction) { log.Info("Post action /Create/Auction has been fired"); if (ModelState.IsValid) { Auction auctionEntity = new Auction(); if (auction.ImageToUpload != null) { auctionEntity.ImageToUpload = auction.ImageToUpload; auctionEntity.Image = new byte[auction.ImageToUpload.ContentLength]; auctionEntity.ImageToUpload.InputStream.Read(auctionEntity.Image, 0, auctionEntity.Image.Length); } auctionEntity.IdOwner = User.Identity.GetUserId(); auctionEntity.State = "READY"; auctionEntity.Created = DateTime.Now; auctionEntity.CurrentPrice = auction.StartingPrice; auctionEntity.StartingPrice = auction.StartingPrice; auctionEntity.Duration = auction.Duration; auctionEntity.Name = auction.Name; auctionEntity.IdAuction = Guid.NewGuid(); db.Auction.Add(auctionEntity); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(auction)); }
public ActionResult CreateRate(Guid?id, Guid?auctionTemplateId) { if (!id.HasValue) { return(RedirectToAction("ActiveLots", "Auctions")); } if (!auctionTemplateId.HasValue) { return(RedirectToAction("ActiveLots", "Auctions")); } var lot = _auctionProvider.GetActiveLotsForAuction(auctionTemplateId.Value, null) .FirstOrDefault(_ => _.Id == id); if (lot == null) { var viewModel = _auctionProvider.GetLotModelById(id.Value); Logger.Debug(Messages.LogsConstant.SelectedLotClosed.Format(viewModel.Context, Session.GetUserId())); ModelState.AddModelError("", Messages.MessagesConstant.SelectedLotClosed.Format(viewModel.Context, Session.GetUserId())); } var model = new AuctionViewModel { LotId = id.Value, AuctionTemplateId = auctionTemplateId.Value, Context = lot.Context, DirectionText = lot.DirectionText, UserId = Session.GetUserId(), User = _authProvider.GetUserById(Session.GetUserId()) }; return(View(model)); }
public bool CreateRate(AuctionViewModel viewModel, out string error) { var res = false; error = null; try { using (DbFactory.CreateUnitOfWork()) { var auction = new DAL.Data.Auction { Id = Guid.NewGuid(), LotId = viewModel.LotId, UserId = viewModel.UserId, Rate = viewModel.Rate, CreateDateTime = viewModel.CreateDateTime, ModifidedDateTime = viewModel.ModifidedDateTime }; DbFactory.Auctions.Save(auction); } } catch (Exception e) { res = true; error = e.Message; } return(res); }
//BRING GIGS TO AURO PRO VIEW public ActionResult AuroraPro(int? specificIndustryID) { // BRING THE GIGS WITH THE DATA I WANT var auctions = unitOfWork.AuctionRepository.GetAuctionsForProIndex(specificIndustryID); // SEND GIGS TO THE VIEW var viewModel = new AuctionViewModel(auctions, User.Identity.IsAuthenticated, specificIndustryID == null ? "No Gigs were Found" : $"All {unitOfWork.SpecificIndustryRepository.GetSpecificIndustry(specificIndustryID).Name} Pro Gigs"); if (User.Identity.IsAuthenticated) { var userId = User.Identity.GetUserId(); viewModel.FavouriteGigs = unitOfWork.FavouriteGigRepository.GetFavouriteGigs(userId) .ToList() .ToLookup(f => f.GigID); viewModel.FavouriteInfluencers = unitOfWork.FavouriteInfluencerRepository.GetFavouriteInfluencers(userId) .ToList() .ToLookup(f => f.InfluencerID); } //SEND THE SORTED LIST TO THE VIEW return View("AuroraPro", viewModel); }
public void checkedAuctions(AuctionViewModel AVM) { foreach (AuctionEventModel AEM in AVM.runningAuctions) { // AuctionProccessor.ChangeStatus(); long aucTime = AuctionProccessor.ConvertToMiliSeconds(AEM.EndTime); //AEM.EndTime; long nowTIme = DateTime.Now.Ticks; Debug.WriteLine("aucTime = " + aucTime + " && nowTime = " + nowTIme); Console.WriteLine("aucTime = " + aucTime + " && nowTime = " + nowTIme); System.Diagnostics.Debug.WriteLine("aucTime = " + aucTime + " && nowTime = " + nowTIme); if (aucTime > nowTIme) { AuctionProccessor.ChangeStatus(AEM.AuctionID, "FINISHED"); } } foreach (AuctionEventModel AEM in AVM.upcommingAuctions) { // AuctionProccessor.ChangeStatus(); long aucTime = AuctionProccessor.ConvertToMiliSeconds(AEM.StartTime); long nowTIme = DateTime.Now.Ticks; if (aucTime >= nowTIme) { AuctionProccessor.ChangeStatus(AEM.AuctionID, "RUNNING"); } } }
public IActionResult AddAuction(AuctionViewModel model) { int?userId = HttpContext.Session.GetInt32("currentUserId"); Person currentUser = context.User.SingleOrDefault(user => user.id == userId); if (ModelState.IsValid) { Auction newAuction = new Auction { ProductName = model.ProductName, CreatedBy = currentUser.firstName + " " + currentUser.lastName, Description = model.Description, Bid = model.Bid, EndDate = DateTime.Parse(model.EndDate), created_at = DateTime.Now, updated_at = DateTime.Now }; context.Add(newAuction); context.SaveChanges(); return(RedirectToAction("Dash")); } else { ViewBag.User = currentUser; return(View(model)); } }
public ActionResult ViewAuctionDetails(AuctionViewModel model) { var bidRepo = new BidRepository(); var aucRepo = new AuctionRepository(); var userRepo = new UserRepository(); var auction = aucRepo.GetAuctionById(model.Id); model.Bid = aucRepo.GetHighestBid(model.Id); var returnModel = auction.ConvertToViewModel(); if (model.NextBid.Price > (auction.MinPrice + auction.Interval) && model.NextBid.Price > model.Bid.Price) { model.NextBid.Auction = auction; model.NextBid.Active = true; model.NextBid.Date = DateTime.Now; model.NextBid.User = userRepo.GetUserById(1); bidRepo.InsertBid(model.NextBid); auction.Bids.Add(model.NextBid); returnModel.Bid = model.NextBid; returnModel.ErrorMessage = "Bud på auktionen er godkendt!"; } else { returnModel.Bid = model.Bid; returnModel.ErrorMessage = "Bud for lavt!"; } return(View(returnModel)); }
public async Task <ActionResult> Create([Bind(Include = "Name,Duration,StartAmmount,Picture")] AuctionViewModel auction) { if (ModelState.IsValid) { Db.Auctions.Add(new Auction { Id = Guid.NewGuid().ToString(), Duration = auction.Duration, EndDate = DateTime.Now, StartDate = DateTime.Now, StartAmmount = auction.StartAmmount, CurrentAmmount = auction.StartAmmount, Name = auction.Name, PictureContent = ImageManipulation.StoreImage(ImageManipulation.ResizeImage(ImageManipulation.LoadImage(auction.Picture.InputStream), 600, 600)), Status = Auction.AuctionStatus.READY, User = await UserManager.FindByIdAsync(User.Identity.GetUserId()), Currency = Db.Params.Find("C").Value, CurrencyPrice = decimal.Parse(Db.Params.Find("T").Value) }); await Db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(auction)); }
public async Task <ActionResult> Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AuctionViewModel auction = new AuctionViewModel(await Db.Auctions.Include(x => x.User).Include(x => x.LastBidder).FirstOrDefaultAsync(x => x.Id == id)); if (auction == null) { return(HttpNotFound()); } var bids = Db.Bids.Where(x => x.AuctionId == id).OrderByDescending(x => x.TimeStamp).ToList(); var users = bids.Select(x => Db.Users.Find(x.UserId)).ToList(); decimal q = auction.CurrentAmmount; foreach (var bid in bids) { decimal g = bid.Increment; bid.Increment = q; q -= g; } ViewBag.Bids = bids; ViewBag.Users = users; return(View(auction)); }
public IActionResult createAuction(AuctionViewModel auctionMe, int bidder_id) { int? userID = HttpContext.Session.GetInt32("loggedUserID"); //checking to see if user is logged in --then grabbing that user's id out of session User currentUser = _context.user.Where(u => u.UserId == userID).FirstOrDefault(); if(currentUser != null) { Auction NewAuction = new Auction { product_name = auctionMe.product_name, description = auctionMe.description, price = auctionMe.price, date = auctionMe.date, UserId = (int) HttpContext.Session.GetInt32("loggedUserID"), }; if (TryValidateModel(NewAuction)) { _context.auctions.Add(NewAuction); _context.SaveChanges(); return Redirect("/success"); } else { ViewBag.errors = ModelState.Values; return View("newAuction"); } } else { ViewBag.errors = ModelState.Values; return View("newAuction"); } }
public ActionResult Create() { var model = new AuctionViewModel(); model.Categories = CategoriesService.Instance.GetCategories(); return(PartialView(model)); }
public ActionResult Auction(int id) { AuctionViewModel model = new AuctionViewModel(); var entity = new auctiondbEntities(); model.Auction = entity.Auctions.Single <Auction>(a => a.Id.Equals(id)); return(View(model)); }
public ActionResult DeleteConfirmed(int id) { AuctionViewModel auctionViewModel = db.AuctionViewModels.Find(id); db.AuctionViewModels.Remove(auctionViewModel); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Add() { var viewModel = new AuctionViewModel { StartDate = DateTime.Now, PredictedEndDate = DateTime.Now }; ViewData["AuctionStatuses"] = GetAuctionStatuses(); return(PartialView("_Add", viewModel)); }
public IActionResult Index() { var model = new AuctionViewModel(); model.Product = _productService.GetRandomProduct(); return(View(model)); }
public ActionResult Edit(int id) { var model = new AuctionViewModel(); model.Auction = AuctionsService.Instance.GetAuction(id); model.Categories = CategoriesService.Instance.GetCategories(); return(PartialView(model)); }
private void InitializeAuction() { // Initialize model auctionViewModel = new AuctionViewModel(0, 10, DateTime.Now.AddSeconds(59), 10); timer = new System.Threading.Timer(TimerExpired, null, sec, 0); initialized = true; }
public ActionResult Edit([Bind(Include = "ProductId,ProductName,ProductPrice,ImagePath,ProductInfo,BidPrice")] AuctionViewModel auctionViewModel) { if (ModelState.IsValid) { db.Entry(auctionViewModel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(auctionViewModel)); }
public async Task <IActionResult> Create(AuctionViewModel auction) { var claimsIdentity = (ClaimsIdentity)this.User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); var user = await _db.Seller.Where(s => s.Id == claim.Value).FirstOrDefaultAsync(); if (ModelState.IsValid) { AuctionHeader auctionHeader = new AuctionHeader() { Seen = false, SellerId = claim.Value, User = user, BeginDate = auction.AuctionHeader.BeginDate, EndDate = auction.AuctionHeader.EndDate, CurrentPrice = auction.AuctionHeader.CurrentPrice, PriceStep = auction.AuctionHeader.PriceStep }; _db.AuctionHeader.Add(auctionHeader); await _db.SaveChangesAsync(); foreach (var item in auction.Products) { var productSale = await _db.ProductSale.Include(p => p.Product).Where(p => p.Id == item.ProductSale.Id).FirstOrDefaultAsync(); productSale.Units -= item.Quantity; var product = await _db.Product.Where(p => p.Id == productSale.ProductId).FirstOrDefaultAsync(); var auctionProduct = new AuctionProduct() { ProductId = product.Id, Product = product, AuctionId = auctionHeader.Id, AuctionHeader = auctionHeader, Quantity = item.Quantity }; _db.AuctionProduct.Add(auctionProduct); } await _db.SaveChangesAsync(); return(RedirectToAction("Index", "Seller")); } foreach (var modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { Console.WriteLine(error.ErrorMessage); } } return(RedirectToAction(nameof(Select))); }
public IActionResult Index() { IEnumerable <IndexAuctionViewModel> openAuctions = _businessService.GetOpenAuctions(); AuctionViewModel viewModel = new AuctionViewModel { IndexAuctionViewModels = openAuctions }; return(View(openAuctions)); }
public ActionResult Add(AuctionViewModel viewModel) { if (!ModelState.IsValid) return PartialView("_Add", viewModel); var auction = TypeAdapter.Adapt<AuctionViewModel, Auction>(viewModel); auction.LastPriceChangeDate = auction.StartDate; auction.UserId = User.Identity.GetUserId(); try { _auctionService.AddAuction(auction); return Json(new { success = true }); } catch (Exception e) { Logger.Error(e); return Json(new { success = false }); } }
public ActionResult Add() { var viewModel = new AuctionViewModel {StartDate = DateTime.Now, PredictedEndDate = DateTime.Now}; ViewData["AuctionStatuses"] = GetAuctionStatuses(); return PartialView("_Add", viewModel); }