public async Task <IActionResult> AddSession(SessionBindingModel sessionBindingModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }

            var speaker = await _speakerService.GetSpeakerByIdAsync(sessionBindingModel.SpeakerId);

            if (speaker == null)
            {
                return(BadRequest("Could not find the speaker"));
            }

            var sessionModel = new SessionModel
            {
                Title        = sessionBindingModel.Title,
                SpeakerModel = speaker
            };

            var successful = await _sessionService.AddSessionAsync(sessionModel);

            if (!successful)
            {
                return(BadRequest("Could not add the session."));
            }

            return(RedirectToAction("Index"));
        }
Example #2
0
        private async Task <bool> SaveChangesAsync()
        {
            try
            {
                if (this.CurrentSession != null)
                {
                    var session = this.CurrentSession;
                    if (_editView.IsAddingNew && this.CurrentSession != _editView.CurrentAddItem)
                    {
                        return(true);
                    }
                    if (_hasChanges || _editView.IsAddingNew)
                    {
                        if (!this.Validate())
                        {
                            return(false);
                        }

                        _isChanging      = true;
                        this.IsBusy      = true;
                        session.TrackIds = new ObservableCollection <int>();
                        foreach (var uitrack in _uiTrackList)
                        {
                            if (uitrack.IsChecked)
                            {
                                session.TrackIds.Add(uitrack.Track.Id);
                            }
                        }

                        if (_editView.IsAddingNew)
                        {
                            var newSession = await _sessionService.AddSessionAsync(session);

                            session.SessionBaseId = newSession.SessionBaseId;
                            _editView.CommitNew();
                        }
                        else
                        {
                            await _sessionService.UpdateSessionAsync(session);
                        }
                        session.Speaker1  = (from s in _speakerList where s.Id == session.Speaker1Id select s).FirstOrDefault();
                        session.Speaker2  = (from s in _speakerList where s.Id == session.Speaker2Id select s).FirstOrDefault();
                        this.CurrentState = NORMAL_STATE;
                        this.IsBusy       = false;
                        _isChanging       = false;
                        _hasChanges       = false;
                    }
                    this.CurrentSession.PropertyChanged -= this.OnSessionPropertyChanged;
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #3
0
        public async Task <IActionResult> Create(CreateSessionModel createSession)
        {
            var errorMessage = String.Empty;

            if (!createSession.ValidateCreateModel(out errorMessage))
            {
                ModelState.AddModelError(string.Empty, errorMessage);
                return(View(await SessionService.GetCreateSessionAsync(createSession.Id)));
            }
            await SessionService.AddSessionAsync(createSession);

            return(RedirectToAction(nameof(Index)));
        }
Example #4
0
        public async Task <int> Add([FromBody] SessionDto sessionDto)
        {
            var session = _mapper.Map <Session>(sessionDto);

            return(await _sessionService.AddSessionAsync(session));
        }