Ejemplo n.º 1
0
        public IActionResult Update(BrandCar brand)
        {
            var result = _brandservice.UpdateToSystem(brand);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Ejemplo n.º 2
0
 public IResult UpdateToSystem(BrandCar brand)
 {
     if (brand.BrandName.Length >= 2)
     {
         _branddal.Update(brand);
         return(new SuccessResult(Messages.BrandUpdated));
     }
     else
     {
         return(new ErrorResult(Messages.BrandNameError));
     }
 }
Ejemplo n.º 3
0
        public Models.BrandCar Create(ViewModel.BrandCreateViewModel model)
        {
            var saveImage = new SaveImage();
            string fileName = Guid.NewGuid().ToString();
            string urlImage = saveImage.ResizeAndSave(fileName, model.ImageUploaded.InputStream, Size.Small, false);

            var brand = new BrandCar()
            {
                Name = model.Name,
                Description = model.Description,
                UrlImage = urlImage
            };
            _brands.Create(brand);
            _context.SaveChanges();
            return brand;
        }
Ejemplo n.º 4
0
 private static void CreateBrand(object parameter)
 {
     try
     {
         using (Cars_DB db = new Cars_DB())
         {
             BrandCar brand = (BrandCar)parameter;
             brand.Logotype   = ViewModelService.Resolve <WorkBrandWindowViewModel>().Logotype;
             brand.Type_Image = ViewModelService.Resolve <WorkBrandWindowViewModel>().ImageType;
             db.BrandCar.Add(brand);
             db.SaveChanges();
             MessageBox.Show("Брэнд успешно добавлен");
         }
     }
     catch (Exception exp)
     {
         MessageBox.Show(exp.Message);
     }
 }
Ejemplo n.º 5
0
        public void GetBrand()
        {
            WebClient client    = new WebClient();
            string    valueJson = client.DownloadString("https://developers.ria.com/auto/categories/1/marks?api_key=Pqu4ZfbPPj9AtraazzTCStUXHKzgvKPDK9L6GZeG");

            brandCarList = JsonConvert.DeserializeObject <List <Request.BrandCar> >(valueJson);

            foreach (var item in brandCarList)
            {
                BrandCar BrandCar = new BrandCar();
                BrandCar.Value.Id   = item.Value;
                BrandCar.Value.Name = item.Name;
                BrandCar.ValueId    = item.Value;

                brandCarListResponse.Add(BrandCar);
            }

            jsonResponse = JsonConvert.SerializeObject(brandCarListResponse);
            File.AppendAllText(@"C:\jsonBrand.txt", jsonResponse, UTF32Encoding.Default);
        }
Ejemplo n.º 6
0
        private static void UpdateBrand(object parameter)
        {
            try
            {
                using (Cars_DB db = new Cars_DB())
                {
                    BrandCar brand = (BrandCar)parameter;

                    if (brand.Brand_Name != ViewModelService.Resolve <WorkBrandWindowViewModel>().Brand_Name_For_Update)
                    {
                        db.BrandCar.Add(brand);
                        foreach (var p in db.Cars.ToList())
                        {
                            if (ViewModelService.Resolve <WorkBrandWindowViewModel>().Brand_Name_For_Update == p.Brand_Name)
                            {
                                p.Brand_Name      = ViewModelService.Resolve <WorkBrandWindowViewModel>().Brand_Name;
                                db.Entry(p).State = EntityState.Modified;
                            }
                        }
                        db.BrandCar.Remove(db.BrandCar.Find(ViewModelService.Resolve <WorkBrandWindowViewModel>().Brand_Name_For_Update));
                        db.SaveChanges();
                        return;
                    }
                    brand.Brand_Name      = ViewModelService.Resolve <WorkBrandWindowViewModel>().Brand_Name;
                    brand.Logotype        = ViewModelService.Resolve <WorkBrandWindowViewModel>().Logotype;
                    brand.Type_Image      = ViewModelService.Resolve <WorkBrandWindowViewModel>().ImageType;
                    db.Entry(brand).State = EntityState.Modified;
                    db.SaveChanges();
                    MessageBox.Show("Брэнд успешно изменён");
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }
Ejemplo n.º 7
0
 public IResult DeleteToSystem(BrandCar brand)
 {
     _branddal.Delete(brand);
     return(new SuccessResult(Messages.BrandDeleted));
 }