Exemple #1
0
        public IActionResult BrisanjeOsobe(long id)
        {
            try
            {
                Osoba osoba = _repository.EntitetPoId(id);

                if (osoba == null)
                {
                    return(NotFound());
                }

                var mozda = (from nn in _osobaUredjajRepository.DajSveEntitete()
                             where nn.Osoba == osoba
                             select new { Osoba = nn.Osoba.Ime, Uredjaj = nn.Uredjaj.Naziv }).FirstOrDefault();

                if (mozda != null)
                {
                    return(BadRequest("Osoba nije izbrisana iz baze zato sto je vec koristila/koristi neki od uredjaja."));
                }

                _repository.ObrisiEntitet(osoba);
                _unitOfWork.Sacuvaj();

                return(Ok("Osoba je izbrisana iz baze podataka."));
            }
            catch (Exception ex)
            {
                Error greska = new Error()
                {
                    Exception  = ex.Message,
                    StackTrace = ex.StackTrace
                };
                return(BadRequest(greska));
            }
        }