public NuevaTareaViewModel(INavigator navigator, IServicioDatos servicioDatos, Session session, IPage page) : base(navigator, servicioDatos, session, page)
 {
     _tarea = new TareaModel();
     CmdAgregar = new Command(Agregar);
     CmdAgregarUbicacion = new Command(AgregarUbicacion);
     CmdAgregarImagen = new Command(AgregarImagen);
 }
        public IHttpActionResult Post(TareaModel model)
        {
            var data = TareaRepositorio.Add(model);

            if (data == null)
                return BadRequest();

            return Ok(data);
        }
        public IHttpActionResult Put(int id, TareaModel model)
        {
            //var d = TareaRepositorio.Get(id);
            if (/*d == null ||*/ id != model.Id)
                return BadRequest();


            var data = TareaRepositorio.Update(model);

            if (data < 1)
                return BadRequest();

            return Ok();
        }
 public async Task EditarTarea(TareaModel model)
 {
     await _navigator.PushAsync<NuevaTareaViewModel>(vm =>
     {
         vm.Titulo = "Editar tarea de " + Titulo;
         vm.AgregarLbl = "Guardar cambios";
         vm.Tarea = model;
         vm.Editing = true;
     });
 }
        public async Task FinalizarTarea(TareaModel model)
        {
            try
            {
                IsBusy = true;
                model.Finalizada = true;
                var res = await _servicioDatos.UpdateTarea(model);

                if (res)
                {
                    await _page.MostrarAlerta("", "Tarea finalizada", "Ok");
                }
                else
                    await _page.MostrarAlerta("", "La tarea no pudo ser finalizada", "Ok");
            }
            catch (Exception ex)
            {
                await _page.MostrarAlerta("Error", ex.Message, "Ok");
            }
            finally
            {
                IsBusy = false;
            }
        }
        public async Task<bool> UpdateTarea(TareaModel model)
        {
            var request = new RestRequest("Tarea") { Method = Method.PUT };
            request.AddQueryParameter("id", model.Id);
            request.AddJsonBody(model);

            try
            {
                var response = await _client.Execute(request);
                if (response.IsSuccess)
                    return true;
            }
            catch (Exception ex)
            {

                var r = ex.Message;
            }

            return false;
        }
        public async Task<TareaModel> AddTarea(TareaModel model)
        {
            var request = new RestRequest("Tarea")
            {
                Method = Method.POST
            };
            request.AddJsonBody(model);
            var response = await _client.Execute<TareaModel>(request);

            if (response.IsSuccess)
                return response.Data;
            return null;
        }