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()); }
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)); }
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)); } }
public async Task Add(Domain.Category category) { var categoryToAdd = _mapper.Map <Entities.Category>(category); await _ctx.AddAsync(categoryToAdd); }
public async Task AddAsync(Todo todo) { await context.AddAsync(todo); }