Exemple #1
0
        private void buttonRequestLayout_Click(object sender, RoutedEventArgs e)
        {
            var currentSiteLayout = (SiteLayout)((Button)sender).DataContext;
            var existingRequests  = logbook.LayoutAccess.ToList().Where(v => v.SiteLayout.id == currentSiteLayout.id);

            if (existingRequests.Count() != 0)  // if private => resend request, if was private, but bow public => getting access
            {
                try
                {
                    var existingRequest = existingRequests.First();
                    SitesCreateEntities.GetContext().LayoutAccess.Remove(existingRequest);
                    SitesCreateEntities.GetContext().SaveChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(
                        ex.Message,
                        "Error",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                    return;
                }
            }
            var newLayoutAccess = new LayoutAccess();

            newLayoutAccess.siteLayoutId = currentSiteLayout.id;
            newLayoutAccess.executerId   = logbook.id;
            if (currentSiteLayout.isPublic)
            {
                newLayoutAccess.haveAccess = true;
            }
            else
            {
                newLayoutAccess.haveAccess = false;
            }
            try
            {
                SitesCreateEntities.GetContext().LayoutAccess.Add(newLayoutAccess);
                SitesCreateEntities.GetContext().SaveChanges();
                MessageBox.Show(
                    newLayoutAccess.haveAccess?"Вы успешно получили права к данному макету!": "Вы успешно запросили права к данному макету",
                    "Success",
                    MessageBoxButton.OK,
                    MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    ex.Message,
                    "Error",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
            }
            finally
            {
                SitesCreateEntities.GetContext().ClearStateAndReloadAll();
                MainTabItem.ExecuteShowPrevPage();
            }
        }
 public SiteLayoutWorkContent(TabItemParent mainTabItem, LayoutAccess layoutAccess, SiteLayout siteLayout) : base(mainTabItem)
 {
     InitializeComponent();
     if (siteLayout == null || layoutAccess == null)
     {
         throw new ArgumentNullException();
     }
     this.DataContext  = this.siteLayout = siteLayout;
     this.layoutAccess = layoutAccess;
     if (!layoutAccess.isOwner)
     {
         buttonSiteLayoutEdit.Visibility = Visibility.Collapsed;
     }
     else
     {
         buttonDenyLayout.Visibility = Visibility.Collapsed;
     }
     Update();
 }
        private void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Вы уверены, что хотите сохранить данные о макете?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                StringBuilder errors = new StringBuilder();

                if (
                    String.IsNullOrWhiteSpace(description.Text)
                    )
                {
                    errors.AppendLine("Вы не заполнили одно или несколько важных полей!");
                }

                if (errors.Length != 0)
                {
                    MessageBox.Show(
                        errors.ToString(),
                        "Error",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                    return;
                }

                if (createFlag)
                {
                    var    uniqueFileName = String.Format(@"{0}.se", Guid.NewGuid());
                    String newFIleName    = $"{Environment.CurrentDirectory}\\{layoutFolder}\\{uniqueFileName}";
                    MainViewModel.CreateScene(newFIleName);
                    siteLayout.fileName = newFIleName;
                    SitesCreateEntities.GetContext().SiteLayout.Add(siteLayout);
                }

                try
                {
                    SitesCreateEntities.GetContext().SaveChanges();
                    if (createFlag)
                    {
                        var newLayoutAccess = new LayoutAccess();
                        newLayoutAccess.isOwner      = true;
                        newLayoutAccess.haveAccess   = true;
                        newLayoutAccess.executerId   = logbook.id;
                        newLayoutAccess.siteLayoutId = siteLayout.id;
                        SitesCreateEntities.GetContext().LayoutAccess.Add(newLayoutAccess);
                        SitesCreateEntities.GetContext().SaveChanges();
                    }
                    MessageBox.Show(
                        "Данные успешно обновлены!",
                        "Success",
                        MessageBoxButton.OK,
                        MessageBoxImage.Information);
                    this.MainTabItem.ExecuteShowPrevPage();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(
                        ex.Message,
                        "Error",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }
        }