public override async Task <ServiceResult> Delete(int id) { var getDoktorResult = await GetDoktor(id); if (!getDoktorResult.Succeeded) { return(ServiceResult.WithStatusCode(getDoktorResult.StatusCode, getDoktorResult.Message)); } var doktorFromDb = getDoktorResult.doktor; if (!await _authService.CurrentUserIsInRoleAsync(RoleType.Administrator) && doktorFromDb.Radnik.KorisnickiNalogId != ((await _authService.LoggedInUser())?.Id ?? 0)) { return(ServiceResult.Forbidden("Ne mozete vrsiti izmene na drugim profilima doktora.")); } if (await _dbContext.Uputnice.AnyAsync(x => x.UputioDoktorId == doktorFromDb.Id || x.UpucenKodDoktoraId == doktorFromDb.Id)) { return(ServiceResult.BadRequest("Ne mozete izbrisati profil doktora sve dok postoje uputnice koje su povezane sa ovim doktorom.")); } if (await _dbContext.ZahteviZaPregled.AnyAsync(x => x.DoktorId == doktorFromDb.Id)) { return(ServiceResult.BadRequest("Ne mozete izbrisati profil doktora sve dok postoje zahtevi za pregled kod ovog doktora.")); } if (await _dbContext.Pregledi.AnyAsync(x => x.DoktorId == doktorFromDb.Id)) { return(ServiceResult.BadRequest("Ne mozete izbrisati profil doktora sve dok postoje zakazani ili odradjeni pregledi koje je odradio ovaj doktor.")); } if (await _dbContext.ZdravstvenaKnjizica.AnyAsync(x => x.DoktorId == doktorFromDb.Id)) { return(ServiceResult.BadRequest("Ne mozete izbrisati profil doktora sve dok ima zdravstvenih knjizica koje su povezane sa ovim doktorom.")); } await _radnikService.Delete(doktorFromDb.RadnikId); await Task.Run(() => { _dbContext.Remove(doktorFromDb); }); await _dbContext.SaveChangesAsync(); return(ServiceResult.NoContent()); }
public override async Task <ServiceResult> Delete(int id) { var entity = await _dbContext.RadniciPrijem.FindAsync(id); if (entity == null) { return(ServiceResult.NotFound($"RadnikPrijem sa ID-em {id} nije pronadjen.")); } await Task.Run(() => { _radnikService.Delete(id); _dbContext.Remove(entity); }); await _dbContext.SaveChangesAsync(); return(new ServiceResult()); }