Exemplo n.º 1
0
        public async Task <IActionResult> ChangeRating([FromBody] RatingBody data)
        {
            var userId       = _userManager.GetUserId(HttpContext.User);
            var ScreenStatus = _context.ScreenStatus.Where(u => u.UserId == userId).Where(i => i.ScreenId == data.ScreenId).SingleOrDefault();

            if (ScreenStatus == null)
            {
                return(NotFound());
            }
            int id    = data.ScreenId;
            var image = await _context.Screens.SingleOrDefaultAsync(m => m.ScreenId == id);

            if (data.state == State.Approved)
            {
                ScreenStatus.Status = ScreenStatus.PossibleStatus.Approved;
            }
            else if (data.state == State.NeedsWork)
            {
                ScreenStatus.Status = ScreenStatus.PossibleStatus.NeedsWork;
            }
            else if (data.state == State.Rejected)
            {
                ScreenStatus.Status = ScreenStatus.PossibleStatus.Rejected;
            }

            await _context.SaveChangesAsync();

            return(Json((await _userManager.FindByIdAsync(userId)).ProfileName));
        }
Exemplo n.º 2
0
        public async Task <CookieRating> AddRatings([FromBody] RatingBody ratingBody)
        {
            var token = Request.Headers["Authorization"][0]
                        .Substring("Bearer ".Length);
            var userId = int.Parse(_tokenService.GetClaim(token, "nameid"));
            var role   = _tokenService.GetClaim(token, "role");

            var cookie = await _cookieService.AddRatings(userId, ratingBody.cookieId, ratingBody.rating);

            return(cookie);
        }
        /// <summary>
        /// Create a rating Create a rating for the node with identifier **nodeId**
        /// </summary>
        /// <param name="nodeId">The identifier of a node.</param>
        /// <param name="ratingBodyCreate">For \&quot;myRating\&quot; the type is specific to the rating scheme, boolean for the likes and an integer for the fiveStar.  For example, to \&quot;like\&quot; a file the following body would be used:  &#x60;&#x60;&#x60;JSON   {     \&quot;id\&quot;: \&quot;likes\&quot;,     \&quot;myRating\&quot;: true   } &#x60;&#x60;&#x60; </param>
        /// <param name="fields">A list of field names.  You can use this parameter to restrict the fields returned within a response if, for example, you want to save on overall bandwidth.  The list applies to a returned individual entity or entries within a collection.  If the API method also supports the **include** parameter, then the fields specified in the **include** parameter are returned in addition to those specified in the **fields** parameter. </param>
        /// <returns>RatingEntry</returns>
        public RatingEntry CreateRating(string nodeId, RatingBody ratingBodyCreate, List <string> fields)
        {
            // verify the required parameter 'nodeId' is set
            if (nodeId == null)
            {
                throw new ApiException(400, "Missing required parameter 'nodeId' when calling CreateRating");
            }

            // verify the required parameter 'ratingBodyCreate' is set
            if (ratingBodyCreate == null)
            {
                throw new ApiException(400, "Missing required parameter 'ratingBodyCreate' when calling CreateRating");
            }


            var path = "/nodes/{nodeId}/ratings";

            path = path.Replace("{format}", "json");
            path = path.Replace("{" + "nodeId" + "}", ApiClient.ParameterToString(nodeId));

            var    queryParams  = new Dictionary <String, String>();
            var    headerParams = new Dictionary <String, String>();
            var    formParams   = new Dictionary <String, String>();
            var    fileParams   = new Dictionary <String, FileParameter>();
            String postBody     = null;

            if (fields != null)
            {
                queryParams.Add("fields", ApiClient.ParameterToString(fields));       // query parameter
            }
            postBody = ApiClient.Serialize(ratingBodyCreate);                         // http body (model) parameter

            // authentication setting, if any
            String[] authSettings = new String[] { "basicAuth" };

            // make the HTTP request
            IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);

            if (((int)response.StatusCode) >= 400)
            {
                throw new ApiException((int)response.StatusCode, "Error calling CreateRating: " + response.Content, response.Content);
            }
            else if (((int)response.StatusCode) == 0)
            {
                throw new ApiException((int)response.StatusCode, "Error calling CreateRating: " + response.ErrorMessage, response.ErrorMessage);
            }

            return((RatingEntry)ApiClient.Deserialize(response.Content, typeof(RatingEntry), response.Headers));
        }