コード例 #1
0
        public async Task <IActionResult> PutSessionTrackerModel(int id, SessionTrackerModel sessionTrackerModel)
        {
            if (id != sessionTrackerModel.Id)
            {
                return(BadRequest());
            }

            _context.Entry(sessionTrackerModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SessionTrackerModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        public async Task AddToTotalXPAsync(string combatXP, string explorationXP, string socialInteractionXP, string sDescription)
        {
            var cXPCheck  = Int32.TryParse(combatXP, out int cXP);
            var eXPCheck  = Int32.TryParse(explorationXP, out int eXP);
            var sIXPCheck = Int32.TryParse(socialInteractionXP, out int sIXP);

            if (cXPCheck || eXPCheck || sIXPCheck == true)
            {
                var runningTotal = _context.XPTracker.ToList().Last();
                // var newTotal = runningTotal.TotalXP + cXP + eXP + sIXP;
                runningTotal.TotalLevel = _context.LevelTracker.Where(w => w.MinXP <= runningTotal.TotalXP && w.MaxXP > runningTotal.TotalXP).Select(s => s.Level).ToList().First();


                var newTotalXP = new XPTrackerModel
                {
                    TotalXP    = runningTotal.TotalXP + cXP + eXP + sIXP,
                    TotalLevel = runningTotal.TotalLevel,
                };

                await _context.XPTracker.AddAsync(newTotalXP);

                var lastSession = _context.SessionTracker.ToList().Last();

                // Creating newSessionTrackerModel to store each sessions individual xp gains

                var newSessionXP = new SessionTrackerModel
                {
                    SessionNumber       = lastSession.SessionNumber + 1,
                    SessionDescription  = sDescription,
                    CombatXP            = cXP,
                    ExplorationXP       = eXP,
                    SocialInteractionXP = sIXP,
                    XPId = newTotalXP.Id
                           // XPId = runningTotal.Id
                };

                await _context.SessionTracker.AddAsync(newSessionXP);

                await _context.SaveChangesAsync();

                await ReplyAsync($"The groups total experience is: {newTotalXP.TotalXP} points and are at Level {newTotalXP.TotalLevel}.");
            }

            // await ReplyAsync("Please Enter: !AddToTotalXP YourCombatExperienceInt YourExplorationExperienceInt YourSocialInteractionExperienceInt ''Short Description of the Session''");
        }
コード例 #3
0
        public async Task <ActionResult <SessionTrackerModel> > PostSessionTrackerModel(SessionTrackerModel sessionTrackerModel)
        {
            _context.SessionTracker.Add(sessionTrackerModel);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetSessionTrackerModel", new { id = sessionTrackerModel.Id }, sessionTrackerModel));
        }