Ejemplo n.º 1
0
 public HttpResponseMessage Delete(PollModel pollModel)
 {
     if (ModelState.IsValid && pollModel.PollId > 0)
     {
         pollRepository.Delete(pollModel.PollId);
         return Request.CreateResponse(HttpStatusCode.OK);
     }
     else
     {
         return Request.CreateResponse(HttpStatusCode.BadRequest);
     }
 }
Ejemplo n.º 2
0
        public HttpResponseMessage Post(PollModel pollModel)
        {
            if (ModelState.IsValid)
            {
                Poll o = new Poll();
                Category c = this.categoryRepository.GetById(pollModel.CategoryId);

                o.StartDate = pollModel.StartDate;
                o.EndDate = pollModel.EndDate;
                o.CategoryId = pollModel.CategoryId;
                o.Category = c;
                o.Frequency = (Frequency)pollModel.FrequencyId;
                o.VoteCountPerFrequency = pollModel.VoteCountPerFrequency;
                pollRepository.Save(o);

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, pollModel);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = pollModel.PollId }));
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }