// NOTE: AddCaseAsync isnt able to delay saving due to needing to query the db in order to get the id, // which is accomplished by saving public async Task <bool> AddCaseAsync(Case targetCase, bool save = true) { try { // Add the case Cases dbCase = _context.Cases.Add(CaseMapper.Map(targetCase)).Entity; await _context.SaveChangesAsync(); // Next, add the caseclient entry for every client foreach (User user in targetCase.Clients) { Caseclient dbCaseclient = _context.Caseclient.Add(new Caseclient { Caseid = dbCase.Caseid, Clientid = user.Id }).Entity; user.Cases.Add(targetCase); await _user.UpdateUserAsync(user, false); dbCase.Caseclient.Add(dbCaseclient); } // Next, add all of the case's appointments, if any foreach (Appointment a in targetCase.Appointments) { await _appointment.AddAppointmentToCaseAsync(targetCase, a, false); } // Finally, add all of the case's notes, if any foreach (Note cn in targetCase.Notes) { await _note.AddNoteToCaseAsync(targetCase, cn, false); } if (save) { await _context.SaveChangesAsync(); } return(true); } catch (Exception e) { return(false); } }
public async Task <bool> AddRole(Role role, bool save = true) { try { _context.Roles.Add(RoleMapper.Map(role)); if (save) { await _context.SaveChangesAsync(); } return(true); } catch (Exception e) { return(false); } }
public async Task <bool> AddUserAsync(User user, bool save = true) { try { Users dbUser = _context.Users.Add(UserMapper.Map(user)).Entity; if (save) { await _context.SaveChangesAsync(); } return(true); } catch (Exception e) { return(false); } }
public async Task <bool> AddCaseStatusAsync(Status caseStatus, bool save = true) { try { _context.Casestatuses.Add(CaseStatusMapper.Map(caseStatus)); if (save) { await _context.SaveChangesAsync(); } return(true); } catch (Exception e) { return(false); } }
public async Task <bool> AddAppointmentToCaseAsync(Case targetCase, Appointment appointment, bool save = true) { try { // First, add the appointment to appointments appointment.CaseId = targetCase.Id; _context.Appointments.Add(AppointmentMapper.Map(appointment)); // Finally, add the appointment to the case model's appointments targetCase.Appointments.Add(appointment); if (save) { await _context.SaveChangesAsync(); } return(true); } catch (Exception e) { return(false); } }
public async Task <bool> AddNoteToCaseAsync(Case targetCase, Note note, bool save = true) { try { // First, add the note note.CaseId = targetCase.Id; _context.Casenotes.Add(CaseNoteMapper.Map(note)); // Finally, update the case model and db targetCase.Notes.Add(note); if (save) { await _context.SaveChangesAsync(); } return(true); } catch (Exception e) { return(false); } }