Пример #1
0
 public virtual void Delete(TEntity entityToDelete)
 {
     if (context.Entry(entityToDelete).State == EntityState.Detached)
     {
         dbSet.Attach(entityToDelete);
     }
     dbSet.Remove(entityToDelete);
 }
Пример #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"));
        }
Пример #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));
        }
Пример #4
0
        public async Task <TEntity> Update(TEntity entity)
        {
            PhoneBookContext.Entry(entity).State = EntityState.Modified;
            await PhoneBookContext.SaveChangesAsync();

            return(entity);
        }
Пример #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));
        }
Пример #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());
        }
Пример #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));
        }
Пример #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);
            }
        }
Пример #9
0
 public void Add(Person person)
 {
     using (PhoneBookContext context = new PhoneBookContext())
     {
         var addedObject = context.Entry(person);
         addedObject.State = EntityState.Added;
         context.SaveChanges();
     }
 }
Пример #10
0
 public void Delete(Person person)
 {
     using (PhoneBookContext context = new PhoneBookContext())
     {
         var deletedObject = context.Entry(person);
         deletedObject.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Пример #11
0
 public void Update(Person person)
 {
     using (PhoneBookContext context = new PhoneBookContext())
     {
         var updatedObject = context.Entry(person);
         updatedObject.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Пример #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));
 }
Пример #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));
        }
Пример #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));
 }
Пример #16
0
 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));
 }
Пример #17
0
 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));
 }
Пример #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;
            }
        }
Пример #19
0
 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));
 }
Пример #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();
            }
        }
Пример #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();
            }
        }
Пример #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();
            }
        }