Exemplo n.º 1
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));
        }
Exemplo n.º 2
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));
        }