Beispiel #1
0
        public void UpdateFavoritesById(int favoritesId, FavoritesUpdateModel favoriteToUpdate)
        {
            var entity = _ctx.Favorites.Single(e => e.FavoritesId == favoriteToUpdate.FavoritesId);

            if (entity != null)
            {
                if (favoriteToUpdate.CharacterId != null)
                {
                    entity.CharacterId = (int)favoriteToUpdate.CharacterId;
                }
                if (favoriteToUpdate.PlanetId != null)
                {
                    entity.PlanetId = (int)favoriteToUpdate.PlanetId;
                }
                if (favoriteToUpdate.ShipId != null)
                {
                    entity.ShipId = (int)favoriteToUpdate.ShipId;
                }
                if (favoriteToUpdate.WeaponId != null)
                {
                    entity.ShipId = (int)favoriteToUpdate.WeaponId;
                }
                _ctx.SaveChanges();
            }
        }
Beispiel #2
0
        public IHttpActionResult UpdateFavorites([FromUri] int favoritesId, FavoritesUpdateModel favoritesToUpdate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateFavoritesService();

            service.UpdateFavoritesById(favoritesId, favoritesToUpdate);
            return(Ok());
        }