Esempio n. 1
0
        public void IntegrationTest()
        {
            var connection = TestSession.GetConnection();

            connection.Open();
            #region good insertion and select by id test
            DepartmentModel inserted = new DepartmentModel();
            inserted.Name         = TestSession.Random.RandomString(50);
            inserted.GroupName    = TestSession.Random.RandomString(50);
            inserted.ModifiedDate = TestSession.Random.RandomDateTime();

            _tested.Insert(connection, new[] { inserted });

            var selectedAfterInsertion = _tested.GetByPrimaryKey(connection, new DepartmentModelPrimaryKey()
            {
                DepartmentID = inserted.DepartmentID,
            });

            CollectionAssert.IsNotEmpty(selectedAfterInsertion);
            var selectedAfterInsert = selectedAfterInsertion.Single();
            Assert.AreEqual(inserted.DepartmentID, selectedAfterInsert.DepartmentID);
            Assert.AreEqual(inserted.Name, selectedAfterInsert.Name);
            Assert.AreEqual(inserted.GroupName, selectedAfterInsert.GroupName);
            Assert.AreEqual(inserted.ModifiedDate, selectedAfterInsert.ModifiedDate);

            #endregion

            #region update and select by id test
            inserted.Name         = TestSession.Random.RandomString(50);
            inserted.GroupName    = TestSession.Random.RandomString(50);
            inserted.ModifiedDate = TestSession.Random.RandomDateTime();

            _tested.Update(connection, new[] { inserted });

            var selectedAfterUpdateAddresss = _tested.GetByPrimaryKey(connection, new DepartmentModelPrimaryKey()
            {
                DepartmentID = inserted.DepartmentID,
            });

            CollectionAssert.IsNotEmpty(selectedAfterUpdateAddresss);
            var selectedAfterUpdate = selectedAfterUpdateAddresss.Single();
            Assert.AreEqual(inserted.DepartmentID, selectedAfterUpdate.DepartmentID);
            Assert.AreEqual(inserted.Name, selectedAfterUpdate.Name);
            Assert.AreEqual(inserted.GroupName, selectedAfterUpdate.GroupName);
            Assert.AreEqual(inserted.ModifiedDate, selectedAfterUpdate.ModifiedDate);

            #endregion

            #region delete test
            _tested.Delete(connection, new[] { inserted });
            var selectedAfterDeleteAddresss = _tested.GetByPrimaryKey(connection, new DepartmentModelPrimaryKey()
            {
                DepartmentID = inserted.DepartmentID,
            });
            CollectionAssert.IsEmpty(selectedAfterDeleteAddresss);
            #endregion
            connection.Close();
        }
Esempio n. 2
0
        public void Delete(int id)
        {
            if (id == 0)
            {
                return;
            }

            dao.Delete(id);
            Core.AccountManager.RefreshCache();
        }
Esempio n. 3
0
        public IHttpActionResult Delete(int id)
        {
            try
            {
                var request = Context.GetCurrentRequest();
                var siteId  = request.GetQueryInt("siteId");
                if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(siteId, ApplicationUtils.PluginId))
                {
                    return(Unauthorized());
                }

                DepartmentDao.Delete(siteId, id);

                return(Ok(new
                {
                    Value = DepartmentManager.GetDepartmentInfoList(siteId)
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Esempio n. 4
0
 /// <summary>
 /// 删除部门
 /// </summary>
 /// <param name="did">部门编号</param>
 /// <returns></returns>
 public bool Delete(int did)
 {
     return(ddao.Delete(did));
 }