public async Task <IActionResult> PutSingleConferenceApplication( [FromHeader] string jwttoken, [FromBody] Conference_Application conferenceApplication, [FromQuery] string apikey) { if (this.jwtService.PermissionLevelValid(jwttoken, "admin") && this.auth.KeyIsValid(apikey)) { await this.InsertHistoryForCAAsync(conferenceApplication.ApplicantUID, conferenceApplication.ConferenceID, jwttoken); this._context.Entry(conferenceApplication).State = EntityState.Modified; try { await this._context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!this.Conference_ApplicationExists(conferenceApplication.ApplicantUID, conferenceApplication.ConferenceID)) { return(this.NotFound()); } else { throw; } } return(this.Ok()); } return(this.Unauthorized()); }
public async Task <IActionResult> ReRegisterConference_Application( [FromQuery] string apikey, [FromBody] ReRegister reregister, [FromHeader(Name = "jwttoken")] string jwttoken, [FromHeader(Name = "conference_id")] int conferenceID) { // Permission Level Admin if (this.jwtService.PermissionLevelValid(jwttoken, "admin") && this.auth.KeyIsValid(apikey)) { var currentCA = await this._context.Conference_Application.Where(ca => ca.ApplicantUID == reregister.OldUID && ca.ConferenceID == conferenceID && ca.Invalid == false).FirstOrDefaultAsync(); string responsibleUID = this.jwtService.GetUIDfromJwtKey(jwttoken); History history = new History { ResponsibleUID = responsibleUID, User = this._context.User.FindAsync(responsibleUID).Result, OldValue = currentCA.ToString(), HistoryType = "Edit" }; currentCA.Invalid = true; Conference_Application newCA = new Conference_Application { ConferenceID = conferenceID, Conference = this._context.Conference.FindAsync(conferenceID).Result, ApplicantUID = reregister.NewUID, User = this._context.User.FindAsync(reregister.NewUID).Result, }; this._context.Conference_Application.Add(newCA); try { await this._context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!this.Conference_ApplicationExists(newCA.ApplicantUID, newCA.ConferenceID)) { return(this.NotFound()); } else { throw; } } return(this.Ok()); } return(this.Unauthorized()); }
private async Task InsertHistoryForCAAsync(string uid, int conference_id, string jwttoken) { Conference_Application ca = this._context.Conference_Application.Where(c => c.ApplicantUID == uid && c.ConferenceID == conference_id).FirstOrDefault(); History history = new History { OldValue = Newtonsoft.Json.JsonConvert.SerializeObject(ca), ResponsibleUID = this.jwtService.GetUIDfromJwtKey(jwttoken), HistoryType = "edit" }; this._context.Entry(ca).State = EntityState.Detached; this._context.History.Add(history); try { await this._context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } }
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()); }