示例#1
0
        public ActionResult Save(Brand brand)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new BrandFormViewModel
                {
                    brand = brand
                };
                return(View("BrandForm", viewModel));
            }

            // work out if there is another in the dbcontext with same name
            var brandWithSameName = _context.brands.Where(b => b.Name == brand.Name).ToList();

            if (brandWithSameName.Count > 0)
            {
                return(RedirectToAction("New"));
            }

            if (brand.id == 0)
            {
                var id = User.Identity.GetUserId();
                brand.userId = id;
                _context.brands.Add(brand);
            }
            else
            {
                var brandInDb = _context.brands.Single(b => b.id == brand.id);
                brandInDb.Name           = brand.Name;
                brandInDb.trainingImages = brand.trainingImages;
            }

            _context.SaveChanges();
            SaveTrainingImages(brand);

            // Set up test and train subdirectories
            Directory.CreateDirectory(Server.MapPath(String.Format("~/Storage/{0}/data", brand.id)));
            Directory.CreateDirectory(Server.MapPath(String.Format("~/Storage/{0}/data/data", brand.id)));
            Directory.CreateDirectory(Server.MapPath(String.Format("~/Storage/{0}/data/graph", brand.id)));
            Directory.CreateDirectory(Server.MapPath(String.Format("~/Storage/{0}/data/training", brand.id)));
            Directory.CreateDirectory(Server.MapPath(String.Format("~/Storage/{0}/data/trainingoutput", brand.id)));
            Directory.CreateDirectory(Server.MapPath(String.Format("~/Storage/{0}/training-images-augmented/test/", brand.id)));
            Directory.CreateDirectory(Server.MapPath(String.Format("~/Storage/{0}/training-images-augmented/train/", brand.id)));
            Directory.CreateDirectory(Server.MapPath(String.Format("~/Storage/{0}/training-images-augmented/debug/", brand.id)));


            // Copy the model starting point
            string SourcePath = Server.MapPath("~/tf_model/faster_rcnn_inception_v2_coco_2017_11_08");
            string DestPath   = Server.MapPath(String.Format("~/Storage/{0}/data/faster_rcnn_inception_v2_coco_2017_11_08", brand.id));

            Directory.CreateDirectory(Server.MapPath(String.Format("~/Storage/{0}/data/faster_rcnn_inception_v2_coco_2017_11_08", brand.id)));
            Copy(SourcePath, DestPath);

            //Copy the model config
            SourcePath = Server.MapPath("~/tf_model/training/faster_rcnn_inception_v2_coco.config");
            DestPath   = Server.MapPath(String.Format("~/Storage/{0}/data/training/faster_rcnn_inception_v2_coco.config", brand.id));
            System.IO.File.Copy(SourcePath, DestPath);

            return(RedirectToAction("Index", "Home"));
        }
示例#2
0
        public ActionResult Edit(int id)
        {
            var brand = _context.Brands.SingleOrDefault <Brand>(c => c.Id == id);

            if (brand == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new BrandFormViewModel();

            viewModel.Brand = brand;

            return(View("BrandForm", viewModel));
        }
示例#3
0
        public ActionResult Save(Brand brand)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new BrandFormViewModel();
                viewModel.Brand = brand;
                return(View("BrandForm", viewModel));
            }

            if (brand.Id != 0)
            {
                var brandInDB = _context.Brands.Single <Brand>(c => c.Id == brand.Id);
                brandInDB.Name     = brand.Name;
                brandInDB.LinkName = brand.LinkName;
            }
            else
            {
                _context.Brands.Add(brand);
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Brands"));
        }