public IActionResult AddSprite(AddSpriteViewModel sprite)
        {
            if (!ModelState.IsValid)
            {
                return(View(sprite));
            }

            var filename = $"{sprite.name}.{sprite.image.FileName.Split('.').Last()}";
            var absPath  = Path.Join(env.WebRootPath, "spriteFiles", filename);

            if (logic.getSpriteByName(sprite.name) != null)
            {
                ModelState.AddModelError("name", "sprite name already exists");
                return(View(sprite));
            }



            using (var stream = System.IO.File.Create(absPath))
            {
                sprite.image.CopyTo(stream);
                stream.Flush();
            }

            logic.AddSprite(sprite.name, filename, sprite.price);


            return(View());
        }
Ejemplo n.º 2
0
 void TestAddSprites()
 {
     logic.AddSprite("test", "test", 500);
     Assert.True(logic.getAllSprites().Count() == 2);
 }