public async Task <IActionResult> PutRating(int id, PublicApi.v1.DTO.Rating rating) { if (id != rating.Id) { return(BadRequest()); } // check, that the object being used is really belongs to logged in user if (!await _bll.Ratings.BelongsToUserAsync(rating.AppUserId, User.GetUserId())) { return(NotFound()); } _bll.Ratings.Update(RatingMapper.MapFromExternal(rating)); await _bll.SaveChangesAsync(); return(NoContent()); }
public async Task <ActionResult <PublicApi.v1.DTO.Rating> > PostRating(PublicApi.v1.DTO.Rating rating) { // check that the person sending the rating is the logged in user if (rating.AppUserId != User.GetUserId()) { return(StatusCode(403)); } // get the enitity back with attached state id - (- maxint) rating = PublicApi.v1.Mappers.RatingMapper.MapFromBLL( _bll.Ratings.Add(PublicApi.v1.Mappers.RatingMapper.MapFromExternal(rating))); // ef will update its internally tracked entities await _bll.SaveChangesAsync(); // get the updated entity, now with ID from database rating = PublicApi.v1.Mappers.RatingMapper.MapFromBLL( _bll.Ratings.GetUpdatesAfterUOWSaveChanges( PublicApi.v1.Mappers.RatingMapper.MapFromExternal(rating))); return(CreatedAtAction("GetRating", new { id = rating.Id, version = HttpContext.GetRequestedApiVersion().ToString() }, rating)); }