コード例 #1
0
        public IHttpActionResult PutChoice(int id, Choice choice)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != choice.ChoiceId)
            {
                return BadRequest();
            }

            db.Entry(choice).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ChoiceExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
コード例 #2
0
        public IHttpActionResult PostChoice(Choice choice)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var choices = db.Choices.ToList();
            foreach(Choice tempChoice in choices)
            {
                if(tempChoice.YearTermId == choice.YearTermId && tempChoice.StudentId == choice.StudentId)
                {
                    var resp = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                    {
                        Content = new StringContent(string.Format("Student Already Made A Choice")),
                        ReasonPhrase = "Student Already Made A Choice"
                    };
                    throw new HttpResponseException(resp);
                }
            }

            db.Choices.Add(choice);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = choice.YearTermId }, choice);
        }
コード例 #3
0
        public IHttpActionResult PostChoice(Choice choice)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Choices.Add(choice);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = choice.ChoiceId }, choice);
        }
コード例 #4
0
        private bool validChoice(Choice choice)
        {
            // Check for non-duplicate options
            List<int> ChoiceList = new List<int>();
            ChoiceList.Add((int)choice.FirstChoiceOptionId);
            ChoiceList.Add((int)choice.SecondChoiceOptionId);
            ChoiceList.Add((int)choice.ThirdChoiceOptionId);
            ChoiceList.Add((int)choice.FourthChoiceOptionId);

            if (ChoiceList.Count != ChoiceList.Distinct().Count())
            {
                return false;
            }
            return true;
        }
コード例 #5
0
        private bool checkChoices(Choice choice)
        {
            /*
            int result = db.Choices.Where(c => c.StudentId == choice.StudentId
            && c.YearTermId == choice.YearTermId).Count();

            if (result == 0)
            {
                return true;
            }
            return false;
            */
            int termId = getActive();
            int vend = (from vnd in db.Choices
                        where vnd.YearTermId == termId && vnd.StudentId == choice.StudentId
                        select vnd).Count();
            if (vend == 0)
                return true;
            return false;
        }