예제 #1
0
        public IActionResult Post([FromBody] VacationOffer vacationOffer)
        {
            //Returning id of added vacation offer
            int id = _vacationOfferService.Post(vacationOffer);

            return(Ok(id));
        }
        /// <summary>
        /// Implementation of Put method
        /// </summary>
        /// <param name="vacationOffer"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool Put(VacationOffer vacationOffer, int id)
        {
            //Searching for offer with given id
            var offerToUpdate = offers.Where(x => x.Id.Equals(id)).SingleOrDefault();

            if (offerToUpdate == null)
            {
                return(false);
            }

            //Updating data
            offerToUpdate.Country     = vacationOffer.Country;
            offerToUpdate.HotelName   = vacationOffer.HotelName;
            offerToUpdate.HotelRating = vacationOffer.HotelRating;
            offerToUpdate.Days        = vacationOffer.Days;
            offerToUpdate.Cost        = vacationOffer.Cost;

            return(true);
        }
        /// <summary>
        /// Implementation of Post method
        /// </summary>
        /// <param name="vacationOffer"></param>
        /// <returns></returns>
        public int Post(VacationOffer vacationOffer)
        {
            //Assigning next id
            int id;

            if (offers.Count() == 0)
            {
                id = 0;
            }
            else
            {
                id = offers.Max(x => x.Id) + 1;
            }

            vacationOffer.Id = id;

            //Adding an offer
            offers.Add(vacationOffer);

            return(id);
        }
예제 #4
0
        public IActionResult Put([FromBody] VacationOffer vacationOffer, [FromRoute] int id)
        {
            //Checking if id given in body matches the id from the route
            if (id != vacationOffer.Id)
            {
                return(Conflict("Given indexes are not equal"));
            }
            else
            {
                //Checking if the update was performed successfully
                var isUpdateSuccessful = _vacationOfferService.Put(vacationOffer, id);

                //Returning adequate status
                if (isUpdateSuccessful)
                {
                    return(NoContent());
                }
                else
                {
                    return(NotFound());
                }
            }
        }