예제 #1
0
        public OperationResult DeleteEmployeeWithProfile(Guid EmployeeId)
        {
            var valueFromBd = dbContext.Employees.Find(EmployeeId);

            if (valueFromBd == null)
            {
                return(OperationResult.BuildNotFoundError("Сотрудник с таким id не найден"));
            }

            var attachedProfile = dbContext.Profiles.FirstOrDefault(p => p.EmployeeId == valueFromBd.Id);

            dbContext.Remove(valueFromBd);
            if (attachedProfile != null)
            {
                dbContext.Remove(attachedProfile);
            }

            dbContext.SaveChanges();
            return(OperationResult.BuildSuccess());
        }
        public OperationResult Delete(TKey key)
        {
            var valueFromBd = dbContext.Find <T>(key);

            if (valueFromBd == null)
            {
                return(OperationResult.BuildNotFoundError(typeName + " с таким id не найден"));
            }
            dbContext.Remove(valueFromBd);
            dbContext.SaveChanges();
            return(OperationResult.BuildSuccess());
        }