Пример #1
0
 public ActionResult Edit([Bind(Include = "Id,Name,Level,Code,Descriptin,ParentId")] Machine machine)
 {
     if (ModelState.IsValid)
     {
         db.Entry(machine).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ParentId = new SelectList(db.Machines, "Id", "Name", machine.ParentId);
     return(View(machine));
 }
Пример #2
0
        /// <summary>
        /// Returns a single object with a primary key of the provided id
        /// </summary>
        /// <remarks>Asynchronous</remarks>
        /// <param name="id">The primary key of the object to fetch</param>
        /// <param name="option">Option need lazy relation</param>
        /// <returns>A single object with the provided primary key or null</returns>
        public async Task <TEntity> GetAsync(int id, bool option = false)
        {
            var entity = await Context.Set <TEntity>().FindAsync(id);

            if (!option)
            {
                Context.Entry(entity).State = EntityState.Detached;
            }

            return(entity);
            // return await this.entities.FindAsync(id);
        }
        /// <summary>
        /// Returns a single object with a primary key of the provided id
        /// </summary>
        /// <remarks>Synchronous</remarks>
        /// <param name="id">The primary key of the object to fetch</param>
        /// <returns>A single object with the provided primary key or null</returns>
        public TEntity Get(int id, bool option = false)
        {
            var entity = this.Entities.Find(id);

            if (!option)
            {
                Context.Entry(entity).State = EntityState.Detached;
            }
            return(entity);
        }