public async Task <CreateSessionResponse> Handle(CreateSessionCommand message) { var cinema = await _cinemaRepository.GetCinemaById(message.CinemaId); if (cinema == null) { throw new InvalidOperationException($"The cinema with id [{message.CinemaId}] can not be found"); } var film = await _filmRepository.GetFilmById(message.FilmId); if (film == null) { throw new InvalidOperationException($"The film with id [{message.FilmId}] can not be found"); } var screen = cinema.Screens.SingleOrDefault(s => s.Id == message.ScreenId); if (screen == null) { throw new InvalidOperationException($"The screen with id [{message.ScreenId}] can not be found in the cinema [{message.CinemaId}]"); } var session = Session.Create( screen, film, message.Start); await _sessionRepository.AddAsync(session); await _unitOfWork.CommitAsync(); return(new CreateSessionResponse(SessionViewModel.FromSession(session))); }
public async Task AddAsync(CreateSessionDTO newSession) { var session = _mapper.Map <Session>(newSession); await SessionValidAsync(session); await _sessionRepository.AddAsync(session); }
public async Task SaveSessionAsync(Session session) { using (var transaction = Database.BeginTransaction()) { var sessionDao = Mapper.Map <SessionDao>(session); await SessionRepo.AddAsync(sessionDao); await TimeEntryRepo.AddAsync(FinalizeTimeEntries(session)); transaction.Complete(); } }
public async Task <Session> CreateSession(string mobileNumber, Wallet wallet) { var session = new Session { ExpireAt = DateTime.UtcNow.AddMinutes(_sessionSettings.ExpiresInMinutes), CreatedAt = DateTime.UtcNow, Wallet = wallet }; await _sessionRepository.AddAsync(session); await _sessionRepository.SaveAsync(); return(session); }
public async Task <SessionResponse> SaveAsync(Session session) { try { await _sessionRepository.AddAsync(session); await _unitOfWork.CompleteAsync(); return(new SessionResponse(session)); } catch (Exception ex) { return(new SessionResponse($"An error ocurred while saving session: {ex.Message}")); } }
public async Task <IActionResult> Index(SessionViewModel viewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _sessionRepository.AddAsync(new SessionModel() { DateCreated = DateTime.Now, Name = viewModel.Name }); return(RedirectToAction(actionName: nameof(Index))); }
public async Task <(ICommandResult result, IReadOnlyList <IDomainEvent> events)> ExecuteAsync(RequestSession command, CancellationToken cancellationToken = default) { Schedule?schedule; try { schedule = Schedule.Create(command.StartTime, command.EndTime); } catch (ArgumentException e) { var result = new ValidationFailureCommandResult($"Schedule is invalid: {e.Message}."); result.AddValidationError(e.ParamName, e.Message); return(result, DomainEvent.None); } if (command.Speakers.Any()) { var peopleExists = await Task.WhenAll(command.Speakers.Select(async s => { var name = await _personProjectionStore.GetNameAsync(s); return(id: s, exists: name != null); })); ValidationFailureCommandResult?vfcr = null; foreach (var p in peopleExists.Where(p => !p.exists)) { vfcr ??= new ValidationFailureCommandResult("Speakers are invalid: unknown speakers"); vfcr.AddValidationError(nameof(RequestSession.Speakers), $"{p.id} is unknown"); } if (vfcr != null) { return(vfcr, DomainEvent.None); } } var session = new Session(SessionId.New(), command.Speakers, command.Title, command.Description, command.Tags, schedule, SessionStatus.Requested); await _sessionRepository.AddAsync(session).ConfigureAwait(false); return(new SuccessCommandResult(), new[] { new SessionRequested(session.Id) }); }
public async Task <SessionResponse> SaveAsync(int tutorId, Session session) { var existingTutor = await _tutorRepository.FindById(tutorId); if (existingTutor == null) { return(new SessionResponse("Id de tutor no encontrado")); } try { session.TutorId = tutorId; await _sessionRepository.AddAsync(session); await _unitOfWork.CompleteAsync(); return(new SessionResponse(session)); } catch (Exception e) { return(new SessionResponse("Has ocurred an error saving the session " + e.Message)); } }
public async Task RegisterAsync(Category category, DateTime startTime, DateTime finishTime, IEnumerable <IPoint> gpsPoints, string note) { var session = new Session(category, startTime, finishTime, gpsPoints); await _sessionRepository.AddAsync(session); }