コード例 #1
0
        public UpdateCarsWindow(CarUpdateVM _carUpdateVM)
        {
            InitializeComponent();
            carUpdateVM = _carUpdateVM;

            additional_base64Image = new List <string>();
            FilterVM = new ObservableCollection <FNameViewModel>();
            FillPanel(carUpdateVM);
        }
コード例 #2
0
        async void FillPanel(CarUpdateVM _carUpdateVM)
        {
            FillImages();

            spCars.Children.Clear();
            spCars.Children.Add(new Label {
                Content = "Характеристики авто", FontSize = 25, Margin = new Thickness(20, 15, 30, 15)
            });
            var listComboBox = new List <ComboBox>();
            FilterApiService      service = new FilterApiService();
            List <FNameViewModel> list    = await service.GetFiltersAsync();

            CarApiService apiService = new CarApiService();
            Label         Name       = new Label();

            Name.Content  = "Марка";
            Name.Width    = 90;
            Name.Margin   = new Thickness(20, 15, 30, 15);
            Name.FontSize = 15;
            make.Name     = "Марка";
            make.Width    = 150;
            make.Margin   = new Thickness(5, 15, 10, 15);
            spCars.Children.Add(Name);
            spCars.Children.Add(make);
            FilterVM.Clear();
            FilterVM.AddRange(list);
            models.Name   = "Модель";
            models.Width  = 150;
            models.Margin = new Thickness(5, 15, 10, 15);
            id            = new int[FilterVM.Count];
            foreach (var item in FilterVM)
            {
                if (item.Name == "Модель")
                {
                    foreach (var children in item.Children)
                    {
                        var BoxItem = new ComboBoxItem()
                        {
                            Content = children.Name, TabIndex = children.Id
                        };
                        models.Items.Add(BoxItem);
                        foreach (var value in _carUpdateVM.FilterAdd.IdValue)
                        {
                            if (BoxItem.TabIndex == value)
                            {
                                models.SelectedItem = BoxItem;
                                id[id.Count() - 1]  = BoxItem.TabIndex;

                                FillMake(value);
                            }
                        }
                    }
                }
                models.Width  = 150;
                models.Margin = new Thickness(5, 15, 10, 15);
                models.Tag    = item.Id;
            }
            Name          = new Label();
            Name.Content  = "Модель";
            Name.FontSize = 15;
            Name.Width    = 90;
            Name.Margin   = new Thickness(20, 15, 30, 15);
            spCars.Children.Add(Name);
            models.SelectionChanged += Models_SelectionChanged;
            spCars.Children.Add(models);

            int i = 0;

            foreach (var item in FilterVM)
            {
                string name = item.Name.Replace(" ", "_");

                if (name != ("Модель"))
                {
                    var listValue = new List <string>();
                    Name          = new Label();
                    Name.Content  = item.Name;
                    Name.Width    = 90;
                    Name.Margin   = new Thickness(20, 15, 30, 15);
                    Name.FontSize = 15;
                    ComboBox box = new ComboBox()
                    {
                        TabIndex = i
                    };
                    foreach (var children in item.Children)
                    {
                        var BoxItem = new ComboBoxItem()
                        {
                            Content = children.Name, TabIndex = children.Id
                        };
                        box.Items.Add(BoxItem);
                        foreach (var value in _carUpdateVM.FilterAdd.IdValue)
                        {
                            if (BoxItem.TabIndex == value)
                            {
                                box.SelectedItem = BoxItem;
                                id[int.Parse(box.TabIndex.ToString())] = BoxItem.TabIndex;
                            }
                        }
                    }
                    box.SelectionChanged += Box_FillId;
                    box.Name              = name;
                    box.Width             = 150;
                    box.Margin            = new Thickness(5, 15, 10, 15);
                    box.Tag = item.Id;


                    spCars.Children.Add(Name);
                    spCars.Children.Add(box);
                }
                else
                {
                    continue;
                }
                i++;
            }
            txtCount.Text       = _carUpdateVM.Count.ToString();
            txtPrice.Text       = _carUpdateVM.Price.ToString();
            dpDate.SelectedDate = _carUpdateVM.Date;
        }
コード例 #3
0
        public IActionResult Update([FromBody] CarUpdateVM model)
        {
            if (!ModelState.IsValid)
            {
                var errors = CustomValidator.GetErrorsByModel(ModelState);
                return(BadRequest(errors));
            }
            if (model.MainImage != null)
            {
                string dirName     = "images";
                string dirPathSave = Path.Combine(dirName, model.UniqueName);
                if (!Directory.Exists(dirPathSave))
                {
                    Directory.CreateDirectory(dirPathSave);
                }
                else
                {
                    Directory.Delete(dirPathSave, true);
                    Directory.CreateDirectory(dirPathSave);
                    System.GC.Collect();
                    System.GC.WaitForPendingFinalizers();
                }
                var    bmp       = model.MainImage.FromBase64StringToImage();
                var    imageName = model.UniqueName;
                string fileSave  = Path.Combine(dirPathSave, $"{imageName}");

                var      bmpOrigin  = new System.Drawing.Bitmap(bmp);
                string[] imageNames = { $"50_" + imageName + ".jpg",
                                        $"100_" + imageName + ".jpg",
                                        $"300_" + imageName + ".jpg",
                                        $"600_" + imageName + ".jpg",
                                        $"1280_" + imageName + ".jpg" };

                Bitmap[] imageSave = { ImageWorker.CreateImage(bmpOrigin,   50,  50),
                                       ImageWorker.CreateImage(bmpOrigin,  100, 100),
                                       ImageWorker.CreateImage(bmpOrigin,  300, 300),
                                       ImageWorker.CreateImage(bmpOrigin,  600, 600),
                                       ImageWorker.CreateImage(bmpOrigin, 1280, 1280) };

                for (int i = 0; i < imageNames.Count(); i++)
                {
                    var imageSaveEnd = System.IO.Path.Combine(dirPathSave, imageNames[i]);
                    imageSave[i].Save(imageSaveEnd, System.Drawing.Imaging.ImageFormat.Jpeg);
                }
                if (model.AdditionalImage != null)
                {
                    dirPathSave = Path.Combine(dirName, model.UniqueName, "Photo");
                    if (!Directory.Exists(dirPathSave))
                    {
                        Directory.CreateDirectory(dirPathSave);
                    }
                    for (int i = 0; i < model.AdditionalImage.Count; i++)
                    {
                        bmp      = model.AdditionalImage[i].FromBase64StringToImage();
                        fileSave = Path.Combine(dirPathSave);

                        bmpOrigin = new System.Drawing.Bitmap(bmp);
                        string[] imageNamess = { $"50_{i+1}_" + imageName + ".jpg",
                                                 $"100_{i+1}_" + imageName + ".jpg",
                                                 $"300_{i+1}_" + imageName + ".jpg",
                                                 $"600_{i+1}_" + imageName + ".jpg",
                                                 $"1280_{i+1}_" + imageName + ".jpg" };

                        Bitmap[] imageSaves = { ImageWorker.CreateImage(bmpOrigin,   50,  50),
                                                ImageWorker.CreateImage(bmpOrigin,  100, 100),
                                                ImageWorker.CreateImage(bmpOrigin,  300, 300),
                                                ImageWorker.CreateImage(bmpOrigin,  600, 600),
                                                ImageWorker.CreateImage(bmpOrigin, 1280, 1280) };

                        for (int j = 0; j < imageNamess.Count(); j++)
                        {
                            var imageSaveEnd = System.IO.Path.Combine(dirPathSave, imageNamess[j]);
                            imageSaves[j].Save(imageSaveEnd, System.Drawing.Imaging.ImageFormat.Jpeg);
                        }
                    }
                }
            }
            var car = _context.Cars.SingleOrDefault(p => p.Id == model.Id);

            if (car != null)
            {
                car.Price = model.Price;
                car.Date  = model.Date;
                if (model.Name != "")
                {
                    car.Name = model.Name;
                }
                car.Count      = model.Count;
                car.UniqueName = model.UniqueName;

                _context.SaveChanges();
                return(Ok(car.Id));
            }
            return(BadRequest());
        }