public ActionResult DeleteConfirmed(Guid id) { AuctionsModel.Auction auction = db.Auctions.Find(id); db.Auctions.Remove(auction); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "Name,StartingPrice")] AuctionsModel.Auction auction, HttpPostedFileBase image, int?duration) { auction.ID = Guid.NewGuid(); auction.CreatedOn = DateTime.UtcNow; auction.State = "READY"; if (duration != null) { auction.Duration = (int)duration; } else { auction.Duration = Settings.GlobalSettings.D; } if (image != null && image.IsImage()) { auction.Image = new byte[image.ContentLength]; image.InputStream.Read(auction.Image, 0, image.ContentLength); //auction.Image = image.CreateThumbnail(150, 150); } if (ModelState.IsValid) { db.Auctions.Add(auction); db.SaveChanges(); Logger.Logger.log("auction created, id = " + auction.ID.ToString()); return(RedirectToAction("Index")); } return(View(auction)); }
public ActionResult OpenAuction(Guid id) { AuctionsModel.Auction auction = db.Auctions.Find(id); if (auction.State == "READY") { Logger.Logger.log("auction " + id.ToString() + "oppened"); auction.State = "OPENED"; auction.OppenedOn = DateTime.UtcNow; db.SaveChanges(); } return(RedirectToAction("Index", db.Auctions.ToList())); }
// GET: Auctions/Edit/5 //public ActionResult Edit(Guid? id) //{ // if (id == null) // { // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); // } // AuctionsModel.Auction auction = db.Auctions.Find(id); // if (auction == null) // { // return HttpNotFound(); // } // return View(auction); //} // POST: Auctions/Edit/5 // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://go.microsoft.com/fwlink/?LinkId=317598. //[HttpPost] //[ValidateAntiForgeryToken] //public ActionResult Edit([Bind(Include = "ID,Name,Image,Duration,StartingPrice,CreatedOn,OppenedOn,ClosedOn,State")] AuctionsModel.Auction auction) //{ // if (ModelState.IsValid) // { // db.Entry(auction).State = EntityState.Modified; // db.SaveChanges(); // return RedirectToAction("Index"); // } // return View(auction); //} // GET: Auctions/Delete/5 public ActionResult Delete(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AuctionsModel.Auction auction = db.Auctions.Find(id); if (auction == null) { Logger.Logger.log("auction dnot deleted, auction " + id.ToString() + "not found"); return(HttpNotFound()); } Logger.Logger.log("auction deleted"); return(View(auction)); }
public ActionResult CloseAuction(Guid id) { AuctionsModel.Auction auction = db.Auctions.Find(id); // close only if the auction has expiered or if the user is admin if ((auction.OppenedOn.AddSeconds(auction.Duration) <= DateTime.UtcNow || (User != null && User.IsInRole("Admin"))) && auction.State == "OPENED") { auction.State = "CLOSED"; auction.ClosedOn = DateTime.UtcNow; Logger.Logger.log("auction: " + auction.ID + " closed"); db.SaveChanges(); Hubs.AuctionNotificaionsHub.SendSignalToClientsToCloseAuction(id); } return(RedirectToAction("Index", db.Auctions.ToList())); }