public IEnumerable <Publication> GetOfBuyer(int idBuyer, int status = 0) { using (CompraAppContext db = new CompraAppContext()) { var query = from p in db.Publications select new { Publication = p, OffersCount = db.Offers.Where(o => o.State == (int)Offer.ACTION.OPEN).Count(o => o.IdPublication == p.Id) }; List <Publication> publications = new List <Publication>(); foreach (var row in query) { Publication p = row.Publication; p.CountOffers = row.OffersCount; if ((p.IdBuyer == idBuyer) && (p.State == status)) { publications.Add(p); } } //return db.Publications.Where(p => p.IdBuyer == idBuyer).ToList(); return(publications); } }
public Offer Get(int id) { using (CompraAppContext db = new CompraAppContext()) { return(db.Offers.Find(id)); } }
public Offer MakeAction(int id, Offer.ACTION action) { using (CompraAppContext db = new CompraAppContext()) { Offer offerForUpdate = db.Offers.Find(id); if (Exists(offerForUpdate)) { if (checkAction(offerForUpdate, action)) { if (action == Offer.ACTION.ACCEPTED) { setRejectedToOffersLosers(db, offerForUpdate); closePublicationByAcceptedOffer(db, offerForUpdate); } offerForUpdate.State = (int)action; db.Offers.Attach(offerForUpdate); db.Entry(offerForUpdate).State = EntityState.Modified; db.SaveChanges(); return(offerForUpdate); } else { throw new Exception("Error: Offerta ya procesada como aceptada, cancelada o rechazada."); } } else { throw new Exception("Error: No existe la oferta."); } } }
public IEnumerable <Offer> GetAll() { using (CompraAppContext db = new CompraAppContext()) { return(db.Offers.ToList()); } }
public Publication Get(int id) { using (CompraAppContext db = new CompraAppContext()) { return(db.Publications.Find(id)); } }
public IEnumerable <Offer> GetAll(int state = (int)Offer.ACTION.OPEN) { using (CompraAppContext db = new CompraAppContext()) { return(db.Offers.Where(o => o.State == state).ToList()); } }
public IEnumerable <Offer> GetBySeller(int idSeller) { using (CompraAppContext db = new CompraAppContext()) { return(db.Offers.Where(o => o.IdSeller == idSeller).ToList()); } }
public Seller Get(string email) { using (CompraAppContext db = new CompraAppContext()) { return(db.Sellers.Where(s => s.Email == email).FirstOrDefault()); } }
public Buyer Edit(int id, Buyer buyer) { using (CompraAppContext db = new CompraAppContext()) { try { Buyer buyerForUpdate = db.Buyers.Find(id); if (Exists(buyerForUpdate)) { buyerForUpdate.Address = buyer.Address; buyerForUpdate.Email = buyer.Email; buyerForUpdate.Name = buyer.Name; buyerForUpdate.Notifications = buyer.Notifications; buyerForUpdate.Phone = buyer.Phone; buyerForUpdate.Latitud = buyer.Latitud; buyerForUpdate.Longitud = buyer.Longitud; db.Buyers.Attach(buyerForUpdate); db.Entry(buyerForUpdate).State = EntityState.Modified; db.SaveChanges(); return(buyerForUpdate); } }catch (Exception e) { var a = e; } return(null); } }
public object MakeAction(int id, Publication.STATE action) { using (CompraAppContext db = new CompraAppContext()) { Publication publicationForUpdate = db.Publications.Find(id); if (Exists(publicationForUpdate)) { if (checkAction(publicationForUpdate, action)) { if (action == Publication.STATE.CLOSE_BY_USER) { } publicationForUpdate.State = (int)action; db.Publications.Attach(publicationForUpdate); db.Entry(publicationForUpdate).State = EntityState.Modified; db.SaveChanges(); return(publicationForUpdate); } else { throw new Exception("Error: Publicación ya cerrada."); } } else { throw new Exception("Error: No existe la publicación."); } } }
private void closePublicationByAcceptedOffer(CompraAppContext db, Offer offerForUpdate) { Publication publication = db.Publications.Find(offerForUpdate.IdPublication); publication.State = (int)Publication.STATE.CLOSE_BY_ACEPTED_OFFER; db.Publications.Attach(publication); db.Entry(publication).State = EntityState.Modified; }
public Seller Add(Seller seller) { using (CompraAppContext db = new CompraAppContext()) { db.Sellers.Add(seller); db.SaveChanges(); return(seller); } }
public Buyer Add(Buyer buyer) { using (CompraAppContext db = new CompraAppContext()) { db.Buyers.Add(buyer); db.SaveChanges(); return(buyer); } }
public Publication Add(Publication publication) { using (CompraAppContext db = new CompraAppContext()) { publication.Buyer = db.Buyers.Find(publication.IdBuyer); db.Buyers.Attach(publication.Buyer); db.Publications.Add(publication); db.SaveChanges(); return(publication); } }
private void setRejectedToOffersLosers(CompraAppContext db, Offer offerWin) { List <Offer> offersToClose = db.Offers.Where(o => o.IdPublication == offerWin.IdPublication && o.Id != offerWin.Id).ToList(); foreach (Offer offer in offersToClose) { offer.State = (int)Offer.ACTION.REJECTED; db.Offers.Attach(offer); db.Entry(offer).State = EntityState.Modified; } }
public IEnumerable <Publication> GetAll(int state = (int)Publication.STATE.OPEN) { using (CompraAppContext db = new CompraAppContext()) { List <Publication> publications = db.Publications.Where(x => x.State == state).Include(b => b.Buyer).ToList(); foreach (Publication publication in publications) { publication.NameBuyer = publication.Buyer.Name; } return(publications); } }
public Offer Add(Offer offer) { using (CompraAppContext db = new CompraAppContext()) { offer.Publication = db.Publications.Find(offer.IdPublication); db.Publications.Attach(offer.Publication); offer.Seller = db.Sellers.Find(offer.IdSeller); db.Sellers.Attach(offer.Seller); db.Offers.Add(offer); db.SaveChanges(); return(offer); } }
public IEnumerable <Offer> GetToABuyerByStatus(int idBuyer, int status = 0) { using (CompraAppContext db = new CompraAppContext()) { List <Offer> query = (from o in db.Offers join p in db.Publications on o.IdPublication equals p.Id where o.State == status select o).ToList(); foreach (Offer o in query) { o.Seller = db.Sellers.Find(o.IdSeller); } return(query); } }
public IEnumerable <Offer> GetOffers(int idPublication, int state = 0) { using (CompraAppContext db = new CompraAppContext()) { db.Configuration.LazyLoadingEnabled = false; db.Configuration.ProxyCreationEnabled = false; var offers = db.Offers.Where(o => o.State == state).Where(o => o.IdPublication == idPublication).ToList(); foreach (Offer o in offers) { o.Seller = db.Sellers.Find(o.IdSeller); } return(offers); } }
public bool Delete(int id) { using (CompraAppContext db = new CompraAppContext()) { try { Publication publication = db.Publications.Find(id); db.Publications.Remove(publication); db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } } }
public bool Delete(int id) { using (CompraAppContext db = new CompraAppContext()) { try { Offer offer = db.Offers.Find(id); db.Offers.Remove(offer); db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } } }
public Publication Edit(int id, Publication publication) { using (CompraAppContext db = new CompraAppContext()) { Publication publicationForUpdate = db.Publications.Find(id); if (Exists(publicationForUpdate)) { publicationForUpdate.IdBuyer = publication.IdBuyer; publicationForUpdate.Price = publication.Price; publicationForUpdate.PriceMaxItem = publication.PriceMaxItem; publicationForUpdate.PriceMinItem = publication.PriceMinItem; publicationForUpdate.State = publication.State; publicationForUpdate.StateItem = publication.StateItem; db.Publications.Attach(publicationForUpdate); db.Entry(publicationForUpdate).State = EntityState.Modified; db.SaveChanges(); } return(publicationForUpdate); } }
public Seller Edit(int id, Seller seller) { using (CompraAppContext db = new CompraAppContext()) { Seller sellerForUpdate = db.Sellers.Find(id); if (Exists(sellerForUpdate)) { sellerForUpdate.Address = seller.Address; sellerForUpdate.Email = seller.Email; sellerForUpdate.Name = seller.Name; sellerForUpdate.Latitud = seller.Latitud; sellerForUpdate.Longitud = seller.Longitud; sellerForUpdate.Notifications = seller.Notifications; sellerForUpdate.Phone = seller.Phone; db.Sellers.Attach(sellerForUpdate); db.Entry(sellerForUpdate).State = EntityState.Modified; db.SaveChanges(); } return(sellerForUpdate); } }
public Offer Edit(int id, Offer offer) { using (CompraAppContext db = new CompraAppContext()) { Offer offerForUpdate = db.Offers.Find(id); if (Exists(offerForUpdate)) { offerForUpdate.DeliveryItem = offer.DeliveryItem; offerForUpdate.DeliveryZoneItem = offer.DeliveryZoneItem; offerForUpdate.DescriptionItem = offer.DescriptionItem; offerForUpdate.IdPublication = offer.IdPublication; offerForUpdate.IdSeller = offer.IdSeller; offerForUpdate.PhotoItem = offer.PhotoItem; offerForUpdate.PriceItem = offer.PriceItem; offerForUpdate.State = offer.State; offerForUpdate.StateItem = offer.StateItem; db.Offers.Attach(offerForUpdate); db.Entry(offerForUpdate).State = EntityState.Modified; db.SaveChanges(); } return(offerForUpdate); } }