public bool RateStore(StoreRateModel model) { if (model.Rating <= 0) { throw _exception.ThrowException(System.Net.HttpStatusCode.BadRequest, "", "Ogiltigt värde för butik betyg."); } var store = _storeRepository.GetStoreDetailById(model.StoreId); if (store == null) { throw _exception.ThrowException(System.Net.HttpStatusCode.BadRequest, "", "Butiken finns inte."); } var storeRating = new StoreRatings { StoreId = model.StoreId, UserId = model.UserId, Rating = model.Rating }; _storeRepository.AddStoreRatings(storeRating); var averageRatings = _storeRepository.GetStoreAverageRatings(model.StoreId); store.Rating = averageRatings; return(_storeRepository.UpdateStoreRating(store)); }
public IHttpActionResult RateStore(long userId, long storeId, StoreRateModel model) { try { model.UserId = userId; model.StoreId = storeId; _storeService.RateStore(model); return(Ok(new { Message = "butik betygsatt framgångsrikt." })); } catch (Exception ex) { _log.ErrorFormat("Error in rating store. Error : {0}", ex.Message); _log.Error(ex); throw; } }