예제 #1
0
        public bool CreateDeck(DeckCreate model)
        {
            var result = DeckTitleValidator(model.DeckTitle, model.CategoryId);

            if (result)
            {
                return(false);
            }
            else
            {
                var entity =
                    new Deck()
                {
                    UserId          = _userId,
                    DeckTitle       = model.DeckTitle,
                    DeckDescription = model.DeckDescription,
                    CategoryId      = model.CategoryId,
                    CreatedUtc      = DateTimeOffset.UtcNow
                };
                using (var ctx = new ApplicationDbContext())
                {
                    ctx.Decks.Add(entity);
                    return(ctx.SaveChanges() == 1);
                }
            }
        }
예제 #2
0
        async public Task <ShortDeckInfo> Post(DeckCreate creation)
        {
            int  creationCount = creation.Count.HasValue ? creation.Count.Value : 1;
            Deck deck          = await _repository.CreateNewShuffledDeckAsync(creationCount);

            ShortDeckInfo deckInfo = new ShortDeckInfo
            {
                DeckId    = deck.DeckId,
                Remaining = deck.Cards.Where(x => !x.Drawn).Count()
            };

            return(deckInfo);
        }
예제 #3
0
        public async Task <ShortDeckInfo> Post(DeckCreate model)
        {
            int count = model.Count.HasValue ? model.Count.Value : 1;
            var deck  = await repository.CreateNewShuffledDeckAsync(count);

            var deckInfo = new ShortDeckInfo()
            {
                DeckId    = deck.DeckId,
                Remaining = deck.Cards.Where(card => !card.Drawn).Count()
            };

            return(deckInfo);
        }
예제 #4
0
        /// <summary>
        /// Create a new deck.
        /// </summary>
        /// <param name="deck"></param>
        /// <returns></returns>
        public IHttpActionResult Post(DeckCreate deck)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateDeckService();

            if (!service.CreateDeck(deck))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
예제 #5
0
        public int CreateDeck(DeckCreate model)
        {
            var entity = new Deck()
            {
                ApplicationUserId = _userid,
                Name = model.Name
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Decks.Add(entity);
                if (ctx.SaveChanges() == 1)
                {
                    return(entity.Id);
                }
                return(0);
            }
        }
예제 #6
0
        public bool CreateDeck(DeckCreate model)
        {
            var entity =
                new DeckData()
            {
                Title           = model.Title,
                Description     = model.Description,
                CreateTime      = DateTime.Now,
                PercentComplete = 0,
                UserID          = _userID
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Decks.Add(entity);

                return(ctx.SaveChanges() == 1);
            }
        }
예제 #7
0
        public ActionResult Create(DeckCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateDeckService();
            int id      = service.CreateDeck(model);

            if (id != 0)
            {
                TempData["SaveResult"] = "Deck created.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Deck could not be created.");

            return(View(model));
        }