public async Task <TrainingCampResponse> UpdateAsync(int id, TrainingCamp trainingCamp) { var existingTrainingCamp = await _trainingCampRepository.FindByIdAsync(id); if (existingTrainingCamp == null) { return(new TrainingCampResponse("TrainingCamp not found.")); } existingTrainingCamp.Title = trainingCamp.Title; existingTrainingCamp.StartDate = trainingCamp.StartDate; existingTrainingCamp.EndDate = trainingCamp.EndDate; existingTrainingCamp.SpecializationID = trainingCamp.SpecializationID; existingTrainingCamp.CoachID = trainingCamp.CoachID; try { _trainingCampRepository.Update(existingTrainingCamp); await _unitOfWork.CompleteAsync(); return(new TrainingCampResponse(existingTrainingCamp)); } catch (Exception ex) { // Do some logging stuff return(new TrainingCampResponse($"An error occurred when updating the trainingCamp: {ex.Message}")); } }
public async Task <TrainingCampResponse> SaveAsync(TrainingCamp trainingCamp, int[] participantStudentsIDs, SaveLectureResource[] lectures) { try { using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { await _trainingCampRepository.AddAsync(trainingCamp); await _unitOfWork.CompleteAsync(); await _trainingCampRepository.AddParticipantStudent(participantStudentsIDs, trainingCamp); await _unitOfWork.CompleteAsync(); await _lectureService.addLecturerCoaches(lectures, trainingCamp); scope.Complete(); } return(new TrainingCampResponse(trainingCamp)); } catch (Exception ex) { // Do some logging stuff return(new TrainingCampResponse($"An error occurred when saving the trainingCamp: {ex.Message}")); } }
public void TestMethod1() { Adventurer memberA = TrainingCamp.trainAdventurer("Archer"); Adventurer memberB = TrainingCamp.trainAdventurer("Warrior"); Assert.AreEqual(memberA.getType(), "Archer"); Assert.AreEqual(memberB.getType(), "Warrior"); }
public static void TestFunction() { Adventurer memberA = TrainingCamp.trainAdventurer("Archer"); Adventurer memberB = TrainingCamp.trainAdventurer("Warrior"); Assert.AreEqual(memberA.getType(), "Archer"); Assert.AreEqual(memberB.getType(), "Warrior"); Console.ReadLine(); }
/// <summary> /// Initializes all buildings that belongs to this town. /// </summary> /// <returns>Array of buildings for the building tree.</returns> public Building[] InitializeTownBuildings() { Building[] buildings = new Building[12]; buildings[0] = new TownHall(); buildings[1] = new Pallisade(); buildings[2] = new Temple(); buildings[3] = new DragonTower(); buildings[4] = new TrollCave(); buildings[5] = new Marketplace(); buildings[6] = new BeastRidersGuild(); buildings[7] = new CernianCamp(); buildings[8] = new TrainingCamp(); buildings[9] = new MageTower(); buildings[10] = new WarriorsCamp(); buildings[11] = new Workshop(); return(buildings); }
public async Task <CoachAttendanceResponse> addLecturerCoaches(SaveLectureResource[] lectures, TrainingCamp trainingCamp) { try { await _lectureRepository.addLecturerCoaches(lectures, trainingCamp); await _unitOfWork.CompleteAsync(); return(new CoachAttendanceResponse()); } catch (Exception ex) { return(new CoachAttendanceResponse($"An error occurred when saving the lecture coaches: {ex.Message}")); } }
/// <summary> /// Creates a success response. /// </summary> /// <param name="trainingCamp">Saved trainingCamp.</param> /// <returns>Response.</returns> public TrainingCampResponse(TrainingCamp trainingCamp) : this(true, string.Empty, trainingCamp) { }
private TrainingCampResponse(bool success, string message, TrainingCamp trainingCamp) : base(success, message) { TrainingCamp = trainingCamp; }
public void Update(TrainingCamp trainingCamp) { _context.TrainingCamp.Update(trainingCamp); }
public async Task <IEnumerable <ParticipantStudents> > AddParticipantStudent(int[] participantStudentsIDs, TrainingCamp trainingCamp) { foreach (int x in participantStudentsIDs) { var student = _context.Student.FirstOrDefault(s => s.StudentId == x); _context.ParticipantStudents.Add(new ParticipantStudents { Student = student, TrainingCamp = trainingCamp }); } return(await _context.ParticipantStudents .Where(tr => tr.TrainingCampID == trainingCamp.TrainingCampID) .ToListAsync()); }
public async Task AddAsync(TrainingCamp trainingCamp) { await _context.TrainingCamp.AddAsync(trainingCamp); }
public void Remove(TrainingCamp trainingCamp) { _context.TrainingCamp.Remove(trainingCamp); }
public async Task <IEnumerable <CoachAttendance> > addLecturerCoaches(SaveLectureResource[] lectures, TrainingCamp trainingCamp) { var lect = trainingCamp.Lectures; for (int i = 0; i < lect.Count; i++) { foreach (int c in lectures[i].CoachIDs) { var coach = _context.Coach.FirstOrDefault(cc => cc.CoachID == c); _context.CoachAttendance.Add( new CoachAttendance { Coach = coach, Lecture = lect[i] }); } } return(await _context.CoachAttendance.ToListAsync()); }