public virtual int ExecUpdate(DepartmentEditPage dto) { if (dto == null) throw new ArgumentNullException("dto"); DepartmentDto data = new DepartmentDto(); data.Code = dto.Code; data.Id = dto.Id; data.Name = dto.Name; data.ShowOrder = Convert.ToInt32(dto.Order); if (dto.Id.HasValue) { DepartmentDto departmentDto = dao.GetData(dto.Id.Value); if (departmentDto != null) return (dao.UpdateData(data)); else return (dao.InsertData(data)); } else { return (dao.InsertData(data)); } }
public void TestInsertOfDao() { // 挿入のテスト DepartmentDto data = new DepartmentDto(); data.Code = "0102"; data.Name = "管理部"; data.ShowOrder = 4; Assert.AreEqual(1, daoOfDepartment.InsertData(data), "Insert"); // 更新のテスト int id = daoOfDepartment.GetId("0102"); data = new DepartmentDto(); data.Code = "0102"; data.Id = id; data.Name = "事業管理部"; data.ShowOrder = 4; Assert.AreEqual(1, daoOfDepartment.UpdateData(data), "Update"); data = daoOfDepartment.GetData(id); Assert.AreEqual(id, data.Id.Value, "ID"); Assert.AreEqual("0102", data.Code, "Code"); Assert.AreEqual("事業管理部", data.Name, "Name"); Assert.AreEqual(4, data.ShowOrder, "Order"); // 削除のテスト data = new DepartmentDto(); data.Id = id; Assert.AreEqual(1, daoOfDepartment.DeleteData(data), "Delete"); IList<DepartmentDto> list = daoOfDepartment.GetAll(); Assert.AreEqual(3, list.Count, "Count"); }
public virtual int ExecDelete(int id) { DepartmentDto data = new DepartmentDto(); data.Id = id; return (dao.DeleteData(data)); }