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

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

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

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

            return(NoContent());
        }
コード例 #2
0
 public Character put(Character obj)
 {
     entities.Attach(obj);
     context.Entry(obj).State = EntityState.Modified;
     context.SaveChanges();
     return(obj);
 }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "UserID,UserEmail,Password,firstName,lastName")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", "Home"));
     }
     return(View(user));
 }
コード例 #4
0
ファイル: Repository.cs プロジェクト: eldharon/Star-Wars
        //aktualizuje wybrany rekord
        public async Task <T> UpdateAsync(T updated, int key)
        {
            if (updated == null)
            {
                throw new ArgumentNullException(nameof(updated));
            }
            _db.Entry(updated).State = EntityState.Modified;
            await _db.SaveChangesAsync();

            return(updated);
        }
コード例 #5
0
        public ActionResult Edit([Bind(Include = "QuestionID,UserID,question,answer")] Questions questions)
        {
            Questions tempQuestion = db.Question.Find(questions.QuestionID);

            if (ModelState.IsValid)
            {
                tempQuestion.answer          = questions.answer;
                db.Entry(tempQuestion).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(questions));
        }
コード例 #6
0
        public IActionResult Post([FromBody] Person person)
        {
            // Calling .Add will mark all entities in the graph as Added
            //_context.People.Add(person);

            // Calling .Attach will mark all entities in the graph as unmodified
            //_context.People.Attach(person);

            // Setting the state of a single entity will not attach related entities
            //_context.Entry(person).State = EntityState.Added;

            // Traverse the graph and apply custom rules to decide when
            // an entity is added, and when it is modified

            /*
             * _context.ChangeTracker.TrackGraph(person,
             *  node =>
             *  {
             *      if (node.Entry.Entity is Starship)
             *      {
             *          // Existing Starship
             *          if ((node.Entry.Entity as Starship).Id > 0)
             *          {
             *              node.Entry.State = EntityState.Modified;
             *          }
             *          else // New Starship
             *          {
             *              node.Entry.State = EntityState.Added;
             *          }
             *      }
             *      else
             *      {
             *          // Not a Starship (Person?). Assume new
             *          node.Entry.State = EntityState.Added;
             *      }
             *  });
             */
            try
            {
                _context.Entry(person).Property("LastUpdated").CurrentValue = DateTime.Now;
                _context.SaveChanges();
                return(new CreatedAtRouteResult("GetPerson", new { id = person.Id }, person));
            }
            catch (Exception ex)
            {
                return(new BadRequestObjectResult(ex.ToString()));
            }
        }
コード例 #7
0
ファイル: Repository.cs プロジェクト: Zdanc123/ApiStarWars
 public T put(T obj)
 {
     entities.Attach(obj);
     context.Entry(obj).State = EntityState.Modified;
     return(obj);
 }