예제 #1
0
 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.");
         }
     }
 }
예제 #2
0
 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.");
         }
     }
 }
예제 #3
0
 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);
     }
 }
예제 #4
0
        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;
        }
예제 #5
0
        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;
            }
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
        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);
            }
        }
예제 #8
0
        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);
            }
        }