예제 #1
0
        /// <summary>
        /// Creating a new event
        /// </summary>
        /// <returns>Result of event creation</returns>
        public async Task EventCreate()
        {
            if (string.IsNullOrEmpty(CurrentMapEvent.Name) || StartDate == null || (EndDate == null && IsNotAllDay))
            {
                await(new MessageDialog("Не заполнено одно из обязательных полей", "Ошибка создания нового события")).ShowAsync();

                return;
            }

            if (!IsNotAllDay)
            {
                EndTime = TimeSpan.Parse("23:59");
                EndDate = StartDate;
            }

            if (CurrentMapEvent.Start > CurrentMapEvent.End)
            {
                await(new MessageDialog("Дата начала не может быть позже даты окончания события", "Ошибка создания нового события")).ShowAsync();

                return;
            }

            CurrentMapEvent.UpdateAt = DateTime.Now;
            CurrentMapEvent.IsDelete = false;

            if (CurrentMapEvent.Location == null)
            {
                CurrentMapEvent.Location = string.Empty;
            }

            if (CurrentMapEvent.UserBind == null)
            {
                CurrentMapEvent.UserBind = string.Empty;
            }

            if (string.IsNullOrEmpty(CurrentMapEvent.Description))
            {
                CurrentMapEvent.Description = null;
            }

            if (string.IsNullOrEmpty(CurrentMapEvent.UserBind))
            {
                CurrentMapEvent.UserBind = null;
            }

            if (string.IsNullOrEmpty(CurrentMapEvent.Location))
            {
                CurrentMapEvent.Location = null;
            }

            using (MapEventContext db = new MapEventContext())
            {
                db.MapEvents.Add(CurrentMapEvent);
                db.SaveChanges();
            }

            NewMapEventNotification(CurrentMapEvent.Name, CurrentMapEvent.Start);
        }
예제 #2
0
        /// <summary>
        /// Creation of new category
        /// </summary>
        public async void CategoryCreate()
        {
            #region Text boxes

            TextBox name = new TextBox()
            {
                Header          = "Название",
                PlaceholderText = "Название новой категории",
                Margin          = new Thickness(0, 0, 0, 10),
                MaxLength       = 30,
            };

            TextBox description = new TextBox()
            {
                Header          = "Описание",
                PlaceholderText = "Краткое описание категории",
                Margin          = new Thickness(0, 0, 0, 10),
                MaxLength       = 50,
            };

            #endregion

            #region Color box

            ComboBox colors = new ComboBox()
            {
                Header = "Цвет категории",
                Width  = 300,
            };

            Dictionary <string, string> colorsTable = new Dictionary <string, string>()
            {
                { "Красный", "#d50000" },
                { "Розовый", "#E67C73" },
                { "Оранжевый", "#F4511E" },
                { "Жёлтый", "#F6BF26" },
                { "Светло-зелёный", "#33B679" },
                { "Зелёный", "#0B8043" },
                { "Голубой", "#039BE5" },
                { "Синий", "#3F51B5" },
                { "Светло-фиолетовый", "#7986CB" },
                { "Фиолетовый", "#8E24AA" },
                { "Чёрный", "#616161" }
            };

            // building list of colors for choosing
            for (int i = 0; i < colorsTable.Count; i++)
            {
                var brush = GetColorFromString(colorsTable.ElementAt(i).Value);

                // ring of color
                Ellipse colorRing = new Ellipse
                {
                    Fill   = brush,
                    Width  = 16,
                    Height = 16,
                };

                Ellipse innerColorRing = new Ellipse
                {
                    Fill = new SolidColorBrush(new Color()
                    {
                        A = 255, R = 255, G = 255, B = 255
                    }),
                    Width  = 12,
                    Height = 12,
                };

                // item panel with color & name of color
                StackPanel colorBoxItem = new StackPanel();
                colorBoxItem.Orientation = Orientation.Horizontal;

                Grid colorGrid = new Grid();
                colorGrid.Children.Add(colorRing);
                colorGrid.Children.Add(innerColorRing);

                colorBoxItem.Children.Add(colorGrid);
                colorBoxItem.Children.Add(new TextBlock()
                {
                    Text              = $"{colorsTable.ElementAt(i).Key}",
                    Margin            = new Thickness(8, 0, 0, 0),
                    VerticalAlignment = VerticalAlignment.Center
                });

                colors.Items.Add(colorBoxItem);
            }

            #endregion

            // Start selected color is red
            colors.SelectedIndex = 0;

            StackPanel panel = new StackPanel();
            panel.Children.Add(name);
            panel.Children.Add(description);
            panel.Children.Add(colors);

            ContentDialog dialog = new ContentDialog()
            {
                Title             = "Создание новой категории",
                Content           = panel,
                PrimaryButtonText = "Создать",
                CloseButtonText   = "Отложить",
                DefaultButton     = ContentDialogButton.Primary,
            };

            var result = await dialog.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                if (string.IsNullOrEmpty(name.Text) || string.IsNullOrEmpty(description.Text))
                {
                    await(new MessageDialog("Заполните все поля", "Ошибка создания категории")).ShowAsync();
                    CategoryCreate();

                    return;
                }

                Area newArea = new Area()
                {
                    Name        = name.Text,
                    Description = description.Text,
                    Color       = colorsTable.ElementAt(colors.SelectedIndex).Value,
                };

                using (MapEventContext db = new MapEventContext())
                {
                    db.Areas.Add(newArea);
                    db.SaveChanges();
                }

                Button newButton = new Button()
                {
                    BorderBrush = GetColorFromString(colorsTable.ElementAt(colors.SelectedIndex).Value),
                    Content     = newArea,
                    Tag         = newArea.Id,
                };

                MainGridPanel.Children.Add(newButton);
            }
        }