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); }
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); }
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); }
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; }
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; }