public async Task <EntityOperationResult <Organization> > DeleeteItemAsync(OrganizationDeleteDto deleteDto, string path) { using (var unitOfWork = _unitOfWorkFactory.MakeUnitOfWork()) { if (unitOfWork.Organization.IsHasDishesh(deleteDto.Id)) { return(EntityOperationResult <Organization> .Failure() .AddError($"Кафе с именем {deleteDto.Name} имеет блюда")); } try { var organization = unitOfWork.Organization.GetById(deleteDto.Id); FileService fileService = new FileService(null, path + "/Org/\\" + organization.PictureName, string.Empty, organization.PictureFormat); fileService.AddOrDelete(true); unitOfWork.Organization.Delete(organization); await unitOfWork.CompleteAsync(); return(EntityOperationResult <Organization> .Success(organization)); } catch (Exception ex) { return(EntityOperationResult <Organization> .Failure().AddError(ex.Message)); } } }
public async Task <int> Delete(OrganizationDeleteDto input) { var count = 0; var query = JIT_t_OrganizationUnit.GetAll().Where(p => p.Id == input.Id) .Include(p => p.Children); var entity = await query.SingleOrDefaultAsync(p => true); var ORByID = JIT_t_OrganizationUnit.GetAll().SingleOrDefault(p => p.Id == entity.ParentId); var EmployeeByID = EmployeeApp.GetOneselfAndJunior(new int[] { input.Id }); List <Entities.Employee> EmployeeList = new EditableList <Entities.Employee>(); if (EmployeeByID != null) { EmployeeList = EmployeeApp._ERepository.GetAll() .Where(p => p.IsDeleted == false && EmployeeByID.Contains(p.FDepartment)).ToList(); } if (entity != null) { foreach (var e in EmployeeList) { if (ORByID != null) { e.FDepartment = ORByID.Id; } else { e.FDepartment = EmployeeApp._ERepository.GetAll().FirstOrDefault(p => p.Id == entity.ParentId && p.IsDeleted == false).Id; } EmployeeApp._ERepository.Update(e); } entity.IsDeleted = true; entity.DeletionTime = DateTime.Now; entity.DeleterUserId = this.AbpSession.UserId.HasValue ? this.AbpSession.UserId.Value : 0; count++; foreach (var c in entity.Children) { c.IsDeleted = true; c.DeletionTime = DateTime.Now; c.DeleterUserId = this.AbpSession.UserId.HasValue ? this.AbpSession.UserId.Value : 0; count++; } await JIT_t_OrganizationUnit.UpdateAsync(entity); } return(count); }
public async Task <t_OrganizationUnit> Get(OrganizationDeleteDto input) { var entity = await JIT_t_OrganizationUnit.GetAll().SingleOrDefaultAsync(p => p.Id == input.Id && p.IsDeleted == false); return(entity.MapTo <t_OrganizationUnit>()); }