Esempio n. 1
0
 public virtual void Delete(TEntity entityToDelete)
 {
     if (context.Entry(entityToDelete).State == EntityState.Detached)
     {
         dbSet.Attach(entityToDelete);
     }
     dbSet.Remove(entityToDelete);
 }
Esempio n. 2
0
        public ActionResult UpdateSave(Contact contact)
        {
            using (PhoneBookContext db = new PhoneBookContext())
            {
                db.Contacts.Attach(contact);
                db.Entry(contact)
                .Property(c => c.PhoneNumber).IsModified = true;
                db.Entry(contact)
                .Property(c => c.Name).IsModified = true;
                db.SaveChanges();
            }

            return(Redirect("/Dist/Index"));
        }
Esempio n. 3
0
        public IHttpActionResult PutPerson([FromUri] int id, [FromBody] Person person)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 4
0
        public async Task <TEntity> Update(TEntity entity)
        {
            PhoneBookContext.Entry(entity).State = EntityState.Modified;
            await PhoneBookContext.SaveChangesAsync();

            return(entity);
        }
Esempio n. 5
0
        public async Task <IHttpActionResult> PutPeople(int id, People people)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 6
0
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 7
0
        public async Task <ActionResult <Contact> > Put(int id, [FromBody] Contact contact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (id != contact.ContactId)
            {
                return(BadRequest());
            }

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

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

            return(Ok(contact));
        }
Esempio n. 8
0
        public bool Update(Person person)
        {
            try
            {
                var obj = GetOneById(person.Id);

                obj.FirstName = person.FirstName;

                obj.LastName = person.LastName;

                obj.Phone = person.Phone;

                obj.Email = person.Email;

                obj.Updated = DateTime.Now;

                _phoneBookContext.Entry(obj).State = Microsoft.EntityFrameworkCore.EntityState.Modified;

                _phoneBookContext.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Esempio n. 9
0
 public void Add(Person person)
 {
     using (PhoneBookContext context = new PhoneBookContext())
     {
         var addedObject = context.Entry(person);
         addedObject.State = EntityState.Added;
         context.SaveChanges();
     }
 }
Esempio n. 10
0
 public void Delete(Person person)
 {
     using (PhoneBookContext context = new PhoneBookContext())
     {
         var deletedObject = context.Entry(person);
         deletedObject.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Esempio n. 11
0
 public void Update(Person person)
 {
     using (PhoneBookContext context = new PhoneBookContext())
     {
         var updatedObject = context.Entry(person);
         updatedObject.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Esempio n. 12
0
 public ActionResult Edit([Bind(Include = "ContactID,FirstName,LastName,Address,Email")] Contact contact)
 {
     if (ModelState.IsValid)
     {
         db.Entry(contact).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(contact));
 }
Esempio n. 13
0
 public ActionResult Edit([Bind(Include = "CuntryId,CountryName,IsActive")] Country country)
 {
     if (ModelState.IsValid)
     {
         db.Entry(country).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(country));
 }
        public ActionResult Edit([Bind(Include = "ID,FirstName,LastName,PhoneNumber,Email,AddressOne,AddressTwo,PinCode,IsActive,CountryId,StateId,CityId")] People people)
        {
            if (ModelState.IsValid)
            {
                db.Entry(people).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(people));
        }
Esempio n. 15
0
 public ActionResult Edit([Bind(Include = "CityId,CityName,IsActive,StateId")] City city)
 {
     if (ModelState.IsValid)
     {
         db.Entry(city).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.StateId = new SelectList(db.States, "StateId", "StateName", city.StateId);
     return(View(city));
 }
 public ActionResult Edit([Bind(Include = "StateId,StateName,IsActive,CountryId")] State state)
 {
     if (ModelState.IsValid)
     {
         db.Entry(state).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CountryId = new SelectList(db.Countries, "CountryId", "CountryName", state.CountryId);
     return(View(state));
 }
 public ActionResult Edit([Bind(Include = "PhoneNumberID,ContactID,PhoneTypeID,Number")] PhoneNumber phoneNumber)
 {
     if (ModelState.IsValid)
     {
         db.Entry(phoneNumber).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ContactID   = new SelectList(db.Contacts, "ContactID", "FullName", phoneNumber.ContactID);
     ViewBag.PhoneTypeID = new SelectList(db.PhoneTypes, "PhoneTypeID", "Type", phoneNumber.PhoneTypeID);
     return(View(phoneNumber));
 }
Esempio n. 18
0
        public void UpdateContact(Contact contactForUpdate)
        {
            var currentContact = _context.Contacts
                                 .Where(c => c.ContactId == contactForUpdate.ContactId)
                                 .Include(c => c.ContactPhones)
                                 .AsNoTracking()
                                 .SingleOrDefault();

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

            foreach (var contactPhone in contactForUpdate.ContactPhones)
            {
                bool contactPhoneExists = currentContact.ContactPhones.Any(c => c.ContactPhoneId == contactPhone.ContactPhoneId);

                if (!contactPhoneExists)
                {
                    return;
                }

                _context.Entry(contactPhone).State = EntityState.Modified;
            }
        }
 public ActionResult Edit([Bind(Include = "ID,FirstName,LastName,PhoneNumber,Email,AddressOne,AddressTwo,PinCode,IsActive,CountryId,StateId,CityId")] People people)
 {
     if (ModelState.IsValid)
     {
         db.Entry(people).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CityId    = new SelectList(db.Cities, "CityId", "CityName", people.CityId);
     ViewBag.CountryId = new SelectList(db.Countries, "CountryId", "CountryName", people.CountryId);
     ViewBag.StateId   = new SelectList(db.States, "StateId", "StateName", people.StateId);
     return(View(people));
 }
Esempio n. 20
0
        public void Update(PhoneNumber item)
        {
            phoneNumber = GetById(item.Id);

            if (phoneNumber != null)
            {
                phoneNumber.Number = item.Number;
            }
            else
            {
                throw new ArgumentNullException("Please choose phone number to update");
            }

            using (var context = new PhoneBookContext())
            {
                context.PhoneNumbers.Attach(phoneNumber);
                context.Entry(phoneNumber).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
Esempio n. 21
0
        public void Update(Contact item)
        {
            contact = GetById(item.Id);

            if (contact != null)
            {
                contact.Firstname = item.Firstname;
                contact.LastName  = item.LastName;
            }
            else
            {
                throw new ArgumentNullException("Please choose contact to update");
            }

            using (var context = new PhoneBookContext())
            {
                context.Contacts.Attach(contact);
                context.Entry(contact).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
Esempio n. 22
0
        public void Update(User item)
        {
            user = GetById(item.Id);

            if (user != null)
            {
                user.UserName  = item.UserName;
                user.Password  = item.Password;
                user.FirstName = item.FirstName;
                user.LastName  = item.LastName;
            }
            else
            {
                throw new ArgumentNullException("Please choose user to update");
            }

            using (var context = new PhoneBookContext())
            {
                context.Users.Attach(user);
                context.Entry(user).State = EntityState.Modified;
                context.SaveChanges();
            }
        }