Esempio n. 1
0
 public virtual void Delete(TEntity entityToDelete)
 {
     if (dbContext.Entry(entityToDelete).State == EntityState.Detached)
     {
         dbSet.Attach(entityToDelete);
     }
     dbSet.Remove(entityToDelete);
 }
Esempio n. 2
0
 private void SetModifiedOrAddedState(CoreContext context, object entity, int?id)
 {
     if (id != null && id.Value != 0)
     {
         context.Entry(entity).State = EntityState.Modified;
     }
     else
     {
         context.Entry(entity).State = EntityState.Added;
     }
 }
        public virtual async Task <IActionResult> PutAsync(long id, T entity)
        {
            var entityId = (long)typeof(T).GetProperty("Id").GetValue(entity);

            if (id != entityId)
            {
                return(BadRequest());
            }

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

            try
            {
                await _context.SaveChangesAsync(new System.Threading.CancellationToken());
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EntityExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(await _table.FindAsync(entityId)));
        }
        public void Update(TEntityDTO entity)
        {
            var mappedEntity = Mapper.Map <TEntity>(entity);

            Db.Entry(mappedEntity).State = EntityState.Modified;
            Db.SaveChanges();
        }
Esempio n. 5
0
        public async Task <IActionResult> PutSensor(int id, Sensor sensor)
        {
            if (id != sensor.SensorId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 6
0
        public async Task <IActionResult> PutIncidente(int id, Incidente incidente)
        {
            if (id != incidente.IncidenteId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 7
0
        public async Task <IActionResult> PutMedia(Guid id, MediaItem media)
        {
            if (id != media.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 8
0
        public async Task <IActionResult> PutFriendship(int id, Friendship friendship)
        {
            if (id != friendship.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 9
0
        public IHttpActionResult PutStudent(string id, Student student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != student.CollegeID)
            {
                return(BadRequest());
            }

            db.Entry(student).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 10
0
        public async Task <IActionResult> PutAlbum(Guid id, Album album)
        {
            if (id != album.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 11
0
        public async Task <IActionResult> PutBrewery([FromRoute] int id, [FromBody] Brewery brewery)
        {
            if (id != brewery.BreweryId)
            {
                return(BadRequest());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_context.Brewery.Any(e => e.BreweryId == id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutEmployee([FromRoute] long id, [FromBody] Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != employee.employeeId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 13
0
        public async Task <IActionResult> PutPaises(int id, Paises paises)
        {
            if (id != paises.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 14
0
        public async Task <IActionResult> PutAfetado(int id, Afetado afetado)
        {
            if (id != afetado.AfetadoId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 15
0
        public IHttpActionResult PutAttendance(int id, Attendance attendance)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != attendance.ID)
            {
                return(BadRequest());
            }

            db.Entry(attendance).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 16
0
 public virtual bool Save(TEntity entity)
 {
     if (entity == null)
     {
         throw new Exception("保存对象不能为空");
     }
     CoreContext.Entry <TEntity>(entity).State = EntityState.Modified;
     return(CoreContext.SaveChanges() > 0);
 }
Esempio n. 17
0
 public ActionResult Edit([Bind(Include = "ID,FirstName,MidName,LastName,DOB")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
Esempio n. 18
0
 public ActionResult Edit(LessonViewModel lessonviewmodel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(lessonviewmodel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(lessonviewmodel));
 }
Esempio n. 19
0
        public void ShouldAddACategoryWithDbSet()
        {
            var category = new ProductsCategory {
                Title = "Foo"
            };

            _db.ProductsCategories.Add(category);
            Assert.Equal(EntityState.Added, _db.Entry(category).State);
            Assert.True(category.Id < 0);
            Assert.Null(category.TimeStamp);
            _db.SaveChanges();
            Assert.Equal(EntityState.Unchanged, _db.Entry(category).State);
            Assert.Equal(0, category.Id);
            Assert.NotNull(category.TimeStamp);
            Assert.Equal(1, _db.ProductsCategories.Count());
        }
Esempio n. 20
0
        public int Delete(int id, byte[] timeStamp, bool persist = true)
        {
            var entry = GetEntryFromChangeTracker(id);

            if (entry != null)
            {
                if (entry.TimeStamp == timeStamp)
                {
                    return(Delete(entry, persist));
                }
                throw new Exception("Unable to delete due to concurrency violation.");
            }
            Db.Entry(new T {
                Id = id, TimeStamp = timeStamp
            }).State = EntityState.Deleted;
            return(persist ? SaveChanges() : 0);
        }
Esempio n. 21
0
        public void ShouldDeleteACategoryWithTimestampData()
        {
            var category = new ProductsCategory {
                Title = "Foo"
            };

            _db.ProductsCategories.Add(category);
            _db.SaveChanges();
            var context     = new CoreContext();
            var catToDelete = new ProductsCategory {
                Id = category.Id, TimeStamp = category.TimeStamp
            };

            context.Entry(catToDelete).State = EntityState.Deleted;
            var affected = context.SaveChanges();

            Assert.Equal(1, affected);
        }
 public void RemoveIdentityFromGroup(SecurityGroupSecurityIdentity groupConenction)
 {
     context.Entry(groupConenction.Group).State    = EntityState.Detached;
     context.Entry(groupConenction.Identity).State = EntityState.Detached;
     context.Entry(groupConenction).State          = EntityState.Deleted;
 }
Esempio n. 23
0
 public virtual void SetModified(T entity)
 {
     _contexto.Entry(entity).State = EntityState.Modified;
 }
Esempio n. 24
0
 public async Task UpdateAsync(T entity)
 {
     _context.Entry(entity).State = EntityState.Modified;
     await _context.SaveChangesAsync();
 }
Esempio n. 25
0
 public async Task Update(Student std)
 {
     _context.Entry(std).State = EntityState.Modified;
     await _context.SaveChangesAsync();
 }
Esempio n. 26
0
 public async Task UpdateAsync(User entity)
 {
     _context.Entry(entity).State = EntityState.Modified;
 }