예제 #1
0
        public virtual void Update(T entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("Tried to update null entity!");
            }

            _entities.Attach(entity);
            _context.Entry(entity).State = EntityState.Modified;
            _context.SaveChanges();
        }
예제 #2
0
        public ActionResult <WordDto> Get(string word)
        {
            if (string.IsNullOrEmpty(word))
            {
                return(BadRequest());
            }

            word = HttpUtility.UrlDecode(word);

            var foundWord = context.Words.Include(w => w.Definitions)
                            .ThenInclude(d => d.SubDictionary)
                            .Include(w => w.Definitions)
                            .ThenInclude(d => d.WordClass)
                            .Include(w => w.Definitions)
                            .ThenInclude(d => d.Usages)
                            .Include(w => w.Phases)
                            .ThenInclude(p => p.Definitions)
                            .Include(w => w.WordForms)
                            //.Include(w => w.RelativeWords)
                            .FirstOrDefault(w => w.Content == word);

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

            // Using explicit loading improves performance
            context.Entry(foundWord).Collection(w => w.RelativeWords).Load();

            return(ModelToDto(foundWord));
        }
예제 #3
0
 public ActionResult Edit([Bind(Include = "ID,Name")] Language language)
 {
     if (ModelState.IsValid)
     {
         db.Entry(language).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(language));
 }
예제 #4
0
        public override bool Delete(int id)
        {
            Word w = GetOne(id);

            if (w.Translations != null)
            {
                w.Translations.Clear();
                _db.Entry(w).State = EntityState.Modified;
                _db.SaveChanges();
            }
            return(base.Delete(id));
        }
예제 #5
0
 public bool Update(T newRecord)
 {
     try
     {
         var old = GetOne(newRecord.ID);
         _db.Entry(old).CurrentValues.SetValues(newRecord);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
예제 #6
0
 public bool Update(IEntity newRecord)
 {
     try
     {
         //object id = newRecord.Id;
         //T old = GetOne((TKey)id);
         T old = GetOne(newRecord.Id);
         _db.Entry(old).CurrentValues.SetValues(newRecord);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
예제 #7
0
 public void Update(Group entity)
 {
     _context.Groups.Attach(entity);
     _context.Entry(entity).State = EntityState.Modified;
 }
예제 #8
0
 public void Update(Subtitles entity)
 {
     _context.Entry(entity).State = EntityState.Modified;
     _context.SaveChanges();
 }
예제 #9
0
 public void Update(TEntity item)
 {
     _context.Entry(item).State = EntityState.Modified;
     _context.SaveChanges();
 }