public Art Insert(string name, string artist, string description, string image, decimal startingbid, decimal purchaseprice) { using (AuctionDBContext db = new AuctionDBContext()) { Art aTemp = new Art(); Random r = new Random(); aTemp.DateCreated = DateTime.Now; aTemp.Name = name; aTemp.Artist = artist; aTemp.Number = SetArtNumber(); aTemp.Description = description; aTemp.Image = image; aTemp.StartingBid = startingbid; aTemp.PurchasePrice = purchaseprice; aTemp.Bids = null; try { db.Arts.Add(aTemp); db.SaveChanges(); } catch (Exception e) { throw e; } return aTemp; } }
public Auction CreateAuction(DateTime date, string description, List<Art> arts) { Auction auction = new Auction() { Date = date, Description = description, Arts = arts }; using (AuctionDBContext db = new AuctionDBContext()) { //db.Arts.Load(); foreach (var art in arts) { db.Arts.Attach(art); db.Entry(art).Entity.Auction = auction; db.Entry(art).State = EntityState.Modified; // //db.Entry(art).State = EntityState.Modified;; } db.Auktions.Add(auction); db.DebugDetectChanges(); db.SaveChanges(); } return auction; }
public decimal WithdrawAmount(int mID, decimal bid) { decimal owe = 0; using (AuctionDBContext db = new AuctionDBContext()) { Member m = RetrieveSingleByID(mID); owe = Convert.ToDecimal(m.Point) - bid; if ((m.Point - bid) < 0) { m.Point = 0; } else { m.Point = m.Point - Convert.ToInt32(bid); } try { db.Members.Attach(m); var entry = db.Entry(m); entry.State = EntityState.Modified; db.SaveChanges(); } catch (Exception e) { throw e; } } return owe; }
public List<Auction> GetAll(bool isDone) { List<Auction> auctionList = new List<Auction>(); using (AuctionDBContext db = new AuctionDBContext()) { auctionList = db.Auktions.Include(x => x.Arts).Where(x => x.IsDone == isDone).OrderByDescending(x => x.Date).ToList(); } return auctionList; }
public void DeleteAuction(Auction auction) { if (auction == null) throw new NullReferenceException("auction"); using (AuctionDBContext db = new AuctionDBContext()) { db.Auktions.Attach(auction); db.Entry(auction).State = EntityState.Deleted; db.Auktions.Remove(auction); db.SaveChanges(); } }
public List<Art> RetrieveAll(int auID) { using (AuctionDBContext db = new AuctionDBContext()) { try { return db.Arts.Where(x => x.AuctionId == auID).ToList(); } catch (Exception e) { throw e; } } }
public List<Art> RetrieveAll() { using (AuctionDBContext db = new AuctionDBContext()) { try { return db.Arts.ToList(); } catch (Exception e) { throw e; } } }
public Member RetrieveSingleByID(int id) { using (AuctionDBContext db = new AuctionDBContext()) { try { return db.Members.SingleOrDefault(x => x.Id == id); } catch (Exception e) { throw e; } } }
public void DeleteArt(Art art) { if (art == null) throw new ArgumentNullException("art"); using (AuctionDBContext db = new AuctionDBContext()) { var dbArt = db.Arts.Single(x => x.Id == art.Id); //db.Arts.Attach(art); //db.Entry(art).State = EntityState.Deleted; db.Arts.Remove(dbArt); db.DebugDetectChanges(); db.SaveChanges(); } }
public Auction UpdateAuction(Auction auction) { if (auction == null) throw new NullReferenceException("auction"); using (AuctionDBContext db = new AuctionDBContext()) { try { var artsInDb = db.Arts.Where(x => x.AuctionId == auction.Id).ToList(); foreach (var art in artsInDb) { art.AuctionId = null; db.Entry(art).State = EntityState.Modified; } var artsInDbIds = artsInDb.Select(x => x.Id); foreach (var art in auction.Arts) { art.AuctionId = auction.Id; if (!artsInDbIds.Contains(art.Id)) { db.Entry(art).State = EntityState.Modified; } else { var tempObj = db.ChangeTracker.Entries<Art>().Single(x => x.Entity.Id == art.Id); tempObj.Entity.AuctionId = auction.Id; } } var artsList = auction.Arts; auction.Arts = null; db.Entry(auction).State = EntityState.Modified; db.DebugDetectChanges(); db.SaveChanges(); auction.Arts = artsList; } catch (UpdateException) { } } return auction; }
public Auction RetriveById(int id) { Auction auction = null; using (AuctionDBContext db = new AuctionDBContext()) { auction = db.Auktions.Include(x => x.Arts).Single(x => x.Id == id); } return auction; }
public List<Bid> RetrieveBidsByArt(Art a) { List<Bid> bCollection = null; using (AuctionDBContext db = new AuctionDBContext()) { try { bCollection = db.Bids.Include(x => x.Member).Where(x => x.Art.Id == a.Id).OrderByDescending(x => x.DateTime).ToList(); } catch (Exception e) { throw e; } } return bCollection; }
public Art Update(int id, string name, int no, string artist, string description, string image, decimal startingbid, decimal purchaseprice) { using (AuctionDBContext db = new AuctionDBContext()) { Art aTemp = RetrieveById(id); aTemp.Name = name; aTemp.Artist = artist; aTemp.Number = no; aTemp.Description = description; aTemp.Image = image; aTemp.StartingBid = startingbid; aTemp.PurchasePrice = purchaseprice; aTemp.Bids = null; try { db.Arts.Attach(aTemp); var entry = db.Entry(aTemp); entry.State = EntityState.Modified; db.SaveChanges(); } catch (Exception e) { throw e; } return RetrieveById(id); } }
public Art RetrieveById(int id) { using (AuctionDBContext db = new AuctionDBContext()) { Art aTemp = null; try { aTemp = db.Arts.Single(x => x.Id == id); } catch (Exception e) { throw e; } return aTemp; } }
private int SetArtNumber() { int? currentNumber; int newNumber; using (AuctionDBContext db = new AuctionDBContext()) { currentNumber = db.Arts.Max(x => (int?)x.Number); if (currentNumber == null) { newNumber = 1000; } else { newNumber = Convert.ToInt32(currentNumber) + 10; } return newNumber; } }
public Art UpdateToAuction(int id, Auction au) { using (AuctionDBContext db = new AuctionDBContext()) { Art aTemp = db.Arts.SingleOrDefault(x => x.Id == id); aTemp.Auction = au; try { db.Arts.Attach(aTemp); var entry = db.Entry(aTemp); entry.State = EntityState.Modified; db.SaveChanges(); } catch (Exception e) { throw e; } return RetrieveById(id); } }
public CtrMember.MemberBidState InsertBid(int mid, decimal bidAmount, int aid) { CtrArt ctrArt = new CtrArt(); CtrMember ctrMem = new CtrMember(); Art a = ctrArt.RetrieveById(aid); Member m = ctrMem.RetrieveSingleByID(mid); CtrMember.MemberBidState bidState = CtrMember.MemberBidState.BidError; if (m == null) { return CtrMember.MemberBidState.BidError; } if (a == null) { return CtrMember.MemberBidState.BidError; } if (ctrMem.CheckEligibleBid(m, bidAmount) == CtrMember.MemberBidState.Verified) { using (AuctionDBContext db = new AuctionDBContext()) { Bid b = new Bid(); b.DateTime = DateTime.Now; b.BidAmount = bidAmount; b.Art = a; b.Member = m; try { db.Members.Attach(m); db.Arts.Attach(a); db.Bids.Add(b); db.DebugDetectChanges(); db.SaveChanges(); } catch (Exception e) { throw e; } bidState = CtrMember.MemberBidState.BidConfirmed; } } else { bidState = CtrMember.MemberBidState.NotEnough; } return bidState; }
public Art RetrieveByNo(int no) { using (AuctionDBContext db = new AuctionDBContext()) { Art aTemp = null; try { aTemp = db.Arts.Single(x => x.Number == no); } catch (Exception e) { throw e; } return aTemp; } }