public async Task <IActionResult> PutConference_ApplicationBulkStatus( [FromQuery] string apikey, [FromBody] ChangeCAStatusBulk newstati, [FromHeader(Name = "jwttoken")] string jwttoken, [FromHeader(Name = "conference_id")] int conference_id) { if (this.auth.KeyIsValid(apikey) && this.jwtService.PermissionLevelValid(jwttoken, "admin")) { foreach (string uid in newstati.UIDs) { var thisca = this._context.Conference_Application.Where(ca => ca.ApplicantUID == uid && ca.ConferenceID == conference_id).FirstOrDefault(); var responsibleUID = this.jwtService.GetUIDfromJwtKey(jwttoken); History history = new History { ResponsibleUID = responsibleUID, User = this._context.User.FindAsync(responsibleUID).Result, OldValue = thisca.Status, HistoryType = "Edit" }; thisca.Status = Conference_ApplicationController.StatusToString(newstati.NewStatus); this._context.Entry(thisca).State = EntityState.Modified; try { await this._context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!this.Conference_ApplicationExists(thisca.ApplicantUID, thisca.ConferenceID)) { this.telBot.SendTextMessage($"CA for {thisca.ApplicantUID} and {thisca.ConferenceID} not in Database"); } else { throw; } } } return(this.Ok()); } return(this.Unauthorized()); }
public async Task <IActionResult> PutConference_ApplicationStatus( [FromQuery] string apikey, [FromBody] ChangeCAStatus newstatus, [FromHeader] string jwttoken) { // Permission Level admin if (this.jwtService.PermissionLevelValid(jwttoken, "admin") && this.auth.KeyIsValid(apikey)) { var thisca = this._context.Conference_Application.Where(ca => ca.ApplicantUID == newstatus.UID && ca.ConferenceID == newstatus.ConferenceID).FirstOrDefault(); var responsibleUID = this.jwtService.GetUIDfromJwtKey(jwttoken); History history = new History { ResponsibleUID = responsibleUID, User = this._context.User.FindAsync(responsibleUID).Result, OldValue = thisca.Status, HistoryType = "Edit" }; thisca.Status = Conference_ApplicationController.StatusToString(newstatus.NewStatus); this._context.Entry(thisca).State = EntityState.Modified; try { await this._context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!this.Conference_ApplicationExists(thisca.ApplicantUID, thisca.ConferenceID)) { return(this.NotFound()); } else { throw; } } return(this.Ok()); } return(this.Unauthorized()); }
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)); }
public async Task <IActionResult> PostConference_Application( [FromQuery] string apikey, [FromBody] IncomingApplication application, [FromHeader] string jwttoken) { // Permission Level: User if (this.jwtService.PermissionLevelValid(jwttoken, "user") && this.auth.KeyIsValid(apikey)) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } if (application.Newsletter) { await this.InsertNewNewsletterAsync(this._context.User.FindAsync(application.ApplicantUID).Result); } Sensible sensible = new Sensible { BuFaKCount = application.Count, ConferenceID = application.ConferenceID, Timestamp = DateTime.Now.ToString(), UID = application.ApplicantUID, EatingPreferences = application.Eating, Intolerances = application.Intolerance, SleepingPreferences = application.SleepingPref, Telephone = application.Tel, ExtraNote = application.Note }; var sensibleID = this.InsertNewSensibleAsync(sensible).Result; Conference_Application cf = new Conference_Application { ConferenceID = application.ConferenceID, Conference = await this._context.Conference.FindAsync(application.ConferenceID), ApplicantUID = application.ApplicantUID, User = await this._context.User.FindAsync(application.ApplicantUID), Priority = application.Priority, IsAlumnus = application.IsAlumnus, IsBuFaKCouncil = application.IsBuFaKCouncil, IsHelper = application.IsHelper, Note = application.Note, Timestamp = DateTime.Now.ToString(), Hotel = application.Hotel, Room = application.Room, Status = Conference_ApplicationController.StatusToString(CAStatus.HasApplied), SensibleID = sensibleID, Sensible = this._context.Sensible.FindAsync(sensibleID).Result }; this._context.Conference_Application.Add(cf); User user = this._context.User.Where(u => u.UID == application.ApplicantUID).AsNoTracking().FirstOrDefault(); this.telBot.SendTextMessage($"User Applied - Name {user.Name} {user.Surname}"); try { await this._context.SaveChangesAsync(); } catch (DbUpdateException) { if (this.Conference_ApplicationExists(cf.ApplicantUID, cf.ConferenceID)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } await this.TickUsedForApplicationKey(application.Key, application.ConferenceID); return(this.CreatedAtAction("GetConference_Application", new { id = cf.ConferenceID }, cf)); } return(this.Unauthorized()); }