コード例 #1
0
        public async Task <IActionResult> Delete([FromBody] DeleteCustomerViewModel model)
        {
            if (model.Id <= 0)
            {
                return(BadRequest());
            }

            var modelo = await _context.Customers.FirstOrDefaultAsync(x => x.Id == model.Id);

            modelo.Enabled = false;



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

            if (modelo == null)
            {
                return(NotFound());
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                //Guardar Exception
                return(BadRequest());
            }

            return(Ok());
        }
        public IActionResult Delete(long Id)
        {
            var customerToDelete     = _unityOfWork.Customer.GetById(Id);
            var relationatedProducts = _unityOfWork.Product.getProductByCustomers(Id);
            var myCustomer           = new DeleteCustomerViewModel()
            {
                ID            = customerToDelete.ID,
                AddressOffice = customerToDelete.AddressOffice,
                AddressBill   = customerToDelete.AddressBill,
                PhoneNumber   = customerToDelete.PhoneNumber,
                products      = relationatedProducts
            };

            return(View(myCustomer));
        }
 public IActionResult Delete(DeleteCustomerViewModel customerToDelete)
 {
     if (customerToDelete.decisionControll)
     {
         Customer       customer             = _unityOfWork.Customer.GetById(customerToDelete.ID);
         List <Product> relationatedProducts = _unityOfWork.Product.getProductByCustomers(customer.ID);
         foreach (var product in relationatedProducts)
         {
             product.CustomerID = null;
             _unityOfWork.Product.Update(product);
         }
         _unityOfWork.Customer.Delete(customer);
         _unityOfWork.Save();
     }
     return(RedirectToAction("Index"));
 }
コード例 #4
0
 public IActionResult DeleteCustomer(DeleteCustomerViewModel viewModel)
 {
     _service.DeleteCustomer(viewModel.idToDelete);
     return(View());
 }