Пример #1
0
        public async Task <IActionResult> PutCustomer(int id, Customer customer)
        {
            if (id != customer.id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #2
0
 public ActionResult Edit([Bind(Include = "ID,FirstName,LastName,Email,age,FullAddress,DateOfBirth")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
Пример #3
0
 public ActionResult Edit([Bind(Include = "CustomerID,ContactName,Country,BirthDay")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
 public async Task <bool> UpdateCustomerAsync(Customer customer)
 {
     //Will update all properties of the Customer
     _Context.Customers.Attach(customer);
     _Context.Entry(customer).State = EntityState.Modified;
     try
     {
         return(await _Context.SaveChangesAsync() > 0 ? true : false);
     }
     catch (Exception exp)
     {
         _Logger.LogError($"Error in {nameof(UpdateCustomerAsync)}: " + exp.Message);
     }
     return(false);
 }
        public void EditCustomer(Customers customer)
        {
            var cust = _customerDBContext.Customers.AsNoTracking().Where(q => q.CustomerId == customer.CustomerId);

            foreach (var cus in cust)
            {
                if ((customer.CustomerId == cus.CustomerId))
                {
                    _customerDBContext.Customers.Remove(cus);
                }
            }
            _customerDBContext.Attach(customer);
            IEnumerable <EntityEntry> noChangeEntities = _customerDBContext.ChangeTracker.Entries().Where(x => x.State == EntityState.Unchanged);

            foreach (EntityEntry cusEE in noChangeEntities)
            {
                cusEE.State = EntityState.Modified;
            }
            _customerDBContext.Entry(customer).State = EntityState.Modified;
            _customerDBContext.SaveChanges();
        }
Пример #6
0
        public bool UpdateCustomer(int id, Customer item)
        {
            try
            {
                var customer = context.Customers.SingleOrDefault(c => c.Id == id);

                if (customer == null)
                {
                    throw new Exception(string.Format("Customer with id: '{0}' not found", id.ToString()));
                }

                customer.Name  = item.Name;
                customer.Email = item.Email;
                customer.Phone = item.Phone;

                context.Entry(customer).State = EntityState.Modified;
                context.SaveChanges();
                return(true);
            }
            catch
            {
                throw;
            }
        }
 public void UpdateCustomer(Customer customer)
 {
     _context.Customers.Update(customer);
     _context.Entry(customer).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 }