public Tuple <bool, string> Delete(StructureTreeModel model) { try { var exist = _organizationStructureNameRepository.Where(x => x.Id == model.OrgId).Any(); if (!exist) { return(new Tuple <bool, string>(false, "خطا در انجام عملیات، درخواست نامعتبر")); } _unitOfWork.BeginTransaction(); switch (model.StructureType) { case StructureType.College: if (_postPersonRepository.Contains(x => x.CollegeId == model.Id)) { return(new Tuple <bool, string>(false, "خطا در انجام عملیات، انتساب سمت در این سطح انجام شده است!")); } if (_educationalGroupRepository.Contains(x => x.CollegeId == model.Id)) { return(new Tuple <bool, string>(false, "خطا در انجام عملیات، این آیتم زیرمجموعه دارد!")); } _collegeRepository.Delete(x => x.Id == model.Id); _organizationStructureNameRepository.Delete(x => x.Id == model.OrgId); break; case StructureType.EducationalGroup: if (_postPersonRepository.Contains(x => x.EducationalGroupId == model.Id)) { return(new Tuple <bool, string>(false, "خطا در انجام عملیات، انتساب سمت در این سطح انجام شده است!")); } if (_fieldofStudyRepository.Contains(x => x.EducationalGroupId == model.Id)) { return(new Tuple <bool, string>(false, "خطا در انجام عملیات، این آیتم زیرمجموعه دارد!")); } _educationalGroupRepository.Delete(x => x.Id == model.Id); _organizationStructureNameRepository.Delete(x => x.Id == model.OrgId); break; case StructureType.FieldofStudy: if (_studentRepository.Contains(x => x.FieldofStudyId == model.Id)) { return(new Tuple <bool, string>(false, "خطا در انجام عملیات، دانشجو در این رشته تعریف شده است!")); } _fieldofStudyRepository.Delete(x => x.Id == model.Id); _organizationStructureNameRepository.Delete(x => x.Id == model.OrgId); break; } _unitOfWork.SaveChanges(); _unitOfWork.CommitTransaction(); return(new Tuple <bool, string>(true, "عملیات حذف انجام شد")); } catch (Exception exception) { _unitOfWork.Rollback(); return(new Tuple <bool, string>(false, "خطا در انجام عملیات")); } }
public ActionResult DeleteConform(int id) { try { College college = _collegeRepository.GetId(id); _collegeRepository.Delete(id); _collegeRepository.Save(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ICommandResult Handle(DeleteCollegeCommand command) { string id = command.Id.ToString(); if (string.IsNullOrEmpty(id)) { AddNotification("Id", "Identificador inválido"); } if (Invalid) { return(new CommandResult(false, "Erro ao deletar faculdade", Notifications)); } _repository.Delete(command); return(new CommandResult(true, "Faculdade deletada com sucesso", null)); }