Пример #1
0
        public IHttpActionResult Put(TarefaEnvelopeJson tarefa, int id)
        {
            try
            {
                if (!this.tarefaBusiness.Validate(tarefa))
                {
                    return(BadRequest("As informações do registro não são válidas!"));
                }

                if (id != tarefa.TarefaID)
                {
                    return(BadRequest("O id da tarefa não corresponde com o do objeto!"));
                }

                if (!this.tarefaBusiness.Exists(t => t.TarefaID == id))
                {
                    return(BadRequest("Nenhum registro encontrado!"));
                }

                this.tarefaBusiness.Edit(ref tarefa);

                return(Ok(tarefa));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Пример #2
0
 public TarefaEnvelopeJson GetById(int id)
 {
     try
     {
         Tarefa             tarefa = this.tarefaService.GetById(id);
         TarefaEnvelopeJson entity = tarefa.Map <Tarefa, TarefaEnvelopeJson>();
         return(entity);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #3
0
 public void Edit(ref TarefaEnvelopeJson entity)
 {
     try
     {
         Tarefa tarefa = entity.Map <TarefaEnvelopeJson, Tarefa>();
         this.tarefaService.Edit(tarefa);
         entity = tarefa.Map <Tarefa, TarefaEnvelopeJson>();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #4
0
        public bool Validate(TarefaEnvelopeJson instance)
        {
            bool valid = true;

            if (instance == null)
            {
                valid = false;
            }

            if (instance.UsuarioID == 0)
            {
                valid = false;
            }

            if (string.IsNullOrWhiteSpace(instance.Titulo))
            {
                valid = false;
            }

            if (string.IsNullOrWhiteSpace(instance.Descricao))
            {
                valid = false;
            }

            if (string.IsNullOrWhiteSpace(instance.DataCadastro))
            {
                valid = false;
            }
            else
            {
                DateTime validDate;
                DateTime.TryParse(instance.DataCadastro, out validDate);
                if (validDate == DateTime.MinValue)
                {
                    valid = false;
                }
            }

            if (!string.IsNullOrWhiteSpace(instance.DataConclusao))
            {
                DateTime validDate;
                DateTime.TryParse(instance.DataConclusao, out validDate);
                if (validDate == DateTime.MinValue)
                {
                    valid = false;
                }
            }

            return(valid);
        }
Пример #5
0
 public TarefaEnvelopeJson ChangeSituation(int id)
 {
     try
     {
         Tarefa tarefa = this.tarefaService.GetById(id);
         tarefa.Concluida     = !tarefa.Concluida;
         tarefa.DataConclusao = DateTime.Now;
         this.tarefaService.Edit(tarefa);
         TarefaEnvelopeJson entity = tarefa.Map <Tarefa, TarefaEnvelopeJson>();
         return(entity);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #6
0
        public IHttpActionResult Post(TarefaEnvelopeJson tarefa)
        {
            try
            {
                if (!this.tarefaBusiness.Validate(tarefa))
                {
                    return(BadRequest("As informações do registro não são válidas!"));
                }

                this.tarefaBusiness.Add(ref tarefa);
                return(Ok(tarefa));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Пример #7
0
        public IHttpActionResult Get(int id)
        {
            try
            {
                TarefaEnvelopeJson tarefa = this.tarefaBusiness.GetById(id);

                if (tarefa == null)
                {
                    return(BadRequest("Nenhum registro encontrado!"));
                }

                return(Ok(tarefa));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Пример #8
0
        public IHttpActionResult PutChangeSituation(int id)
        {
            try
            {
                if (!this.tarefaBusiness.Exists(t => t.TarefaID == id))
                {
                    return(BadRequest("Nenhum registro encontrado!"));
                }

                TarefaEnvelopeJson tarefa = this.tarefaBusiness.ChangeSituation(id);

                return(Ok(tarefa));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }