コード例 #1
0
 public ActionResult Edit(ArtworkPool imagepool)
 {
     if (ModelState.IsValid)
     {
         db.Entry(imagepool).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(imagepool));
 }
コード例 #2
0
        public ActionResult Create(ArtworkPool imagepool)
        {
            if (ModelState.IsValid)
            {
                db.ArtworkPools.Add(imagepool);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(imagepool));
        }
コード例 #3
0
ファイル: TagDbData.cs プロジェクト: AccelerateX-org/soTaggy
        public void InitDemoPool(string homeDir)
        {
            var pool = _context.ArtworkPools.SingleOrDefault(p => p.Name.Equals("Demo"));

            if (pool != null)
            {
                return;
            }

            InitCatalogData();

            pool = new ArtworkPool()
            {
                Name        = "Demo",
                Description = "Demodateien",
            };

            _context.ArtworkPools.Add(pool);
            _context.SaveChanges();

            var lines = File.ReadAllLines(Path.Combine(homeDir, "Index.csv"), Encoding.Default);

            foreach (var line in lines)
            {
                var elem = line.Split(';');

                var libName = elem[6];
                var cpName  = elem[7];

                var library = _context.ArtworkLibraries.SingleOrDefault(l => l.ShortName.Equals(libName));
                var copy    = _context.CopyrightOwners.SingleOrDefault(c => c.ShortName.Equals(cpName));

                var artwork = new Artwork()
                {
                    ArtworkPoolId  = pool.ArtworkPoolId,
                    Artist         = elem[1],
                    Title          = elem[2],
                    Dating         = elem[3],
                    Technique      = elem[4],
                    Dimensions     = elem[5],
                    ArtworkLibrary = library,
                    CopyrightOwner = copy,
                };

                _context.Artworks.Add(artwork);

                var imageFile = Path.Combine(homeDir, elem[0]);

                var image = new ArtworkImage
                {
                    ImageFileType = "image/" + Path.GetExtension(imageFile).Remove(0, 1),
                    Artwork       = artwork,
                    ImageData     = File.ReadAllBytes(imageFile),
                };

                _context.Images.Add(image);
                _context.SaveChanges();
            }

            _context.SaveChanges();
        }