Beispiel #1
0
        public async Task <IHttpActionResult> DeleteAsync()
        {
            var store = new VotesStore();

            await store.ResetAsync().ConfigureAwait(false);

            return(this.StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #2
0
        public async Task <IHttpActionResult> PostAsync([FromBody] string vote)
        {
            var store = new VotesStore();
            var added = await store.AddVoteAsync(this.User.Identity.Name, vote).ConfigureAwait(false);

            if (added)
            {
                return(this.StatusCode(HttpStatusCode.NoContent));
            }

            return(this.NotFound());
        }
Beispiel #3
0
        public async Task <IHttpActionResult> GetAsync()
        {
            var store = new VotesStore();

            var result = new JObject();

            foreach (var pair in await store.GetVoteCountByCategoryAsync().ConfigureAwait(false))
            {
                var item = result[pair.Key] = new JObject();
                item["votes"] = new JValue(pair.Value);
                item["uri"]   = "img/" + pair.Key + ".png";
            }

            return(this.Ok(result));
        }