Beispiel #1
0
        public Checklist delete(int id)
        {
            bool isCheckListDeleted    = true;
            bool isItemsDeleted        = true;
            bool isTranslationsDeleted = true;

            Checklist checklistToDelete = _checklistRepo.GetChecklistById(id)
                                          .Include("Items")
                                          .Single();

            var itemsToDelete = checklistToDelete.Items.ToList();

            Checklist deletedChecklist = _checklistRepo.DeleteChecklist(id);

            if (!itemsToDelete.Any() || itemsToDelete == null)
            {
                isCheckListDeleted = _checklistRepo.Save();

                if (!isCheckListDeleted)
                {
                    deletedChecklist = null;
                }

                return(deletedChecklist);
            }
            else
            {
                //Delete all Items and corresponding translations
                foreach (var item in itemsToDelete)
                {
                    Item itemToDelete = _itemRepo.GetItemById(item.Id).FirstOrDefault();

                    List <Translation> translationsToDelete = _translationRepo.GetTranslations(item.Id).ToList();

                    foreach (var translationToDelete in translationsToDelete)
                    {
                        if (translationToDelete != null)
                        {
                            _translationRepo.DeleteTranslation(translationToDelete);
                        }
                    }

                    if (itemToDelete != null)
                    {
                        _itemRepo.DeleteItem(itemToDelete);
                    }
                }

                isCheckListDeleted    = _checklistRepo.Save();
                isTranslationsDeleted = _translationRepo.Save();
                isItemsDeleted        = _itemRepo.Save();

                if (!isTranslationsDeleted || !isTranslationsDeleted && !isTranslationsDeleted)
                {
                    deletedChecklist = null;
                }

                return(deletedChecklist);
            }
        }
        public Item delete(int id)
        {
            Item itemToDelete = _itemRepo.GetItemById(id).FirstOrDefault();
            List <Translation> translationsToDelete = _translationRepo.GetTranslations(id).ToList();

            bool isItemDeleted         = true;
            bool isTranslationsDeleted = true;

            foreach (var translationToDelete in translationsToDelete)
            {
                if (translationToDelete != null)
                {
                    _translationRepo.DeleteTranslation(translationToDelete);
                }
            }

            isTranslationsDeleted = _translationRepo.Save();

            if (itemToDelete != null)
            {
                _itemRepo.DeleteItem(itemToDelete);
                isItemDeleted = _itemRepo.Save();
            }

            if (isItemDeleted && isTranslationsDeleted)
            {
                return(itemToDelete);
            }

            return(null);
        }