예제 #1
0
        public void ExcluirLeito(Leito leito)
        {
            if (leito == null)
            {
                throw new ArgumentNullException(nameof(leito));
            }

            try
            {
                // Remove todos os acompanhantes e acompanhamentos
                foreach (var internacao in leito.Internacoes)
                {
                    foreach (var acompanhante in internacao.Acompanhantes)
                    {
                        this._context.Acompanhamentos.RemoveRange(acompanhante.Acompanhamentos);
                    }

                    this._context.Acompanhantes.RemoveRange(internacao.Acompanhantes);
                }

                this._context.Leitos.Remove(leito);
                this._context.SaveChanges();
            }
            catch (RetryLimitExceededException ex)
            {
                this._logger.Error(ex.StackTrace);
                throw;
            }
        }
예제 #2
0
        public void AtualizarLeito(Leito leito)
        {
            if (leito == null)
            {
                throw new ArgumentNullException(nameof(leito));
            }

            try
            {
                this._context.Entry(leito).State = EntityState.Modified;
                this._context.SaveChanges();
            }
            catch (RetryLimitExceededException ex)
            {
                this._logger.Error(ex.StackTrace);
                throw;
            }
        }
예제 #3
0
        public ActionResult Criar([Bind(Exclude = "Id")] LeitoViewModel viewModel)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View(viewModel);
            }

            var leito = new Leito
            {
                Quarto = viewModel.Quarto,
                Tipo = viewModel.Tipo,
                Setor = viewModel.Setor,
                Ocupado = false,
                Ativo = viewModel.Ativo
            };

            var leitoId = this._servico.CriarLeito(leito);
            this.LogAcao(leitoId);

            return this.RedirectToAction("Index");
        }
예제 #4
0
        public int CriarLeito(Leito leito)
        {
            if (leito == null)
            {
                throw new ArgumentNullException(nameof(leito));
            }

            try
            {
                leito.Hospital = this._context.Hospitais.First();
                this._context.Leitos.Add(leito);
                this._context.SaveChanges();
            }
            catch (RetryLimitExceededException ex)
            {
                this._logger.Error(ex.StackTrace);
                throw;
            }

            return leito.Id;
        }