Exemplo n.º 1
0
        private void Child_Insert(IPollSubmission parent)
        {
            var entity = new MVPollResponse
            {
                OptionSelected   = this.IsOptionSelected,
                PollID           = parent.PollID,
                PollSubmissionID = parent.PollSubmissionID.Value,
                PollOptionID     = this.PollOptionID,
                ResponseDate     = DateTime.UtcNow,
                UserID           = parent.UserID
            };

            this.Entities.MVPollResponses.Add(entity);
            this.Entities.SaveChanges();
            this.PollResponseID = entity.PollResponseID;
        }
Exemplo n.º 2
0
        public void Put([FromBody] Models.PollResponse value)
        {
            IPollSubmission submission = null;

            try
            {
                var authUserID = MyVoteAuthentication.GetCurrentUserID().Value;
                var criteria   = new PollSubmissionCriteria(value.PollID, authUserID);
                submission = this.PollSubmissionFactory.Create(criteria);

                foreach (var item in value.ResponseItems)
                {
                    var response = submission.Responses.Where(_ => _.PollOptionID == item.PollOptionID).Single();
                    response.IsOptionSelected = item.IsOptionSelected;
                }

                submission.Save();
            }
            catch (ValidationException ex)
            {
                string brokenRules = string.Empty;
                if (submission != null)
                {
                    brokenRules = submission.GetBrokenRules().ToString();
                }

                throw new HttpResponseException(
                          new HttpResponseMessage
                {
                    StatusCode     = HttpStatusCode.BadRequest,
                    ReasonPhrase   = ex.Message.Replace(Environment.NewLine, " "),
                    Content        = new StringContent(brokenRules),
                    RequestMessage = Request
                });
            }
            catch (Exception ex)
            {
                throw ex.ToHttpResponseException(Request);
            }
        }