public virtual int ExecUpdate(EmployeeEditPage data)
        {
            if (data == null)
                throw new ArgumentNullException("data");

            EmployeeDto dto = new EmployeeDto();
            dto.Code = data.Code;
            dto.DeptNo = data.Depart;
            dto.EntryDay = data.Entry;
            dto.Gender = data.Gender;
            dto.Id = data.Id;
            dto.Name = data.Name;

            if (data.Id.HasValue)
            {
                EmployeeDto e1 = dao.GetData(data.Id.Value);
                if (e1 != null)
                    return (dao.UpdateData(dto));
                else
                    return (dao.InsertData(dto));
            }
            else
            {
                return (dao.InsertData(dto));
            }
        }
Пример #2
0
        public void TestInsertOfDao()
        {
            // 挿入のテスト
            EmployeeDto data = new EmployeeDto();
            data.Code = "060006";
            data.Name = "後藤六郎";
            data.EntryDay = new DateTime(2006, 4, 1, 0, 0, 0);
            data.Gender = 1;
            data.DeptNo = 1;

            Assert.AreEqual(1, daoOfEmp.InsertData(data), "Insert");

            // 更新のテスト
            int id = daoOfEmp.GetId("060006");
            data.Id = id;
            data.Code = "060006";
            data.Name = "五島六郎";
            data.EntryDay = new DateTime(2006, 4, 1, 0, 0, 0);
            data.Gender = 1;
            data.DeptNo = 2;

            Assert.AreEqual(1, daoOfEmp.UpdateData(data), "Update");

            data = daoOfEmp.GetData(id);
            Assert.AreEqual(id, data.Id.Value, "Id");
            Assert.AreEqual("五島六郎", data.Name, "Name");
            Assert.AreEqual("060006", data.Code, "Code");
            Assert.AreEqual(1, data.Gender, "Gender2");
            Assert.AreEqual(new DateTime(2006, 4, 1, 0, 0, 0),
                            data.EntryDay.Value, "Entry");
            Assert.AreEqual(2, data.DeptNo.Value, "DeptNo");
            Assert.AreEqual(2, data.Department.Id.Value, "Dept.No2");
            Assert.AreEqual("技術部", data.Department.Name, "Dept.Name2");
            Assert.AreEqual("0002", data.Department.Code, "Dept.Code2");

            // 削除のテスト
            data = new EmployeeDto();
            data.Id = id;

            Assert.AreEqual(1, daoOfEmp.DeleteData(data), "Delete");

            IList<EmployeeDto> list = daoOfEmp.GetAll();
            Assert.AreEqual(5, list.Count, "Count");
        }
        public virtual int ExecDelete(int id)
        {
            EmployeeDto data = new EmployeeDto();
            data.Id = id;

            return (dao.DeleteData(data));
        }