예제 #1
0
		public HttpResponseMessage DeleteReview( int id ) {
			CrudResult result = new CrudResult();
			using ( Repo repo = new Repo() ) {
				result = repo.DeleteReview( id );
				string json = JsonConvert.SerializeObject( result, jss );
				HttpResponseMessage msg = Request.CreateResponse( HttpStatusCode.OK, json );
				return msg;
			}
		}
예제 #2
0
		public HttpResponseMessage AddRestaurant( Restaurant restaurant ) {
			CrudResult result = new CrudResult();
			using ( Repo repo = new Repo() ) {
				result = repo.SaveRestaurant( restaurant );
				string json = JsonConvert.SerializeObject( result, jss );
				HttpResponseMessage msg = Request.CreateResponse( HttpStatusCode.OK, json );
				return msg;
			}
		}
예제 #3
0
		public CrudResult SaveRestaurant( Restaurant restaurant ) {
			CrudResult result = new CrudResult();

			if ( restaurant.Id > 0 )
				ctx.Entry( restaurant ).State = EntityState.Modified;
			else
				ctx.Restaurant.Add( restaurant );

			try {
				ctx.SaveChanges();
				result.Success = true;
			}
			catch ( DbEntityValidationException ex ) {
				result.Errors = ex.EntityValidationErrors;
				result.Success = false;
			}

			return result;
		}
예제 #4
0
		public CrudResult DeleteReview( int id ) {
			CrudResult result = new CrudResult();
			try {
				Review delete = ctx.Review.Where( r => r.Id == id ).Single();
				ctx.Review.Remove( delete );
				ctx.SaveChanges();
				result.Success = true;
			}
			catch ( DbEntityValidationException ex ) {
				result.Errors = ex.EntityValidationErrors;
				result.Success = false;
			}

			return result;
		}