public IActionResult Post([FromBody] TodoItem value) { var model = _context.TodoItems; var tempCategory = value.Category; if (string.IsNullOrEmpty(value.Id)) { value = _defaultUtility.GenerateItemModel(value); } value.Category = tempCategory; value.CategoryId = tempCategory.Id; model.Add(value); _context.SaveChanges(); return(Ok(model)); }
public IActionResult Post([FromBody] Category value) { var model = _context.Categories; var categoryItem = model.FirstOrDefault(x => x.Title == value.Title); if (categoryItem != null) { return(Ok(model)); } else { value = _categoryUtility.GenerateCategory(value); model.Add(value); _context.SaveChanges(); } return(Ok(model)); }