Ejemplo n.º 1
0
        //Edit the Listing function

        public bool EditListing(AuctionBEANS _listingBEAN)
        {
            if (ListingCheck(_listingBEAN.Id) == true)
            {
                Listings update = GetSingularListing(_listingBEAN.Id);
                update.category    = _listingBEAN.categoryId;
                update.description = _listingBEAN.description;
                update.image       = _listingBEAN.image;
                update.priceBuy    = _listingBEAN.priceBuy;
                _context.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
 public HttpResponseMessage postListing(AuctionBEANS newListing)
 {
     if (_listingService.AddListing(newListing) == true)
     {
         HttpResponseMessage response =
             Request.CreateResponse(HttpStatusCode.Created, newListing);
         response.Headers.Location =
             new Uri(Request.RequestUri, "/api/Listing/" + newListing.Id.ToString());
         return(response);
     }
     else
     {
         HttpResponseMessage response =
             Request.CreateResponse(HttpStatusCode.NotAcceptable, newListing);
         return(response);
     }
 }
Ejemplo n.º 3
0
 public HttpResponseMessage putListing(AuctionBEANS listingChange)
 {
     if (_listingService.EditListing(listingChange) == true)
     {
         HttpResponseMessage response =
             Request.CreateResponse(HttpStatusCode.Created, listingChange);
         response.Headers.Location =
             new Uri(Request.RequestUri, "/api/Listing/" + listingChange.Id.ToString());
         return(response);
     }
     else
     {
         HttpResponseMessage response =
             Request.CreateResponse(HttpStatusCode.NotAcceptable, listingChange);
         return(response);
     }
 }
Ejemplo n.º 4
0
        //Delete Listing Functionality
        public bool DeleteListing(AuctionBEANS _listingBEAN)
        {
            bool check = ListingCheck(_listingBEAN.Id);

            if (check == false)
            {
                return(false);
            }
            else
            {
                Listings _doomedList = new Listings();
                _doomedList.description = _listingBEAN.description;
                _doomedList.image       = _listingBEAN.image;
                _doomedList.priceBuy    = _listingBEAN.priceBuy;
                _doomedList.category    = _listingBEAN.categoryId;
                _doomedList.accountId   = _listingBEAN.accountId;
                _doomedList.startDate   = _listingBEAN.startDate;
                _context.Listings.Remove(_doomedList);
                _context.SaveChanges();
                return(true);
            }
        }
Ejemplo n.º 5
0
        //Add new listing funcionality
        public bool AddListing(AuctionBEANS _listingBEAN)
        {
            try
            {
                Listings _newListing = new Listings();
                _newListing.description = _listingBEAN.description;
                _newListing.image       = _listingBEAN.image;
                _newListing.priceBuy    = _listingBEAN.priceBuy;
                _newListing.category    = _listingBEAN.categoryId;
                _newListing.accountId   = _listingBEAN.accountId;
                _newListing.startDate   = _listingBEAN.startDate;
                _context.Listings.Add(_newListing);
                _context.SaveChanges();
                return(true);
            }

            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine
                        ("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                        eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"",
                                          ve.PropertyName,
                                          eve.Entry.CurrentValues.GetValue <object>(ve.PropertyName),
                                          ve.ErrorMessage);
                    }
                }
                return(false);

                throw;
            }
        }