// [Authorize] public ActionResult Create(int auctionNumber) { if (!CanBiding(auctionNumber)) //aukcja nie trwa return View("CantBiding"); Offer offer = null; if (Roles.IsUserInRole(User.Identity.Name, @"SuperAdmin")) { int freeUsers = PopulateUserWithoutAuctionDropDownList(auctionNumber); if (freeUsers == 0) return View("OverLimitTotal"); offer = new Offer() { AuctionId = auctionNumber, StartPrice = SetCurrentPriceWithJump(auctionNumber) }; return View(offer); } if (!CanAddOffer(auctionNumber)) return View("OverLimit"); if (Roles.IsUserInRole(User.Identity.Name, @"Bidder")) { offer = new Offer() { AuctionId = auctionNumber, StartPrice = SetCurrentPriceWithJump(auctionNumber) }; return View(offer); } return View("AccessDenied"); }
/// <summary> /// Deprecated Method for adding a new object to the Offers EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToOffers(Offer offer) { base.AddObject("Offers", offer); }
/// <summary> /// Create a new Offer object. /// </summary> /// <param name="offerId">Initial value of the OfferId property.</param> /// <param name="startPrice">Initial value of the StartPrice property.</param> /// <param name="currentPrice">Initial value of the CurrentPrice property.</param> /// <param name="auctionId">Initial value of the AuctionId property.</param> /// <param name="userId">Initial value of the UserId property.</param> public static Offer CreateOffer(global::System.Int32 offerId, global::System.Decimal startPrice, global::System.Decimal currentPrice, global::System.Int32 auctionId, global::System.Guid userId) { Offer offer = new Offer(); offer.OfferId = offerId; offer.StartPrice = startPrice; offer.CurrentPrice = currentPrice; offer.AuctionId = auctionId; offer.UserId = userId; return offer; }
public ActionResult Create(Offer offer) { if (!CanBiding(offer.AuctionId)) return View("CantBiding"); if (!CanAddOffer(offer.AuctionId, offer.UserId)) return View("OverLimit"); if ((!Roles.IsUserInRole(User.Identity.Name, @"SuperAdmin")) && (!Roles.IsUserInRole(User.Identity.Name, @"Bidder"))) return View("AccessDenied"); if (ModelState.IsValid) { offer.CurrentPrice = offer.StartPrice; offer.BDCounter = 0; offer.JoinedDate = System.DateTime.UtcNow; SetAuctionCurrentPrice(offer.AuctionId, 0, offer.CurrentPrice, false); if ((Roles.IsUserInRole(User.Identity.Name, @"SuperAdmin")) && (CanAddOffer(offer.AuctionId, offer.UserId))) { } else { MembershipUser mu = Membership.GetUser(); Guid currentUserId = (Guid)mu.ProviderUserKey; offer.UserId = currentUserId; } offer.BDCounter = 0; var offerAuction = InBidEntities.Auctions.Where(x => x.AuctionId == offer.AuctionId).FirstOrDefault(); var timeToEndAuction = offerAuction.EndTime - DateTime.UtcNow; if (timeToEndAuction <= deathTimeExtend) offerAuction.EndTime += timeToEndAuction; InBidEntities.AddToOffers(offer); InBidEntities.SaveChanges(); return RedirectToAction("Index", new { auctionNumber = offer.AuctionId }); } PopulateUserWithoutAuctionDropDownList(offer.AuctionId, offer.UserId); return View(offer); }
public ActionResult Edit(int id, Offer offer/* FormCollection collection*/) { Offer o = InBidEntities.Offers.Where(x => x.OfferId == id).First(); if (!CanBiding(o.AuctionId)) return View("CantBiding"); if (null == offer) { return View("NotFound"); } if (ModelState.IsValid) { if ((Roles.IsUserInRole(User.Identity.Name, @"SuperAdmin"))/* && (CanAddOffer(offer.AuctionId, offer.UserId))*/) { try { o.CurrentPrice = offer.CurrentPrice; o.BDCounter += 1; o.EditDate = System.DateTime.UtcNow; SetAuctionCurrentPrice(offer.AuctionId, 0, o.CurrentPrice, false); var offerAuction = InBidEntities.Auctions.Where(x => x.AuctionId == offer.AuctionId).FirstOrDefault(); var timeToEndAuction = offerAuction.EndTime - DateTime.UtcNow; if (timeToEndAuction <= deathTimeExtend) offerAuction.EndTime += timeToEndAuction; InBidEntities.SaveChanges(); return RedirectToAction("Index", new { auctionNumber = offer.AuctionId }); } catch { return View(offer); } } if (!o.IsHostedBy()) //tu jest błąd return View("InvalidOwner"); try { o.CurrentPrice = offer.CurrentPrice; o.BDCounter += 1; o.EditDate = System.DateTime.UtcNow; SetAuctionCurrentPrice(offer.AuctionId, 0, o.CurrentPrice, false); var offerAuction = InBidEntities.Auctions.Where(x => x.AuctionId == offer.AuctionId).FirstOrDefault(); var timeToEndAuction = offerAuction.EndTime - DateTime.UtcNow; if (timeToEndAuction <= deathTimeExtend) offerAuction.EndTime += timeToEndAuction; InBidEntities.SaveChanges(); return RedirectToAction("Index", new { auctionNumber = offer.AuctionId }); } catch { return View(offer); } } return View(offer); }