Ejemplo n.º 1
0
        private void OpenEditSessionWindow(SessionTemplate template = null)
        {
            SessionAddedRemovedOrChanged = false;
            var window = new Windows.EditSessionTemplateWindow(template);

            window.Show();
            windowOpened = true;
            window.Events().Closing.Subscribe(x => this.windowOpened = false);
            Task.Run(() =>
            {
                var addedRemovedOrChanged = false;

                while (windowOpened)
                {
                    if (window.ViewModel.SessionAddedRemovedOrChanged)
                    {
                        addedRemovedOrChanged = true;
                    }

                    new ManualResetEvent(false).WaitOne(200);
                }

                SessionAddedRemovedOrChanged = addedRemovedOrChanged;//mainwindow is subscribed to this value and will rebuild the tag context menu
            });
        }
Ejemplo n.º 2
0
        public EditSessionViewModel(SessionTemplate template)
        {
            if (template == null)
            {
                TheSessionTemplate = new SessionTemplate()
                {
                    ID = -1, Sessions = new List <TemplateSession>()
                    {
                        new TemplateSession {
                            IsSessionEnd = true, OpeningDay = DayOfTheWeek.Monday, ClosingDay = DayOfTheWeek.Monday
                        }
                    }
                };
                ModifyBtnContent  = "Add";
                WindowTitle       = "Add New Session";
                AddSessionCommand = ReactiveCommand.Create(AddSession);
            }
            else
            {
                template.Sessions  = template.Sessions.OrderBy(x => x.OpeningDay).ThenBy(x => x.OpeningTime).ToList();
                originalTemplate   = template;
                TheSessionTemplate = (SessionTemplate)template;
                ModifyBtnContent   = "Modify";
                WindowTitle        = $"Edit Session {template.Name}";
                IObservable <bool> canAddEditSession = this.WhenAny(x => x.TheSessionTemplate.Sessions, x => x.Value != null);
                AddSessionCommand = ReactiveCommand.Create(AddSession, canAddEditSession);
            }

            ModifyCommand = ReactiveCommand.Create(Modify);

            var canDeleteSession = this.WhenAny(x => x.SelectedSession, x => x.Value != null);

            RemoveSessionCommand = ReactiveCommand.Create(() => TheSessionTemplate.Sessions.Remove(SelectedSession),
                                                          canDeleteSession);
        }
Ejemplo n.º 3
0
        public void Handle(CreateSessionTemplateCommand command)
        {
            SessionTemplate template = new SessionTemplate()
            {
                Name       = command.Name,
                Definition = command.Definition,
            };

            _context.SessionTemplates.Add(template);

            template.Author = command.Author;
        }
Ejemplo n.º 4
0
 void HandleDidAddSessionRecord(string arg1, SessionTemplate arg2)
 {
     Debug.Log("session add detected!!1");
     //chooseSessionButton = new GameObject ();
     if (arg2.name != null)
     {
         Debug.Log("name of session: " + arg2.name);
     }
     else
     {
         Debug.Log("session arg2.name as no name :( ");
     }
     //chooseSessionCanvas.AddComponent (chooseSessionButton);
 }
Ejemplo n.º 5
0
        private async void SetSession_ItemClick(object sender, RoutedEventArgs e)
        {
            IList selectedInstruments = InstrumentsGrid.SelectedItems;
            var   btn = (MenuItem)e.Source;

            int templateID = (int)btn.Tag;

            ApiResponse <List <SessionTemplate> > templates = await _client.GetSessionTemplates().ConfigureAwait(true);

            if (!templates.WasSuccessful)
            {
                await this.ShowMessageAsync("Error", string.Join("\n", templates.Errors)).ConfigureAwait(true);

                return;
            }

            SessionTemplate template = templates.Result.FirstOrDefault(x => x.ID == templateID);

            if (template == null)
            {
                await this.ShowMessageAsync("Error", "Could not find template on the server").ConfigureAwait(true);

                return;
            }

            foreach (Instrument instrument in selectedInstruments)
            {
                instrument.SessionsSource    = SessionsSource.Template;
                instrument.SessionTemplateID = templateID;

                if (instrument.Sessions == null)
                {
                    instrument.Sessions = new List <InstrumentSession>();
                }

                instrument.Sessions.Clear();

                //Add the new sessions
                foreach (TemplateSession ts in template.Sessions)
                {
                    instrument.Sessions.Add(ts.ToInstrumentSession());
                }

                //update the instruments
                await _client.UpdateInstrument(instrument).ConfigureAwait(true);
            }
        }
Ejemplo n.º 6
0
        private void AddSessionToInstrument(Instrument instrument)
        {
            if (instrument.SessionsSource == SessionsSource.Template)
            {
                SessionTemplate template = Context.SessionTemplates.Include(x => x.Sessions)
                                           .FirstOrDefault(x => x.ID == instrument.SessionTemplateID);

                if (template?.Sessions != null)
                {
                    //todo
                    //instrument.InstrumentInstrumentSessions.Sessions = new List<InstrumentSession>();
                    //foreach (TemplateSession s in template.Sessions)
                    //{
                    //    instrument.Sessions.Add(s.ToInstrumentSession());
                    //}
                }
            }
        }
        public EditSessionTemplateWindow(SessionTemplate template)
        {
            InitializeComponent();
            DataContext = this;


            if (template == null)
            {
                TheTemplate = new SessionTemplate {
                    ID = -1
                };
                TheTemplate.Sessions = new List <TemplateSession>();
                ModifyBtn.Content    = "Add";
            }
            else
            {
                template.Sessions = template.Sessions.OrderBy(x => x.OpeningDay).ThenBy(x => x.OpeningTime).ToList();
                _originalTemplate = template;
                TheTemplate       = (SessionTemplate)template.Clone();
                ModifyBtn.Content = "Modify";
            }
        }
        public EditSessionTemplateWindow(SessionTemplate template)
        {
            InitializeComponent();

            ViewModel = new EditSessionViewModel(template);

            this.WhenAnyObservable(x => x.ViewModel.AddSessionCommand)
            .Subscribe(_ => { CollectionViewSource.GetDefaultView(SessionsGrid.ItemsSource).Refresh(); });
            this.WhenAnyObservable(x => x.ViewModel.RemoveSessionCommand)
            .Subscribe(_ => { CollectionViewSource.GetDefaultView(SessionsGrid.ItemsSource).Refresh(); });
            this.WhenAnyObservable(x => x.ViewModel.ModifyCommand)
            .Subscribe(_ =>
            {
                CollectionViewSource.GetDefaultView(SessionsGrid.ItemsSource).Refresh();
                new ManualResetEvent(false).WaitOne(500);
                Close();
            });

            this.WhenAnyObservable(x => x.ViewModel.CloseCommand).Subscribe(x => Close());

            DataContext = ViewModel;

            this.Events().Closing.InvokeCommand(ViewModel.CloseCommand);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Delete a session template
 /// </summary>
 public async Task <ApiResponse <SessionTemplate> > DeleteSessionTemplate(SessionTemplate sessiontemplate) =>
 await _apiClient.DeleteAsync <SessionTemplate>($"/sessiontemplates/{sessiontemplate?.ID}").ConfigureAwait(false);
Ejemplo n.º 10
0
 /// <summary>
 /// Update an existing session template with new values
 /// </summary>
 public async Task <ApiResponse <SessionTemplate> > UpdateSessionTemplate(SessionTemplate sessiontemplate) =>
 await _apiClient.PutAsync <SessionTemplate>("/sessiontemplates", sessiontemplate).ConfigureAwait(false);
Ejemplo n.º 11
0
 public async Task <IActionResult> Put(int id, [FromBody] SessionTemplate value)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 12
0
        public SessionTemplateModule(IMyDbContext context) : base("/sessiontemplates")
        {
            this.RequiresAuthentication();

            var dbSet = context.Set <SessionTemplate>();

            Get("/", async(_, token) => await dbSet.Include(x => x.Sessions).ToListAsync(token).ConfigureAwait(false));

            Post("/", _ =>
            {
                SessionTemplate template = this.BindAndValidate <SessionTemplate>();
                if (ModelValidationResult.IsValid == false)
                {
                    return(this.ValidationFailure());
                }

                dbSet.Add(template);
                context.SaveChanges();

                //return the object with the id after inserting
                return(template);
            });

            Put("/", _ =>
            {
                SessionTemplate newValues = this.BindAndValidate <SessionTemplate>();
                if (ModelValidationResult.IsValid == false)
                {
                    return(this.ValidationFailure());
                }

                //make sure the template we want to update exists
                var template = dbSet.Include(x => x.Sessions).FirstOrDefault(x => x.ID == newValues.ID);
                if (template == null)
                {
                    return(HttpStatusCode.NotFound);
                }

                //update values on the template
                context.UpdateEntryValues(template, newValues);

                //add/remove/update the Sessions collection
                template.Sessions.UpdateCollectionAndElements(newValues.Sessions, context);

                //some instruments may have their sessions based on this template, we need to update them
                var instruments = context.Set <Instrument>()
                                  .Where(x => x.SessionsSource == SessionsSource.Template && x.SessionTemplateID == template.ID).ToList();
                foreach (Instrument i in instruments)
                {
                    context.Set <InstrumentSession>().RemoveRange(i.Sessions);
                    i.Sessions.Clear();

                    foreach (TemplateSession s in template.Sessions)
                    {
                        i.Sessions.Add(s.ToInstrumentSession());
                    }
                }

                context.SaveChanges();

                return(template);
            });

            Delete("/{Id:int}", parameters =>
            {
                //It's possible to delete
                int id       = parameters.Id;
                var template = dbSet.FirstOrDefault(x => x.ID == id);

                if (template == null)
                {
                    return(HttpStatusCode.NotFound);
                }

                //make sure there are no references to it
                var templateReferenced = context.Set <Instrument>().Any(x => x.SessionTemplateID == id && x.SessionsSource == SessionsSource.Template);
                if (templateReferenced)
                {
                    return(Negotiate
                           .WithModel(new ErrorResponse(
                                          HttpStatusCode.Conflict,
                                          "Can't delete this template because it has instruments assigned to it.", ""))
                           .WithStatusCode(HttpStatusCode.Conflict));
                }

                dbSet.Remove(template);
                context.SaveChanges();
                return(template);
            });
        }
 void HandleDidAddSessionRecord(string arg1, SessionTemplate arg2)
 {
     Debug.Log ("session add detected!!1");
     //chooseSessionButton = new GameObject ();
     if (arg2.name != null)
         Debug.Log ("name of session: " + arg2.name);
     else
         Debug.Log ("session arg2.name as no name :( ");
     //chooseSessionCanvas.AddComponent (chooseSessionButton);
 }