public Category UpsertCategory(Category category) { if(category.CategoryID == 0){ return Execute<Category>(() => { category.CategoryID = conn.Execute(@"INSERT category (Title, AccountID, ParentCategoryID) VALUES (@title, @accountID, @parentCategoryID); SELECT SCOPE_IDENTITY();", new { title = category.Title, parentCategoryID = category.ParentCategoryID, accountID = category.AccountID }); return category; }); }else{ conn.Execute(@"UPDATE category set Title=@title, AccountID=@accountID, ParentCategoryID=@parentCategoryID WHERE categoryID=@categoryID", new { category.CategoryID, category.Title, category.ParentCategoryID, category.AccountID }); return category; } }
public Category Update(Category Category) { return categoryRepository.UpsertCategory(Category); }
public Category SaveNew(Category Category) { Category.AccountID = getAccountID(); return categoryRepository.UpsertCategory(Category); }