Beispiel #1
0
        public IHttpActionResult PutUserAirport(string id, UserAirport userAirport)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userAirport.UserId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #2
0
        public IHttpActionResult GetUserAirport(string id)
        {
            UserAirport userAirport = db.UserAirports.Find(id);

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

            return(Ok(userAirport));
        }
Beispiel #3
0
        public async Task <UserAirport> RemoveUserAirportAsync(UserAirport userAirport)
        {
            var removedUserAirport = context.UserAirport.Remove(userAirport);

            var result = await context.SaveChangesAsync();

            if (result < 1)
            {
                return(null);
            }

            return(removedUserAirport.Entity);
        }
Beispiel #4
0
        public IHttpActionResult DeleteUserAirport(string id)
        {
            UserAirport userAirport = db.UserAirports.Find(id);

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

            db.UserAirports.Remove(userAirport);
            db.SaveChanges();

            return(Ok(userAirport));
        }
Beispiel #5
0
        public async Task <UserAirport> AddUserAirportAsync(User user, Airport airport)
        {
            var userAirport = new UserAirport
            {
                User    = user,
                Airport = airport
            };

            var entityEntry = await context.UserAirport.AddAsync(userAirport);

            var result = await context.SaveChangesAsync();

            if (result < 1)
            {
                return(null);
            }

            return(entityEntry.Entity);
        }
Beispiel #6
0
        public IHttpActionResult PostUserAirport(UserAirport userAirport)
        {
            db.UserAirports.Add(userAirport);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (UserAirportExists(userAirport.UserId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = userAirport.UserId }, userAirport));
        }