Example #1
0
        // GET: api/TaskList/5
        public TaskListModel Get(int id)
        {
            var taskList = new TaskListBusiness().GetByID(id);

            if (taskList == null)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"Tarefa Id={id} não encontrada."));
            }
            return(mapper.Map <TaskListModel>(taskList));
        }
Example #2
0
        public IList <TaskListModel> GetTask(string idUsuario)
        {
            var taskList = new TaskListBusiness().GetWhere(e => e.IdUsuario == idUsuario);

            //var taskList = new TaskListBusiness().GetAll();

            if (taskList == null)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"Erro ao consultar tarefas."));
            }
            return(mapper.Map <IList <TaskListModel> >(taskList));
        }
Example #3
0
        public bool Delete(int id)
        {
            var business = new TaskListBusiness();
            var entity   = business.GetByID(id);

            if (entity == null)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"Tarefa Id={id} não encontrada."));
            }

            entity.DataExclusao = DateTime.Now;
            entity.IdStatus     = (int)TaskListEnumModel.StatusTaskList.Cancelada;
            business.Update(entity);
            return(true);
        }
Example #4
0
        public TaskListModel Post([FromBody] TaskListModel taskListModel)
        {
            var business = new TaskListBusiness();
            var taskList = mapper.Map <Entity.TaskList>(taskListModel);

            taskList.DataCriacao   = DateTime.Now;
            taskList.DataAlteracao = null;
            taskList.DataExclusao  = null;
            taskList.DataConclusao = null;
            taskList.IdStatus      = (int)TaskListEnumModel.StatusTaskList.Pendente;

            var result = business.Insert(taskList);

            if (!result)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"Erro ao incluir tarefa."));
            }
            return(mapper.Map <TaskListModel>(taskList));
        }
Example #5
0
        public TaskListModel Put(int id, [FromBody] TaskListModel taskListModel)
        {
            var business = new TaskListBusiness();

            var entity = business.GetByID(id);

            if (entity == null)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"Tarefa Id={id} não encontrada."));
            }

            var taskList = mapper.Map <Entity.TaskList>(taskListModel);

            taskList.DataAlteracao = DateTime.Now;

            var result = business.Update(entity, taskList);

            if (!result)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"Erro ao incluir tarefa."));
            }

            return(mapper.Map <TaskListModel>(taskList));
        }