public bool UpdateOwnerRating(OwnerRatingCreate model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .OwnerRatings .Single(e => e.OwnerRatingId == model.OwnerId); entity.Timeliness = model.Timeliness; entity.Price = model.Price; entity.Availability = model.Availability; return(ctx.SaveChanges() == 1); } }
/// <summary> /// Change an existing OwnerRating in the Database /// </summary> /// <param name="rating">The new OwnerRating, with the same ID, to replace the existing OwnerRating in the Database</param> /// <returns></returns> public IHttpActionResult Put(OwnerRatingCreate rating) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateOwnerRatingService(); if (!service.UpdateOwnerRating(rating)) { return(InternalServerError()); } return(Ok()); }
public bool CreateOwnerRating(OwnerRatingCreate model) { var entity = new OwnerRating() { FKOwnerID = model.OwnerId, Price = model.Price, Availability = model.Availability, Timeliness = model.Timeliness }; using (var ctx = new ApplicationDbContext()) { ctx.OwnerRatings.Add(entity); return(ctx.SaveChanges() == 1); } }