public IHttpActionResult PutTravelers(int id, Travelers travelers)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != travelers.Id)
            {
                return(BadRequest());
            }

            db.Entry(travelers).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TravelersExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Se agrega un nuevo Viajero al Camino. Se acepta hasta 6 Viajeros.
 /// </summary>
 /// <param name="traveler"> Viajero a agregar</param>
 public void AddTravelers(Traveler traveler)
 {
     if (travelers.Count < 6)
     {
         Travelers.Add(traveler);
     }
 }
        public IActionResult Put(int id, [FromBody] Travelers traveler)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != traveler.TravelerId)
            {
                return(BadRequest());
            }

            _context.Entry(traveler).State = EntityState.Modified;

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TravelerExists(traveler.TravelerId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(new StatusCodeResult(StatusCodes.Status204NoContent));
        }
Ejemplo n.º 4
0
 public void Cancel(string s)
 {
     while (Travelers.Contains(s))
     {
         Travelers.Remove(s);
     }
 }
        public IHttpActionResult GetTravelers(int id)
        {
            Travelers travelers = db.Travelers.Find(id);

            if (travelers == null)
            {
                return(NotFound());
            }

            return(Ok(travelers));
        }
        public HttpResponseMessage Put(int id, [FromBody] Traveler traveler)
        {
            // returning 404 if the entity doesn't exist
            if (Travelers.GetSingle(id) == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            Travelers.Edit(traveler);
            Travelers.Save();
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        public IHttpActionResult PostTravelers(Travelers travelers)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Travelers.Add(travelers);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = travelers.Id }, travelers));
        }
        public HttpResponseMessage GetTravelerByUserIdentity([FromUri] string travelerUserIdentity)
        {
            var traveler = Travelers.FindBy(t => t.TravelerUserIdentity == travelerUserIdentity).SingleOrDefault();

            // Handling the HTTP status codes
            if (traveler != null)
            {
                return(Request.CreateResponse <Traveler>(HttpStatusCode.OK, traveler));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
        }
        public HttpResponseMessage Delete(int id)
        {
            var reservation = Travelers.GetSingle(id);

            // returning 404 if the entity doesn't exist
            if (reservation == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            Travelers.Delete(reservation);
            Travelers.Save();
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Ejemplo n.º 10
0
        public IHttpActionResult DeleteTravelers(int id)
        {
            Travelers travelers = db.Travelers.Find(id);

            if (travelers == null)
            {
                return(NotFound());
            }

            db.Travelers.Remove(travelers);
            db.SaveChanges();

            return(Ok(travelers));
        }
        public IActionResult Get(int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Travelers geek = _context.Travelers.Single(m => m.TravelerId == id);

            if (geek == null)
            {
                return(NotFound());
            }

            return(Ok(geek));
        }
        //[HttpPost]
        //public HttpResponseMessage RegisterForNotifications
        //    ([FromBody]RegisterNotificationsRequest request)
        //{
        //    var traveler = Travelers.FindBy(t => t.TravelerUserIdentity == request.DeviceID).SingleOrDefault();

        //    // Handling the HTTP status codes
        //    if (traveler == null)
        //    {
        //        return Request.CreateResponse(HttpStatusCode.NotFound);
        //    }
        //    else
        //    {
        //        WNSManager.RegisterDevice(request.DeviceID, request.DeviceURI);
        //        return Request.CreateResponse(HttpStatusCode.Created, request);
        //    }
        //}

        public HttpResponseMessage Post([FromBody] Traveler traveler)
        {
            // saving the new order to the database
            Travelers.Add(traveler);
            Travelers.Save();

            AddInitialData(traveler);

            // creating the response, with three key features:
            // 1. the newly saved entity
            // 2. 201 Created status code
            // 3. Location header with the location of the new resource
            var response = Request.CreateResponse(HttpStatusCode.Created, traveler);

            response.Headers.Location = new Uri(Request.RequestUri, traveler.TravelerId.ToString());
            return(response);
        }
        public IActionResult Delete(int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Travelers traveler = _context.Travelers.Single(m => m.TravelerId == id);

            if (traveler == null)
            {
                return(NotFound());
            }

            _context.Travelers.Remove(traveler);
            _context.SaveChanges();

            return(Ok(traveler));
        }
        public IActionResult Post([FromBody] Travelers traveler)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            //var existingUser = from t in _context.Travelers
            //                   where t.Username == traveler.Username
            //                   select t;

            //if (existingUser.Count<Travelers>() > 0)
            //{
            //    return new StatusCodeResult(StatusCodes.Status409Conflict);
            //}


            _context.Travelers.Add(traveler);

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (TravelerExists(traveler.TravelerId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("GetTraveler", new { id = traveler.TravelerId }, traveler));
        }
        public IEnumerable <Traveler> Get()
        {
            var travelers = Travelers.GetAll();

            return(travelers.ToList());
        }
Ejemplo n.º 16
0
 public virtual bool Book(String p)
 {
     Travelers.Add(p);
     return(true);
 }