public IActionResult GetSensibleForUser( [FromHeader(Name = "conference_id")] int conference_id, [FromHeader(Name = "jwttoken")] string jwttoken, [FromRoute] string uid, [FromQuery] string apikey) { // Permission Level Admin if (this.jwtService.PermissionLevelValid(jwttoken, "user") && this.auth.KeyIsValid(apikey)) { Sensible currentSensible = this._context.Sensible.Where(s => s.ConferenceID == conference_id && s.UID == uid && s.Invalid == false).LastOrDefaultAsync().Result; return(this.Ok(currentSensible)); } return(this.Unauthorized()); }
private async Task <int> InsertNewSensibleAsync(Sensible sensible) { List <Sensible> sensibles = this._context.Sensible.Where(se => se.ConferenceID == sensible.ConferenceID && se.UID == sensible.UID).ToList(); if (sensibles.Count() != 0) { foreach (Sensible se in sensibles) { se.Invalid = true; this._context.Entry(se).State = EntityState.Modified; } await this._context.SaveChangesAsync(); } await this._context.Sensible.AddAsync(sensible); try { await this._context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (this._context.Sensible.Any(s => s.ConferenceID == sensible.ConferenceID && s.UID == sensible.UID)) { throw new ArgumentException(); } else { throw new InvalidDataException(); } } var currentSensible = this._context.Sensible.Where(s => s.ConferenceID == sensible.ConferenceID && s.UID == sensible.UID).LastOrDefaultAsync().Result; return(currentSensible.SensibleID); }
public async Task <IActionResult> PutSensible( [FromHeader(Name = "conference_id")] int conference_id, [FromBody] Sensible sensible, [FromQuery] string apikey, [FromHeader(Name = "jwttoken")] string jwttoken) { // Permission Level User if (this.jwtService.PermissionLevelValid(jwttoken, "user") && this.auth.KeyIsValid(apikey)) { Sensible oldSensible = this._context.Sensible.FindAsync(sensible.SensibleID).Result; string responsibleUID = this.jwtService.GetUIDfromJwtKey(jwttoken); History history = new History { ResponsibleUID = responsibleUID, User = this._context.User.FindAsync(responsibleUID).Result, OldValue = oldSensible.ToString(), HistoryType = "Edit" }; oldSensible = sensible; await this._context.History.AddAsync(history); this._context.Entry(oldSensible).State = EntityState.Modified; try { await this._context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(this.Ok()); } return(this.Unauthorized()); }
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()); }