public ActionResult Delete(int?id, FormCollection collection)
 {
     try
     {
         DictionaryRepository ml = new DictionaryRepository();
         if (id != null && id > 0)
         {
             ml.Delete(id ?? 0);
         }
         else
         {
             if (string.IsNullOrEmpty(collection["IDs"]))
             {
                 return(Content("未指定删除对象ID"));
             }
             string[] ids = collection["IDs"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
             foreach (string item in ids)
             {
                 ml.Delete(int.Parse(item));
             }
         }
         return(Content("1"));
     }
     catch (Exception ex)
     {
         return(Content(ErrorWirter(RouteData, ex.Message)));
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 删除数据字典信息信息
        /// </summary>
        /// <param name="ids">要删除的数据字典信息编号</param>
        /// <returns>业务操作结果</returns>
        public OperationResult DeleteDictionarys(params int[] ids)
        {
            ids.CheckNotNull("ids");
            OperationResult result = DictionaryRepository.Delete(ids,
                                                                 entity =>
            {
                if (entity.Children.Any())
                {
                    throw new Exception("数据字典“{0}”的子级不为空,不能删除。".FormatWith(entity.Name));
                }
            });

            return(result);
        }
Esempio n. 3
0
        public void Can_Perform_Delete_On_DictionaryRepository()
        {
            // Arrange
            var provider           = new PetaPocoUnitOfWorkProvider();
            var unitOfWork         = provider.GetUnitOfWork();
            var languageRepository = new LanguageRepository(unitOfWork);
            var repository         = new DictionaryRepository(unitOfWork, languageRepository);

            // Act
            var item = repository.Get(1);

            repository.Delete(item);
            unitOfWork.Commit();

            var exists = repository.Exists(1);

            // Assert
            Assert.That(exists, Is.False);
        }
Esempio n. 4
0
        public void DictionaryRepositoryCrudTest()
        {
            //-- Arrange
            var dictionaryRepository = new DictionaryRepository <EquatableStringEntity>();
            var testEntity           = new EquatableStringEntity(1)
            {
                Data = "response1"
            };
            var updateEntity = new EquatableStringEntity(1)
            {
                Data = "response2"
            };
            var expectedAdded = new EquatableStringEntity(1)
            {
                Data = "response1"
            };
            var expectedUpdated = new EquatableStringEntity(1)
            {
                Data = "response2"
            };
            var expectedExceptionType    = typeof(System.Collections.Generic.KeyNotFoundException);
            var expectedExceptionMessage = "The given key '1' was not present in the dictionary.";

            //-- Act

            //-- Create
            dictionaryRepository.Add(testEntity);

            //-- Read
            var actualAdded = dictionaryRepository.FindById(testEntity.Id);

            //-- Update
            dictionaryRepository.Update(updateEntity);
            var actualUpdated = dictionaryRepository.FindById(testEntity.Id);

            //-- Delete
            dictionaryRepository.Delete(testEntity);
            EquatableStringEntity actualDeleted;

            System.Exception actualException;
            try
            {
                actualDeleted   = dictionaryRepository.FindById(testEntity.Id);
                actualException = new System.Exception();
            }
            catch (System.Collections.Generic.KeyNotFoundException ex)
            {
                actualDeleted   = null;
                actualException = ex;
            }
            catch (System.Exception ex)
            {
                actualException = ex;
                throw;
            }
            var actualExceptionType    = actualException.GetType();
            var actualExceptionMessage = actualException.Message;

            //-- Assert
            Assert.AreEqual(expectedAdded, actualAdded);
            Assert.AreEqual(expectedUpdated, actualUpdated);
            Assert.AreNotEqual(expectedAdded, actualUpdated);
            Assert.IsNull(actualDeleted);
            Assert.AreEqual(expectedExceptionType, actualExceptionType);
            Assert.AreEqual(expectedExceptionMessage, actualExceptionMessage);
        }
        public void Can_Perform_Delete_On_DictionaryRepository()
        {
            // Arrange
            var provider = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            var languageRepository = new LanguageRepository(unitOfWork);
            var repository = new DictionaryRepository(unitOfWork, languageRepository);

            // Act
            var item = repository.Get(1);
            repository.Delete(item);
            unitOfWork.Commit();

            var exists = repository.Exists(1);

            // Assert
            Assert.That(exists, Is.False);
        }