コード例 #1
0
        public IHttpActionResult PutComp(int id, Competition competition)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != competition.ID)
            {
                return(BadRequest("No Competition exists with that ID"));
            }

            // commented line for unit tests and added the mark as modified, reverse before deploying
            //db.MarkAsModified(competition);
            db.Entry(competition).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CompetitionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
        public IHttpActionResult PutGolfer(int id, Golfer golfer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != golfer.ID)
            {
                return(BadRequest("Golfer with ID doesn't exist"));
            }

            // commented line for unit tests and added the mark as modified, reverse before deploying
            db.Entry(golfer).State = EntityState.Modified;
            //db.MarkAsModified(golfer);
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GolferExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "ProductID,Name,Price,Quantity,SubDepartment,ItemCategory")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
コード例 #4
0
 public ActionResult Edit([Bind(Include = "TournamentID,TournamentName,TournamentDate")] Tournament tournament)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tournament).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tournament));
 }
コード例 #5
0
 public ActionResult Edit([Bind(Include = "EventTypeID,Type")] EventType eventType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(eventType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(eventType));
 }
コード例 #6
0
        public async Task <Reservation> UpdateReservation(Reservation reservation)
        {
            try
            {
                reservation = setReservation(reservation);
                _context.Entry(reservation).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(reservation);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }