Exemplo n.º 1
0
        // POST: api/courses
        public IHttpActionResult Postcourse(EmberWrapper course)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Course newCourse = new Course
            {
                Name = course.Course.Name,
            };

            db.Courses.Add(newCourse);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (courseExists(newCourse.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(new { course = newCourse }));
        }
Exemplo n.º 2
0
        // POST: api/cardSets
        public IHttpActionResult PostcardSet(EmberWrapper wrappedCardSet)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            CardSet newCardSet = new CardSet
            {
                Name   = wrappedCardSet.CardSet.Name,
                Course = db.Courses.Find(wrappedCardSet.CardSet.Course)
            };

            db.CardSets.Add(newCardSet);
            db.SaveChanges();

            wrappedCardSet.CardSet.Course = newCardSet.Course.Id;
            wrappedCardSet.CardSet.Id     = newCardSet.Id;

            return(Ok(new { cardSet = wrappedCardSet.CardSet }));
        }
Exemplo n.º 3
0
        public object PostCard(EmberWrapper wrappedCard)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Card newCard = new Card
            {
                FrontText = wrappedCard.Card.FrontText,
                BackText  = wrappedCard.Card.BackText,
                CardSet   = db.CardSets.Find(wrappedCard.Card.CardSet)
            };

            db.Cards.Add(newCard);
            db.SaveChanges();

            wrappedCard.Card.CardSet = newCard.CardSet.Id;
            wrappedCard.Card.Id      = newCard.Id;

            return(new { card = wrappedCard.Card });
        }
Exemplo n.º 4
0
        public IHttpActionResult PurchaseStructure(EmberWrapper structure)
        {
            string structureType = structure.structureType;

            // Once users are implemented, can call "GameExists(id)
            if (true)
            {
                int  currencyRequired = 0;
                int  populationNeeded = 0;
                Game game             = db.Games.FirstOrDefault();
                switch (structureType.ToLower().Trim())
                {
                case "laundry":
                    currencyRequired = 1;
                    populationNeeded = 1;
                    return(Ok(Game.PurchaseBuilding(currencyRequired, populationNeeded, Structure.StructureType.Laundry)));

                case "restaurant":
                    currencyRequired = 1;
                    populationNeeded = 3;
                    return(Ok(Game.PurchaseBuilding(currencyRequired, populationNeeded, Structure.StructureType.Restaurant)));


                case "amusementpark":
                    currencyRequired = 3;
                    populationNeeded = 1;
                    return(Ok(Game.PurchaseBuilding(currencyRequired, populationNeeded, Structure.StructureType.AmusementPark)));

                case "residence":
                    currencyRequired = 1;
                    populationNeeded = 0;
                    return(Ok(Game.PurchaseBuilding(currencyRequired, populationNeeded, Structure.StructureType.Residence)));

                default:
                    return(BadRequest());
                }
            }
        }