Example #1
0
        public async Task <IActionResult> InsertData([FromBody] TodoItem todoItem)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var result = await _context.AddAsync <TodoItem>(todoItem);

                    int res = _context.SaveChanges();

                    if (res > 0)
                    {
                        return(Ok(result));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
            }
            catch (Exception)
            {
                return(BadRequest());
            }

            return(BadRequest());
        }
Example #2
0
        public async Task <TodoItem> AddTodoItem(TodoItem item)
        {
            TodoItemValidator todoItemValidator = new TodoItemValidator(_context);

            ValidationResult result = todoItemValidator.Validate(item);

            if (result.IsValid)
            {
                var itemReturn = await _context.AddAsync(item);

                await _context.SaveChangesAsync();

                return(item);
            }
            else if (result.Errors.Select(w =>
                                          w.ErrorMessage.Contains("existe") &&
                                          w.ErrorMessage.Contains("tarefa")) != null)
            {
                return new TodoItem {
                           Name = result.Errors.FirstOrDefault().ErrorMessage
                }
            }
            ;

            return(null);
        }
    }
        public async Task <ActionResult <TodoItem> > Post([FromBody] TodoItem todoItem)
        {
            await _todoContext.AddAsync(todoItem);

            await _todoContext.SaveChangesAsync();

            return(CreatedAtAction(nameof(Get), new { id = todoItem.Id }, todoItem));
        }
Example #4
0
        public virtual async Task <BaseResponse> Add(T entity, bool isGenerateId = true)
        {
            entity.CreatedDate = DateTime.Now;
            entity.CreatedBy   = _parameterService.UserId;
            if (isGenerateId)
            {
                entity.Id = Guid.NewGuid().ToString();
            }
            try
            {
                var x = await _context.AddAsync(entity);

                return(await SaveChanges(entity));
            }
            catch (Exception ex)
            {
                //todo: Exception messaj türlerine göre handle edilmeli.
                return(new ErrorResponse(State.ConnectionError, "System Error", ex.Message));
            }
        }
Example #5
0
        public async Task Add(Domain.Category category)
        {
            var categoryToAdd = _mapper.Map <Entities.Category>(category);

            await _ctx.AddAsync(categoryToAdd);
        }
Example #6
0
 public async Task AddAsync(Todo todo)
 {
     await context.AddAsync(todo);
 }