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 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."); } } }
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 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); } }
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 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 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 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); } }