Exemple #1
0
        public async Task <ActionResult <Product> > DeleteProduct(int id)
        {
            var product = await _context.Product.FindAsync(id);

            product.IsActive = false;
            _context.Update(product);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException e)
            {
                throw;
            }

            return(CreatedAtAction("GetProduct", new { id = product.ProductId }, product));
        }
        public async Task <ActionResult <Employees> > EditEmployee(Employees employees)
        {
            employees.EmployeeId    = _context.Employees.Where(c => c.UserId == employees.UserId).Select(a => a.EmployeeId).Single();
            employees.User.Password = _context.Users.Where(b => b.UserId == employees.User.UserId).Select(a => a.Password).Single();
            _context.Update(employees.User);
            _context.Update(employees);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException e)
            {
                throw;
            }

            return(CreatedAtAction("GetEmployees", new { id = employees.EmployeeId }, employees));
        }
        public async Task <ActionResult <Customers> > EditCustomer(Customers customer)
        {
            customer.CustomerId    = _context.Customers.Where(c => c.UserId == customer.UserId).Select(a => a.CustomerId).Single();
            customer.User.Password = _context.Users.Where(b => b.UserId == customer.User.UserId).Select(a => a.Password).Single();
            _context.Update(customer.User);
            _context.Update(customer);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException e)
            {
                throw;
            }

            return(CreatedAtAction("GetCustomer", new { id = customer.CustomerId }, customer));
        }