Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "Id,Name,Designer,PlayTime,CoreMechanic,MinPlayers,MaxPlayers,Weight,Rating")] Game game)
        {
            if (ModelState.IsValid)
            {
                db.Games.Add(game);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(game));
        }
    public IActionResult Deletesong(int id)
    {
        var song = context.Songs.Find(id);

        if (song == null)
        {
            return(NotFound());
        }

        context.Songs.Remove(song);
        context.SaveChanges();
        return(NoContent());
    }
Exemplo n.º 3
0
    public IActionResult DeleteAlbum(int id)
    {
        var album = context.Albums.Find(id);

        if (album == null)
        {
            return(NotFound());
        }

        context.Albums.Remove(album);
        context.SaveChanges();
        return(NoContent());
    }
Exemplo n.º 4
0
        public IActionResult Create([FromBody] Artist artist)
        {
            if (artist == null)
            {
                return(BadRequest());
            }

            //  Set created to now
            artist.Created = DateTime.Now;

            _context.Artist.Add(artist);
            _context.SaveChanges();

            //  Set location in header to the "GetArtist" route. So we return the created object
            return(CreatedAtRoute("GetArtist", new { id = artist.Id }, artist));
        }
Exemplo n.º 5
0
        public ArtistController(CollectionContext context)
        {
            _context = context;

            if (_context.Artist.Count() == 0)
            {
                _context.Artist.Add(new Artist {
                    Name = "Exodus"
                });
                _context.SaveChanges();
            }
        }
Exemplo n.º 6
0
 public static void CreateDeck()
 {
     using (var db = new CollectionContext())
     {
         User demoUser = new User()
         {
             UserName = "******", Password = "******"
         };
         db.Users.Add(demoUser);
         db.SaveChanges();
     }
 }
 public JsonResult PostCollection([FromBody] Collection collection)
 {
     try
     {
         if (collection is not null)
         {
             db.Collections.Add(collection);
             db.SaveChanges();
         }
         return(Json(collection));
     } catch (SqlException e)
     {
         return(Json(e.Message));
     }
 }
Exemplo n.º 8
0
        //TODO: Do at startup
        public static void addToDb()
        {
            using (var db = new CollectionContext())
            {
                using (var httpclient = new WebClient())
                {
                    var jsonData = httpclient.DownloadString("https://mtgjson.com/json/Standard.json");
                    var model    = JsonConvert.DeserializeObject <Carddata>(jsonData);

                    var data = from i in model.M19.cards
                               select i;

                    foreach (var q in data)
                    {
                        db.Cards.Add(new Card()
                        {
                            name                   = q.name,
                            artist                 = q.artist,
                            colors                 = q.colors,
                            convertedManaCost      = q.convertedManaCost,
                            manaCost               = q.manaCost,
                            multiverseId           = q.multiverseId,
                            loyalty                = q.loyalty,
                            number                 = q.number,
                            rarity                 = q.rarity,
                            scryfallId             = q.scryfallId,
                            scryfallIllustrationId = q.scryfallIllustrationId,
                            scryfallOracleId       = q.scryfallOracleId,
                            subtype                = q.subtype,
                            supertype              = q.supertype,
                            text                   = q.text,
                            type                   = q.type,
                            types                  = q.types,
                            uuid                   = q.uuid,
                            uuidV421               = q.uuidV421,
                            power                  = q.power,
                            toughness              = q.toughness
                        });

                        db.SaveChanges();
                    }
                }
            }
        }
Exemplo n.º 9
0
        public ActionResult Create(CreateCollectionModel model)
        {
            CollectionContext context = new CollectionContext();

            Models.Collections collections  = new Collections();
            LikesContext       likesContext = new LikesContext();
            Like like = new Like();
            List <Collections> listCol  = context.Collections.ToList();
            List <Like>        listLike = likesContext.Like.ToList();

            if (context.Collections.Count() >= 1)
            {
                collections.Id = listCol[listCol.Count - 1].Id + 1;
            }
            else
            {
                collections.Id = 1;
            }
            if (likesContext.Like.Count() >= 1)
            {
                like.Id = listLike[listLike.Count - 1].Id + 1;
            }
            else
            {
                like.Id = 1;
            }
            like.CollectionId = collections.Id;
            like.Count        = 0;
            likesContext.Like.Add(like);
            likesContext.SaveChanges();
            collections.ImgUrl      = "https://res.cloudinary.com/coursepoject/image/upload/v1585662014/" + model.image + ".jpg";
            collections.Topic       = model.Topic;
            collections.Description = model.Description;
            collections.UserId      = CurrentUser.Id;
            collections.Name        = model.Name;
            context.Collections.Add(collections);
            context.SaveChanges();
            return(View("Collections"));
        }