public void Alterar(ModelNota nota)
        {
            try
            {
                if (string.IsNullOrEmpty(nota.Titulo))
                {
                    throw new Exception("Título da nota não informado");
                }
                if (string.IsNullOrEmpty(nota.Dados))
                {
                    throw new Exception("Dados da nota não informados");
                }
                if (nota.Id <= 0)
                {
                    throw new Exception("Id da nota não informado");
                }

                int result = conn.Update(nota);
                StatusMessage = string.Format("{0} Registros alterados", result);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Erro: {0}", ex.Message));
            }
        }
 public void Inserir(ModelNota nota)
 {
     try
     {
         if (string.IsNullOrEmpty(nota.Titulo))
         {
             throw new Exception("Titulo da nota não informado");
         }
         if (string.IsNullOrEmpty(nota.Dados))
         {
             throw new Exception("Dados da nota não informado");
         }
         int result = conn.Insert(nota);
         if (result != 0)
         {
             this.StatusMessage =
                 String.Format("{0} registro(s) adicionado(s): [Nota: {1}]",
                               result, nota.Titulo);
         }
         else
         {
             string.Format("0 registro(s) adicionado(s)");
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
        private void ListaNotas_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            ModelNota        nota = (ModelNota)ListaNotas.SelectedItem;
            MasterDetailPage p    = (MasterDetailPage)Application.Current.MainPage;

            p.Detail = new NavigationPage(new CadastrarDetail(nota));
        }
        public async Task <dynamic> Upload(IFormFile file, [FromForm] ModelNota nota)
        {
            if (!ModelState.IsValid)
            {
                return(this.ResultAsync(HttpStatusCode.BadRequest));
            }

            // TODO[DH] use a pipeline instead of separate Send commands
            // daca nota este asociata sectiei
            int idSectie = await _mediator.Send(_mapper.Map <ModelSectieQuery>(nota));

            if (idSectie < 0)
            {
                return(this.ResultAsync(HttpStatusCode.NotFound));
            }

            var command     = _mapper.Map <AdaugaNotaCommand>(nota);
            var fileAddress = await _mediator.Send(new ModelFile { File = file });

            // TODO[DH] get the actual IdObservator from token
            command.IdObservator     = int.Parse(User.Claims.First(c => c.Type == "IdObservator").Value);
            command.CaleFisierAtasat = fileAddress;
            command.IdSectieDeVotare = idSectie;

            var result = await _mediator.Send(command);

            if (result < 0)
            {
                return(this.ResultAsync(HttpStatusCode.NotFound));
            }

            return(await Task.FromResult(new { FileAdress = fileAddress, nota = nota }));
        }
 private void btSalvar_Clicked(object sender, EventArgs e)
 {
     try
     {
         ModelNota nota = new ModelNota();
         nota.Titulo   = txtTitulo.Text;
         nota.Dados    = txtDados.Text;
         nota.Favorito = swFavorito.IsToggled;
         ServicesBDNota dbNotas = new ServicesBDNota(App.DbPath);
         if (btSalvar.Text == "Inserir")
         {
             dbNotas.Inserir(nota);
             DisplayAlert("Resultado da operação", dbNotas.StatusMessage, "OK");
         }
         else
         { //ALTERAR EM PROXIMA AULA
             nota.Id = id;
             dbNotas.Alterar(nota);
             DisplayAlert("Resultado da operação", dbNotas.StatusMessage, "OK");
         }
         voltar();
     }
     catch (Exception ex)
     {
         DisplayAlert("Erro", ex.Message, "OK");
     }
 }
        public CadastrarDetail(ModelNota nota)
        {
            InitializeComponent();
            btSalvar.Text = "Alterar";

            btExcluir.IsVisible = true;

            id                   = nota.Id;
            txtTitulo.Text       = nota.Titulo;
            txtDados.Text        = nota.Dados;
            swFavorito.IsToggled = nota.Favorito;
        }