Exemple #1
0
        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));
        }
Exemple #2
0
 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;
     }
 }