Esempio n. 1
0
        public bool Delete(int id)
        {
            var employee = EmployeeDBContext.Employees.Find(id);

            EmployeeDBContext.Remove <Employee>(employee);
            EmployeeDBContext.SaveChanges();
            return(true);
        }
Esempio n. 2
0
        public ActionResult DeleteEmployeeById(int empId)
        {
            var result = _dBContext.Employees.Where(x => x.EmpId == empId).FirstOrDefault();

            if (result != null)
            {
                _dBContext.Remove(result);
                _dBContext.SaveChanges();
                return(Ok(result));
            }
            return(NoContent());
        }
        public async Task <bool> DeleteEmployeeAsync(int id)
        {
            var employee = await _Context.Employees
                           .SingleOrDefaultAsync(c => c.id == id);

            _Context.Remove(employee);
            try
            {
                return(await _Context.SaveChangesAsync() > 0 ? true : false);
            }
            catch (System.Exception exp)
            {
                _Logger.LogError($"Error in {nameof(DeleteEmployeeAsync)}: " + exp.Message);
            }
            return(false);
        }
        public async Task <bool> DeleteEmployeeAsync(int id)
        {
            //Extra hop to the database but keeps it nice and simple for this demo
            //Including orders since there's a foreign-key constraint and we need
            //to remove the orders in addition to the customer
            var employee = await _Context.Employees
                           .SingleOrDefaultAsync(c => c.id == id);

            _Context.Remove(employee);
            try
            {
                return(await _Context.SaveChangesAsync() > 0 ? true : false);
            }
            catch (System.Exception exp)
            {
                _Logger.LogError($"Error in {nameof(DeleteEmployeeAsync)}: " + exp.Message);
            }
            return(false);
        }