public long SaveCategory(CategoryModel model) { CategoryRepository cRepo = new CategoryRepository(_dal); Category category = new Category { id = model.Id, name = model.Name.Escape().Trim() }; if(category.id == 0) { try { _dal.BeginTransaction(); long ret = cRepo.Insert(category); if (ret == 0) throw new Exception("Category was not inserted."); long id = cRepo.GetLastInsertId(); _dal.CommitTransaction(); return id; } catch(Exception ex) { _dal.RollbackTransaction(); log.Error(ex); throw; } } else { try { _dal.BeginTransaction(); long ret = cRepo.Update(category); if (ret == 0) throw new Exception("Category was not updated."); _dal.CommitTransaction(); return model.Id; } catch(Exception ex) { _dal.RollbackTransaction(); log.Error(ex); throw; } } }
public int Insert(Category category) { return _dal.Insert<Category>("insertCategory", category); }
public int Update(Category category) { return _dal.Update<Category>("updateCategory", category); }
public int Delete(Category category) { return _dal.Delete<Category>("deleteCategory", category); }