コード例 #1
0
 private void salvarBtn_Click(object sender, EventArgs e)
 {
     if (validateForm())
     {
         if (opt == App.CrudOpt.CADASTRAR)
         {
             List <Model.Item>           itens      = new List <Model.Item>();
             Emprestimo.Model.Emprestimo emprestimo = new Model.Emprestimo();
             emprestimo.aluno       = (Pessoa.Model.Aluno)alunoCb.SelectedItem;
             emprestimo.dataEntrada = DateTime.Now;
             emprestimo.dataSaida   = DateTime.Parse(dataDevolucaoTb.Text);
             emprestimo.usuario     = App.Service.Session.getUserLogged();
             foreach (Livro.Model.Livro l in livrosEmprestimo)
             {
                 Model.Item item = new Model.Item();
                 item.emprestimo = emprestimo;
                 item.livro      = l;
                 //Emprestado
                 item.situacao = 1;
                 itens.Add(item);
                 l.quantidade -= 1;
                 livroDao.update(l);
                 livroDao.saveChanges();
             }
             emprestimo.itens = itens;
             emprestimoDao.add(emprestimo);
             emprestimoDao.saveChanges();
             MessageBox.Show("Emprestimo realizado com sucesso, codigo gerado: " + emprestimo.id);
             new Relatorio(emprestimo).ShowDialog();
             this.Close();
         }
     }
 }
コード例 #2
0
 public DadosForm(Model.Emprestimo e)
 {
     InitializeComponent();
     this.emprestimo          = e;
     this.itens               = e.itens;
     this.quantidadeDevolucao = 0;
     this.calcularQuantidadeDevolucao();
 }
コード例 #3
0
        public async Task <IActionResult> Put([FromBody] Model.Emprestimo amigo)
        {
            if (amigo == default(API.Model.Emprestimo))
            {
                return(BadRequest());
            }

            var item = await _emprestimoRepository.UpdateAsync(amigo);

            return(Accepted(item));
        }
コード例 #4
0
        public async Task <Model.Emprestimo> AddAsync(Model.Emprestimo emprestimo)
        {
            var id = _emprestimoContext.Emprestimos.Select(x => x.Id).ToList().Max() + 1;

            emprestimo.SetId(id);
            _emprestimoContext.Emprestimos.Add(emprestimo);

            await _emprestimoContext.SaveChangesAsync();

            return(await GetAsync(emprestimo.Id));
        }
コード例 #5
0
        public async Task <Model.Emprestimo> UpdateAsync(Model.Emprestimo emprestimo)
        {
            var am = await _emprestimoContext.Emprestimos.FirstOrDefaultAsync(x => x.Id == emprestimo.Id);

            if (am == default(Model.Emprestimo))
            {
                return(default(Model.Emprestimo));
            }

            _emprestimoContext.Entry(am).CurrentValues.SetValues(emprestimo);

            await _emprestimoContext.SaveChangesAsync();

            return(await GetAsync(emprestimo.Id));
        }