Beispiel #1
0
        public async Task <IEnrolleeNote> UpdateEnrolleeNoteAsync(int enrolleeId, IEnrolleeNote newNote)
        {
            var enrollee = await _context.Enrollees
                           .Include(e => e.AccessAgreementNote)
                           .Where(e => e.Id == enrolleeId)
                           .SingleOrDefaultAsync();

            IEnrolleeNote dbNote = null;

            if (newNote.GetType() == typeof(AccessAgreementNote))
            {
                dbNote = enrollee.AccessAgreementNote;
            }
            else
            {
                throw new ArgumentException("Enrollee note type is not recognized, or not allowed.");
            }

            if (dbNote != null)
            {
                if (newNote.Note == null)
                {
                    _context.Remove(dbNote);
                }
                else
                {
                    dbNote.Note     = newNote.Note;
                    dbNote.NoteDate = DateTimeOffset.Now;
                    _context.Update(dbNote);
                }
            }
            else if (newNote != null)
            {
                newNote.EnrolleeId = enrolleeId;
                _context.Add(newNote);
            }

            var updated = await _context.SaveChangesAsync();

            if (updated < 1)
            {
                throw new InvalidOperationException($"Could not update the enrollee note.");
            }
            else
            {
                await _businessEventService.CreateNoteEventAsync(enrolleeId, "Updated Limits and Conditions Note: " + newNote.Note);
            }

            return(newNote);
        }
Beispiel #2
0
        public Task <IEnrolleeNote> UpdateEnrolleeNoteAsync(int enrolleeId, IEnrolleeNote newNote)
        {
            // TODO add proper tests, but need test spike
            IEnrolleeNote updatedNote = null;

            if (this.GetHolder <int, Enrollee>().ContainsKey(enrolleeId))
            {
                var enrollee = this.GetHolder <int, Enrollee>()[enrolleeId];

                if (newNote.GetType() == typeof(AccessAgreementNote))
                {
                    enrollee.AccessAgreementNote = (AccessAgreementNote)newNote;
                }
                else
                {
                    throw new ArgumentException("Enrollee note type is not recognized, or not allowed.");
                }

                updatedNote = newNote;
            }

            return(Task.FromResult(updatedNote));
        }