Exemplo n.º 1
0
        public IHttpActionResult PutGuest(long id, GuestContract guest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != guest.PersonalCode)
            {
                return(BadRequest());
            }

            db.Entry(guest.ToInternal()).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 2
0
        public IHttpActionResult PostGuest(GuestContract guest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Guest temp = guest.ToInternal();

            db.GuestSet.Add(temp);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (GuestExists(guest.PersonalCode))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = guest.PersonalCode }, guest));
        }