// GET: VotingAnswers/Create public ActionResult Create(int?id) { VotingAnswer votingAnswer = new VotingAnswer(); votingAnswer.VotingId = id.GetValueOrDefault(); return(View(votingAnswer)); }
public ActionResult DeleteConfirmed(int id) { VotingAnswer votingAnswer = db.VotingAnswers.Find(id); db.VotingAnswers.Remove(votingAnswer); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult> DeleteConfirmed(int id) { VotingAnswer votingAnswer = await db.VotingAnswer.FindAsync(id); db.VotingAnswer.Remove(votingAnswer); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit([Bind(Include = "VotingAnswerId,AnswerText")] VotingAnswer votingAnswer) { if (ModelState.IsValid) { db.Entry(votingAnswer).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(votingAnswer)); }
public ActionResult Edit([Bind(Include = "VotingAnswerId,VotingId,AnswerText")] VotingAnswer votingAnswer) { if (ModelState.IsValid) { db.Entry(votingAnswer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.VotingId = new SelectList(db.Votings, "VotingId", "Name", votingAnswer.VotingId); return(View(votingAnswer)); }
public async Task <ActionResult> Create([Bind(Include = "VotingAnswerId,AnswerText,VotingId")] VotingAnswer votingAnswer) { if (ModelState.IsValid) { db.VotingAnswer.Add(votingAnswer); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(votingAnswer)); }
public ActionResult Create([Bind(Include = "VotingAnswerId,VotingId,AnswerText")] VotingAnswer votingAnswer) { if (ModelState.IsValid) { db.VotingAnswers.Add(votingAnswer); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.VotingId = new SelectList(db.Votings, "VotingId", "Name", votingAnswer.VotingId); return(View(votingAnswer)); }
// public async Task<ActionResult> Edit(int? id) public ActionResult CreateAnswer(int?id) {//przerobić na przeładowane create if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } VotingAnswer votingAnswer = new VotingAnswer(); votingAnswer.VotingId = id.GetValueOrDefault(); return(View(votingAnswer)); //return RedirectToAction("Create", "VotingAnswers", id); }
// GET: VotingAnswers/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } VotingAnswer votingAnswer = await db.VotingAnswer.FindAsync(id); if (votingAnswer == null) { return(HttpNotFound()); } return(View(votingAnswer)); }
// GET: VotingAnswers/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } VotingAnswer votingAnswer = db.VotingAnswers.Find(id); if (votingAnswer == null) { return(HttpNotFound()); } return(View(votingAnswer)); }
// GET: VotingAnswers/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } VotingAnswer votingAnswer = db.VotingAnswers.Find(id); if (votingAnswer == null) { return(HttpNotFound()); } ViewBag.VotingId = new SelectList(db.Votings, "VotingId", "Name", votingAnswer.VotingId); return(View(votingAnswer)); }
public async Task <IActionResult> PostVote( [FromHeader(Name = "conference_id")] int conference_id, [FromHeader(Name = "jwttoken")] string jwttoken, [FromQuery] string apikey, [FromBody] VoteObject voteObject) { if (!this.jwtService.PermissionLevelValid(jwttoken, "user") || !this.auth.KeyIsValid(apikey)) { return(this.Unauthorized()); } Conference_Application application = await this._context.Conference_Application.FindAsync(conference_id, this.jwtService.GetUIDfromJwtKey(jwttoken)); if (application == null || application.Status != Conference_ApplicationController.StatusToString(CAStatus.IsAttendee)) { return(this.Unauthorized()); // user is not attending the conference } VotingQuestion question = await this._context.VotingQuestion.FindAsync(voteObject.QuestionID); if (!this.ModelState.IsValid || question == null || !question.IsOpen || question.ResolvedOn != null) { return(this.BadRequest(this.ModelState)); // modelState not valid, question does not exist or is not open for voting } if (question.IsSecret && (application.Priority != 1 || application.IsAlumnus || application.IsBuFaKCouncil || application.IsHelper)) { return(this.BadRequest("Only user with priority 1 are allowed to vote")); } int councilID = this.jwtService.GetCouncilfromJwtKey(jwttoken); VotingAnswer currentAnswer = this._context.VotingAnswer.Where(x => x.CouncilID == councilID && x.QuestionID == voteObject.QuestionID).FirstOrDefault(); if (currentAnswer == null) { VotingAnswer votingAnswer = new VotingAnswer() // create new votingAnswer { CouncilID = councilID, Priority = application.Priority, QuestionID = voteObject.QuestionID, Vote = question.IsSecret ? string.Empty : voteObject.Vote, }; this._context.VotingAnswer.Add(votingAnswer); if (question.IsSecret) { // add the vote to the secret question VotingQuestionsController.AddVoteToQuestion(question, VotingQuestionsController.GetVoteType(voteObject.Vote)); this._context.Update(question); } await this._context.SaveChangesAsync(); return(this.CreatedAtAction("PostVote", new { id = votingAnswer.AnswerID }, votingAnswer)); } if (currentAnswer.Priority < application.Priority || question.IsSecret) { return(this.Conflict()); // there is already a vote from that council (with a higher priority or its a secret question) } currentAnswer.Vote = voteObject.Vote; // update the current Answer to the new vote currentAnswer.Priority = application.Priority; this._context.Update(currentAnswer); await this._context.SaveChangesAsync(); return(this.CreatedAtAction("PostVote", new { id = currentAnswer.AnswerID }, currentAnswer)); }