public void UpdateProductRating(string id, RatingDataIn data) { try { // VERIFY int pId; try { pId = (int)_h.Uint(id); } catch(BadRequestException){ throw new NotFoundException(); } var invoker = _h.Authorize(); string user; if (invoker.IsAuth) user = ((PermissionsUtil.Invoker.Auth)invoker).Item.user; else throw new PermissionExceptions.PermissionDenied(); // Rating is valid if(data == null || !(data.rating >= -5 && data.rating <= 5)) throw new BadRequestException(); // ADD RATING Product.rateProduct(pId, user, (int)data.rating); // SIGNAL SUCCESS _h.Success(204); } catch (BadRequestException) { _h.Failure(400); } catch (PermissionExceptions.PermissionDenied) { _h.Failure(403); } catch (PermissionExceptions.AccountBanned) { _h.Failure(403); } catch (NotFoundException) { _h.Failure(404); } catch (ProductExceptions.ArgumentException) { _h.Failure(400); } catch (ProductExceptions.NoSuchProduct) { _h.Failure(404); } catch (Exception) { _h.Failure(500); } }
public void UpdateProductRating(string id, RatingDataIn data) { _product.UpdateProductRating(id, data); }