public void SaveFeedback(Feedback feedback) { DealDoubleContext context = new DealDoubleContext(); context.Feedbacks.Add(feedback); context.SaveChanges(); }
public void SaveAuction(Auction auction) { DealDoubleContext context = new DealDoubleContext(); context.Auctions.Add(auction); context.SaveChanges(); }
public void SaveCategory(Category category) { DealDoubleContext context = new DealDoubleContext(); context.Categories.Add(category); context.SaveChanges(); }
public void DeleteAuction(Auction auction) { DealDoubleContext context = new DealDoubleContext(); context.Entry(auction).State = System.Data.Entity.EntityState.Deleted; context.SaveChanges(); }
//create new bid public bool AddBid(Bid bid) { DealDoubleContext context = new DealDoubleContext(); context.Bids.Add(bid); return(context.SaveChanges() > 0); }
public void DeleteCategory(Category category) { DealDoubleContext context = new DealDoubleContext(); context.Entry(category).State = System.Data.Entity.EntityState.Deleted; context.SaveChanges(); }
//create a comment public bool LeaveComment(Comment comment) { var context = new DealDoubleContext(); context.Comments.Add(comment); return(context.SaveChanges() > 0); }
public void DeleteAuction(Auction auctionModel) { var context = new DealDoubleContext(); context.Entry(auctionModel).State = EntityState.Deleted; context.SaveChanges(); }
public int SavePicture(Picture picture) { DealDoubleContext context = new DealDoubleContext(); context.Pictures.Add(picture); context.SaveChanges(); return(picture.ID); }
//update existing category public void UpdateCategory(Category category) { var context = new DealDoubleContext(); context.Entry(category).State = EntityState.Modified; context.SaveChanges(); }
public List <Auction> GetAuctions() { var context = new DealDoubleContext(); return(context.Auctions.Include(a => a.Category) .Include(a => a.AuctionPictures) .Include("AuctionPictures.Picture").ToList()); }
public Auction GetAuction(int id) { var context = new DealDoubleContext(); return(context.Auctions.Include(a => a.AuctionPictures).Include("AuctionPictures.Picture") .Include(a => a.Bids).Include("Bids.User") .Where(a => a.Id == id).First()); }
public void UpdateAuction(Auction auction) { DealDoubleContext context = new DealDoubleContext(); var exitingAuction = context.Auctions.Find(auction.ID); context.AuctionPictures.RemoveRange(exitingAuction.AuctionPictures); context.Entry(exitingAuction).CurrentValues.SetValues(auction); context.AuctionPictures.AddRange(auction.AuctionPictures); context.SaveChanges(); }
//delete a comment by entityId, and recordId public bool DeleteEntityComment(int entityId, int recordId) { var context = new DealDoubleContext(); var auctionComment = context.Comments.Where(c => c.EntityId == entityId && c.RecordId == recordId).First(); context.Entry(auctionComment).State = EntityState.Deleted; return(context.SaveChanges() > 0); }
public int GetCategoriesCount(string search) { var context = new DealDoubleContext(); var categories = context.Categories.AsQueryable(); if (!string.IsNullOrEmpty(search)) { categories = categories.Where(c => c.Name.ToLower().Contains(search.ToLower())); } return(categories.Count()); }
//delete comments by entityId, and recordId public void DeleteEntityComments(int entityId, int recordId) { var context = new DealDoubleContext(); var auctionComments = context.Comments.Where(c => c.EntityId == entityId && c.RecordId == recordId); foreach (var auctionComment in auctionComments) { context.Entry(auctionComment).State = EntityState.Deleted; } context.SaveChanges(); }
public void UpdateAuction(Auction auction) { DealDoubleContext context = new DealDoubleContext(); var existingAuction = context.Auctions.Find(auction.ID); //first Take Auction from DB. context.AuctionPictures.RemoveRange(existingAuction.AuctionPictures); //second Remove all AuctionPictures table 1 to * relational data of The auction. context.Entry(existingAuction).CurrentValues.SetValues(auction); //Set new data on first selected auction data. context.AuctionPictures.AddRange(auction.AuctionPictures); //Add all new 1 to * relational data of upadted Auction on AuctionPictures table. //context.Entry(auction).State=System.Data.Entity.EntityState.Modified; context.SaveChanges(); }
public void UpdateAuction(Auction auction) { var context = new DealDoubleContext(); var existingAuction = context.Auctions.Where(a => a.Id == auction.Id).Include(a => a.AuctionPictures).First(); context.AuctionPictures.RemoveRange(existingAuction.AuctionPictures); //delete existing pics context.Entry(existingAuction).CurrentValues.SetValues(auction); //update all old values to newest except : navigation objects like pics context.AuctionPictures.AddRange(auction.AuctionPictures); //add new pics context.SaveChanges(); }
//filter categories public List <Category> FilterCategories(string search, int pageNo, int pageSize) { var context = new DealDoubleContext(); var categories = context.Categories.Include(c => c.Auctions).AsQueryable(); if (!string.IsNullOrEmpty(search)) { categories = categories.Where(c => c.Name.ToLower().Contains(search.ToLower())); } var skipCount = (pageNo - 1) * pageSize; return(categories.OrderByDescending(c => c.Id).Skip(skipCount).Take(pageSize).ToList()); }
//get count of auction that filtered by category and search public int GetAuctionsCount(int?categoryId, string searchTerm) { var context = new DealDoubleContext(); var auction = context.Auctions.Include(a => a.Category).AsQueryable(); if (categoryId.HasValue && categoryId.Value > 0) { auction = auction.Where(x => x.CategoryId == categoryId.Value); } if (!string.IsNullOrEmpty(searchTerm)) { auction = auction.Where(x => x.Title.ToLower().Contains(searchTerm.ToLower())); } return(auction.Count()); }
public List <Auction> SearchAuctions(int?categoryID, string searchTerm, int?pageNo, int pageSize) { DealDoubleContext context = new DealDoubleContext(); var auctions = context.Auctions.AsQueryable(); if (categoryID.HasValue && categoryID.Value > 0) { auctions = auctions.Where(x => x.CategoryID == categoryID.Value); } if (!string.IsNullOrEmpty(searchTerm)) { auctions = auctions.Where(x => x.Title.ToLower().Contains(searchTerm.ToLower())); } pageNo = pageNo ?? 1; // is same as pageNo = pageNo.HasValue ? pageNo : 1; var skipCount = (pageNo.Value - 1) * pageSize; return(auctions.OrderByDescending(x => x.CategoryID).Skip(skipCount).Take(pageSize).ToList()); }
public int GetAuctionCount(int?categoryID, string searchTerm) { DealDoubleContext context = new DealDoubleContext(); var auctions = context.Auctions.AsQueryable(); if (categoryID.HasValue && categoryID.Value > 0) { auctions = auctions.Where(x => x.CategoryID == categoryID.Value); } if (!string.IsNullOrEmpty(searchTerm)) { auctions = auctions.Where(x => x.Title.ToLower().Contains(searchTerm.ToLower())); } //.OrderByDescending(x => x.CategoryID) return(auctions.Count()); }
//get auctions by filtering them using search, category, and page no public List <Auction> FilterAuctions(int?categoryId, string searchTerm, int pageNo, int pageSize) { var context = new DealDoubleContext(); var auction = context.Auctions.Include(a => a.Category).AsQueryable(); if (categoryId.HasValue && categoryId.Value > 0) { auction = auction.Where(x => x.CategoryId == categoryId.Value); } if (!string.IsNullOrEmpty(searchTerm)) { auction = auction.Where(x => x.Title.ToLower().Contains(searchTerm.ToLower())); } int skipCount = pageSize * (pageNo - 1); return(auction.OrderByDescending(a => a.Id).Skip(skipCount).Take(pageSize).ToList()); }
//get average rate public int?GetAverageRate(int entityId, int recordId) { var context = new DealDoubleContext(); var comments = context.Comments.Where(c => c.EntityId == entityId && c.RecordId == recordId); if (comments != null && comments.Count() > 0) { var rates = comments.Select(c => c.Rating); var multipliedRatesCount = (rates.Where(r => r == 5).Count() * 5) + (rates.Where(r => r == 4).Count() * 4) + (rates.Where(r => r == 3).Count() * 3) + (rates.Where(r => r == 2).Count() * 2) + (rates.Where(r => r == 1).Count() * 1); decimal average = decimal.Divide(multipliedRatesCount, rates.Count()); return((Int32)Math.Round(average, MidpointRounding.AwayFromZero)); } return(null); }
public List <string> GetBidByID(int ID, string UserID) { DealDoubleContext context = new DealDoubleContext(); var AuctionID = context.Bids.Where(x => x.ID == ID).Select(x => x.AuctionID).FirstOrDefault(); var title = context.Bids.Where(x => x.ID == ID).Select(x => x.Auction.Title).FirstOrDefault(); var Amount = context.Bids.Where(x => x.ID == ID).Select(x => x.Auction.ActualAmount).FirstOrDefault(); // string a = Amount.ToString(); var BigId = context.Bids.Where(x => x.AuctionID == AuctionID && x.UserID == UserID).OrderByDescending(x => x.ID).FirstOrDefault(); var BidAmount1 = Amount + context.Bids.Where(x => x.AuctionID == AuctionID && x.ID >= ID).Sum(x => x.BidAmount); string a = BidAmount1.ToString(); var totalBidAmount = Amount + context.Bids.Where(x => x.AuctionID == AuctionID).Sum(x => x.BidAmount); string b = totalBidAmount.ToString(); var EndingTime = context.Bids.Where(x => x.ID == ID).Select(x => x.Auction.EndingTime).FirstOrDefault(); string c = EndingTime.ToString(); List <string> TitleAmountList = new List <string>(); TitleAmountList.Add(title); TitleAmountList.Add(a); TitleAmountList.Add(b); TitleAmountList.Add(c); return(TitleAmountList); }
public List <Comment> GetComments(int entityID, int recordID) { DealDoubleContext context = new DealDoubleContext(); return(context.Comments.Where(x => x.EntityID == entityID && x.RecordID == recordID).ToList()); }
public Repository(DealDoubleContext context) { Context = context; }
public Auction GetAuctionbyID(int ID) { DealDoubleContext context = new DealDoubleContext(); return(context.Auctions.Find(ID)); }
public List <Auction> GetPromotedAuction() { DealDoubleContext context = new DealDoubleContext(); return(context.Auctions.Take(4).ToList()); }
public List <Auction> GetAuctionsbyIDs(List <int> IDs) { DealDoubleContext context = new DealDoubleContext(); return(IDs.Select(id => context.Auctions.Find(id)).ToList()); }