public IActionResult Apply([FromBody] Models.OpeningApplication application) { var result = _dataSource.Openings.Apply(application); _dataSource.CommitTransaction(); return(Ok(result)); }
/// <summary> /// The participant is apply for the opening. /// </summary> /// <param name="application"></param> /// <param name="participant"></param> /// <returns></returns> public Models.Opening Apply(Models.OpeningApplication application, Models.Participant participant = null) { if (application == null) { throw new ArgumentNullException(nameof(application)); } var userId = this.GetUserId(); var participantId = participant?.Id ?? this.GetParticipantId() ?? throw new NotAuthorizedException(); var eparticipant = this.Find <Participant>((set) => set.Include(p => p.Attributes).ThenInclude(a => a.Attribute).SingleOrDefault(p => p.Id == participantId)) ?? throw new NotAuthorizedException(); var eopening = this.Find((set) => set .Include(o => o.Participants).ThenInclude(op => op.Participant) .Include(o => o.Questions).ThenInclude(oq => oq.Question) .Include(o => o.Criteria).ThenInclude(c => c.Criteria) .Include(o => o.Activity).ThenInclude(a => a.Event) .SingleOrDefault(o => o.Id == application.OpeningId)); if (Convert.ToBase64String(eopening.RowVersion) != application.RowVersion) { throw new InvalidOperationException($"The opening has been updated recently. Please resync your version before applying."); // TODO: Resource file for text. } return(Apply(eopening, eparticipant, application.Answers?.ToArray())); }