コード例 #1
0
        public async Task <IActionResult> PutComment([FromRoute] int id, [FromBody] Comment comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != comment.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> PutPersonas3(int id, [FromBody] Personas3 personas3)
        {
            if (id != personas3.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #3
0
        public async Task <IActionResult> PutUsuarios2(int id, [FromBody] Usuarios2 usuarios2)
        {
            if (id != usuarios2.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #4
0
ファイル: RideController.cs プロジェクト: ruzla/CycleAPI
        public async Task <IActionResult> PutRideMetric(int id, RideMetric rideMetric)
        {
            if (id != rideMetric.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #5
0
        public async Task <ActionResult <Publisher> > GetPublisherDetails(int id)
        {
            ////Eager Loading
            //var publisher = _context.Publishers
            //                .Include(pub=>pub.Books)
            //                    .ThenInclude(book=> book.Sales)
            //                .Include(pub => pub.Users)

            //                .Where(pub => pub.PubId == id).FirstOrDefault();

            //Explicit Loading
            var publisher = await _context.Publishers.SingleAsync(publisher => publisher.PubId == id);

            _context.Entry(publisher)
            .Collection(pub => pub.Users)
            .Query()
            .Where(user => user.EmailAddress.Contains("Karin"))
            .Load();
            _context.Entry(publisher)
            .Collection(pub => pub.Books)
            .Query()
            .Include(book => book.Sales)
            .Load();

            var user = await _context.Users.SingleAsync(usr => usr.UserId == 1);

            _context.Entry(user)
            .Reference(usr => usr.Role)
            .Load();

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

            return(publisher);
        }
コード例 #6
0
        public void setNewScore(string winner)
        {
            TblScores oldScore = db.TblScores.FirstOrDefault(x => x.PlayerName == winner);

            if (oldScore != null)
            {
                oldScore.GamesWon++;
                try
                {
                    db.Entry(oldScore).State = EntityState.Modified;

                    _logger.LogInformation("If a player with the same name existed the corresponding record is updated instead of creating a new one");

                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    _logger.LogError("Exception happened:" + ex.Message, ex);
                    throw;
                }
            }
            else
            {
                TblScores newScore = new TblScores();
                newScore.PlayerName = winner;
                newScore.GamesWon   = 1;
                try
                {
                    db.Add(newScore);
                    db.SaveChanges();
                    _logger.LogInformation("if the player name didn't existed the score is a new record.");
                }
                catch (Exception ex)
                {
                    _logger.LogError("Exception happened:" + ex.Message, ex);
                    throw;
                }
            }
            try
            {
                db.Database.ExecuteSqlCommand("TRUNCATE TABLE [tblrounds]");
                _logger.LogInformation("Table rounds truncated to start a new game");
            }
            catch (Exception ex)
            {
                _logger.LogError("Exception happened:" + ex.Message, ex);
                throw;
            }
        }
コード例 #7
0
ファイル: GameDao.cs プロジェクト: Saura81/Drones
        public int saveRound(TblRounds round)
        {
            try
            {
                db.Entry(round).State = EntityState.Modified;
                db.SaveChanges();

                _logger.LogInformation("Saved changes to round in progress.");
                return(round.RoundId);
            }
            catch (Exception ex)
            {
                _logger.LogError("Exception happened:" + ex.Message, ex);
                throw;
            }
        }
コード例 #8
0
        public async Task <IActionResult> PutArticle([FromRoute] int id, [FromBody] Article article)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Article tempArticle = await _context.Article.FindAsync(id);

            tempArticle.Id             = id;
            tempArticle.Title          = article.Title;
            tempArticle.ContentMain    = article.ContentMain;
            tempArticle.ContentSummary = article.ContentSummary;
            tempArticle.CategoryId     = article.Category.Id;
            tempArticle.Picture        = article.Picture;

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

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

            return(NoContent());
        }