Exemple #1
0
        public IHttpActionResult GetAccomodation(int id)
        {
            Accomodation accomodation = db.Accomodations.Find(id);

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

            return(Ok(ViewModelMapper.ToViewModelAccomodations(accomodation)));
        }
Exemple #2
0
        public IHttpActionResult DeleteAccomodation(int id)
        {
            Accomodation accomodation = db.Accomodations.Find(id);

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

            db.Accomodations.Remove(accomodation);
            db.SaveChanges();

            return(Ok(ViewModelMapper.ToViewModelAccomodations(accomodation)));
        }
Exemple #3
0
        public IHttpActionResult PostAccomodation(AccomodationViewModel accomodationViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Client c = db.Clients.SingleOrDefault(x => x.FirstName + " " + x.LastName == accomodationViewModel.ClientName);

            if (c == null)
            {
                string[] parts     = accomodationViewModel.ClientName.Split(' ');
                Client   newClient = new Client()
                {
                    FirstName = parts.FirstOrDefault(), LastName = parts.LastOrDefault()
                };
                c = db.Clients.Add(newClient);
            }

            Accomodation accomodation = ViewModelMapper.ToModelAccomodations(accomodationViewModel);

            accomodation.Client = c;
            db.Accomodations.Add(accomodation);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = accomodation.AccomodationId }, ViewModelMapper.ToViewModelAccomodations(accomodation)));
        }
Exemple #4
0
 // GET: api/AccomodationsApi
 public List <AccomodationViewModel> GetAccomodations()
 {
     return(db.Accomodations.OrderByDescending(x => x.AccomodationId).ToList().Select(x => ViewModelMapper.ToViewModelAccomodations(x)).ToList());
 }