本文整理汇总了C#中BaseRepository.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# BaseRepository.Delete方法的具体用法?C# BaseRepository.Delete怎么用?C# BaseRepository.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseRepository
的用法示例。
在下文中一共展示了BaseRepository.Delete方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Customer_Add_SingleRecord
public void Customer_Add_SingleRecord()
{
dataSetup.AddOrUpdateCustomer(dataSetup.getCustomer2());
IList<Customer> customers = new List<Customer>();
using (var repo = new BaseRepository<Customer>())
{
customers = (IList<Customer>)repo.findAll();
Assert.AreEqual(customers.Count, 1);
repo.Delete(customers);
repo.save();
}
}
示例2: Customer_DeleteById_SingleRecord
public void Customer_DeleteById_SingleRecord()
{
Customer temp = dataSetup.getCustomer3();
dataSetup.AddOrUpdateCustomer(temp);
IList<Customer> customers = new List<Customer>();
using (var repo = new BaseRepository<Customer>())
{
repo.Delete(temp);
repo.save();
Customer c = repo.FindById(dataSetup.newCustId);
Assert.IsNull(c);
}
}
示例3: Delete_expect_call_helper_delete_object
public void Delete_expect_call_helper_delete_object()
{
_config.EnableCaching = false;
var storageHelper = MockRepository.GenerateStub<IStorageHelper<FakeObject>>();
storageHelper.Stub(h => h.DeleteObject(FakeObject.InstanceIdentifier));
var repo = new BaseRepository<FakeObject>(_config) { StorageHelper = storageHelper };
repo.Delete(FakeObject.InstanceIdentifier);
storageHelper.AssertWasCalled(h => h.DeleteObject(FakeObject.InstanceIdentifier));
}
示例4: Delete_with_caching_enabled_expect_cache_purged
public void Delete_with_caching_enabled_expect_cache_purged()
{
_config.EnableCaching = true;
var storageHelper = MockRepository.GenerateStub<IStorageHelper<FakeObject>>();
storageHelper.Stub(h => h.DeleteObject(FakeObject.InstanceIdentifier));
var cacheHelper = MockRepository.GenerateStub<ICacheHelper<FakeObject>>();
var repo = new BaseRepository<FakeObject>(_config) { StorageHelper = storageHelper, CacheHelper = cacheHelper };
repo.Delete(FakeObject.InstanceIdentifier);
cacheHelper.AssertWasCalled(c => c.PurgeCacheItems());
}
示例5: DeleteResultItems
/// <summary>
/// Remove all records from ResultItems table
/// filter by resultId
/// It is need for clearing db when person get profile and all inerpretations
/// by result of one test
/// Data fron Rwsult items not need yet
/// </summary>
/// <param name="resultId"></param>
public void DeleteResultItems(Guid resultId)
{
using (var resultRepository = new BaseRepository<Result>())
{
if (!resultRepository.GetAllItems.Any(x => x.Id == resultId))
{
throw new ResultDoesNotExistException();
}
}
// 1 variant remove Result items
using (var resulItemtRepository = new BaseRepository<ResultItem>())
{
var resultItems = resulItemtRepository.GetAllItems.Where(x => x.Result.Id == resultId);
foreach (var resultItem in resultItems.ToList())
{
if (!resulItemtRepository.Delete(resultItem).Status)
{
throw new DeleteException();
}
}
}
// 2 variant, remove only foreign key to Result
//using (var resultRepository = new BaseRepository<Result>())
//{
// var Result = resultRepository.GetAllItems.FirstOrDefault(x => x.Id == resultId);
// if (Result == null)
// {
// throw new ResultDoesNotExistException();
// }
// Result.ResultItems.ToList().ForEach(x => Result.ResultItems.Remove(x));
// if (!resultRepository.Update(Result).Status)
// {
// throw new UpdateException();
// }
//}
}
示例6: DeleteGroupUser
public void DeleteGroupUser(GroupUser groupUser, long groupId, OldUser curator)
{
using (var groupUserRepository = new BaseRepository<GroupUser>())
{
var group = groupUserRepository.Context.Groups.FirstOrDefault(x => x.Id == groupId);
if (group == null)
{
throw new PersonsGroupDoesNotExistException();
}
if (!String.Equals(curator.Role.Name, Constraints.KCuratorRoleName)
|| curator.Id != group.Curator)
{
throw new UserRightsException();
}
var deletedGroupUser = groupUserRepository.GetAllItems.FirstOrDefault(x => x.Id == groupUser.Id);
if (deletedGroupUser == null)
{
throw new UserDoesNotExistException();
}
if (deletedGroupUser.Group.Id != groupId)
{
throw new GroupUserException();
}
if (!groupUserRepository.Delete(deletedGroupUser).Status)
{
throw new DeleteException();
}
}
}
示例7: DeleteGroup
public bool DeleteGroup(Group group)
{
using (var groupRepository = new BaseRepository<Group>())
{
var deletedGroup = groupRepository.GetAllItems.FirstOrDefault(x => x.Id == group.Id);
if (deletedGroup == null)
{
throw new PersonsGroupDoesNotExistException();
}
if (deletedGroup.Curator != group.Curator)
{
throw new UserRightsException();
}
if (groupRepository.Delete(deletedGroup).Status)
{
return true;
}
throw new DeleteException();
}
}
示例8: SetSurveysAnswers
public void SetSurveysAnswers(long surveysResultId, List<SurveysAnswerContent> surveysAnswerContents)
{
using (var surveysAnswerRepository = new BaseRepository<SurveysAnswer>())
{
SurveysResult surveysResult =
surveysAnswerRepository.Context.SurveysResults.FirstOrDefault(x => x.Id == surveysResultId);
if (surveysResult == null)
{
throw new SurveysResultDoesNotExistException();
}
// Rewrite surveys answers if exists
List<SurveysAnswer> surveysAnswers =
surveysAnswerRepository.GetAllItems.Where(x => x.SurveysResult.Id == surveysResultId).ToList();
if (surveysAnswers.Count != 0)
{
// Remove all surveys answers
foreach (var surveysAnswer in surveysAnswers)
{
surveysAnswerRepository.Delete(surveysAnswer);
}
}
if (surveysAnswerContents == null)
{
return;
}
foreach (var surveysAnswerContent in surveysAnswerContents)
{
foreach (var answerContent in surveysAnswerContent.Answers)
{
surveysAnswerRepository.Create(new SurveysAnswer()
{
QuestionId = surveysAnswerContent.QuestionId,
Answer = answerContent.Id,
SurveysResult = surveysResult
});
}
}
// Not need yet
//// Set SurveyResult.IsCompleted = true
//surveysResult.IsCompleted = true;
//surveysAnswerRepository.Context.Entry(surveysResult).State = EntityState.Modified;
//surveysAnswerRepository.Context.SaveChanges();
}
}
示例9: DeleteSurveysResult
public void DeleteSurveysResult(long surveysResultId)
{
using (var surveysRepository = new BaseRepository<SurveysResult>())
{
SurveysResult surveysResult = surveysRepository.GetAllItems.FirstOrDefault(x => x.Id == surveysResultId);
if (surveysResult == null)
{
throw new SurveysResultDoesNotExistException();
}
switch (surveysResult.MethodsType)
{
case Constraints.KMethodsTypeTest:
// Remove rows from SurveysAnswers
List<SurveysAnswer> surveysAnswers = surveysResult.SurveysAnswers.ToList();
if (surveysAnswers.Count != 0)
{
foreach (var surveysAnswer in surveysAnswers)
{
surveysRepository.Context.SurveysAnswers.Remove(surveysAnswer);
}
surveysRepository.Context.SaveChanges();
}
// Remove row from SurveysShellResults
SurveysShellResult surveysShellResult =
surveysRepository.Context.SurveysShellResults.FirstOrDefault(
x => x.SurveyResultId == surveysResult.Id);
if (surveysShellResult != null)
{
surveysRepository.Context.SurveysShellResults.Remove(surveysShellResult);
surveysRepository.Context.SaveChanges();
}
break;
case Constraints.KMethodsTypePackage:
// Get childs test surveys
List<SurveysResult> childTestSurveys =
surveysRepository.GetAllItems.Where(x => x.Parent.Id == surveysResult.Id).ToList();
if (childTestSurveys.Count != 0)
{
foreach (var childTestSurvey in childTestSurveys)
{
// Recursive call, input argument is test survey
DeleteSurveysResult(childTestSurvey.Id);
}
}
break;
case Constraints.KMethodsTypeCuratorGroup:
// Get rows from SurveysPersonsGroups
List<SurveysPersonsGroup> surveysPersons = surveysResult.SurveysPersonsGroups.ToList();
foreach (var surveysPerson in surveysPersons)
{
// Remove row from Authorizations
Authorization authorization =
surveysRepository.Context.Authorizations.FirstOrDefault(
x => x.SurveysPersonId == surveysPerson.Id);
if (authorization != null)
{
surveysRepository.Context.Authorizations.Remove(authorization);
}
// Remove surveyPerson row from SurveysPersonsGroups
surveysRepository.Context.SurveysPersonsGroups.Remove(surveysPerson);
}
surveysRepository.Context.SaveChanges();
// Remove rows from SurveysMethodicsGroupItems
List<SurveysMethodicsGroupItem> methodicsGroupItems =
surveysRepository.Context.SurveysMethodicsGroupItems.Where(
x => x.SurveysResultId == surveysResultId).ToList();
foreach (var surveysMethodicsGroupItem in methodicsGroupItems)
{
surveysRepository.Context.SurveysMethodicsGroupItems.Remove(surveysMethodicsGroupItem);
}
surveysRepository.Context.SaveChanges();
// Remove child surveys
List<SurveysResult> childCuratorSurveys =
surveysRepository.GetAllItems.Where(x => x.Parent.Id == surveysResult.Id).ToList();
if (childCuratorSurveys.Count != 0)
{
foreach (var childCuratorSurvey in childCuratorSurveys)
{
// Recursive call, input argument is child survey
DeleteSurveysResult(childCuratorSurvey.Id);
}
}
break;
default:
break;
}
// General remove for all methods type
//.........这里部分代码省略.........
示例10: DeleteCustomer
private void DeleteCustomer(IList<Customer> customers)
{
using (var uow = new BaseUnitOfWork<FixMyCarEntities>())
{
using (var repo = new BaseRepository<Customer>(uow))
{
repo.Delete(customers);
}
uow.Save();
}
}
示例11: DeletePersonsGroup
public void DeletePersonsGroup(long curatorId, long groupId)
{
using (var personsGroupRepository = new BaseRepository<PersonsGroup>())
{
Client curator = personsGroupRepository.Context.Clients.FirstOrDefault(x => x.Id == curatorId);
if (curator == null)
{
throw new UserDoesNotExistException();
}
PersonsGroup foundedGroup = personsGroupRepository.GetAllItems.FirstOrDefault(x => x.Id == groupId && x.Curator.Id == curatorId);
if (foundedGroup == null)
{
throw new PersonsGroupDoesNotExistException();
}
// Before group deleting we need to remove all persons from group
List<Person> persons =
personsGroupRepository.Context.Persons.Where(x => x.PersonsGroup.Id == foundedGroup.Id).ToList();
foreach (var person in persons)
{
person.PersonsGroup = null;
}
personsGroupRepository.Context.SaveChanges();
foundedGroup.Persons = null;
if (!personsGroupRepository.Delete(foundedGroup).Status)
{
throw new DeleteException();
}
}
}
示例12: DeleteGroupMethod
public void DeleteGroupMethod(long curatorId, long methodicsGroupId, long groupMethodId)
{
using (var groupMethodRepository = new BaseRepository<GroupMethod>())
{
if (!groupMethodRepository.Context.Clients.Any(x => x.Id == curatorId))
{
throw new UserDoesNotExistException();
}
CuratorMethodicsGroup CMG =
groupMethodRepository.Context.CuratorMethodicsGroups.FirstOrDefault(
x => x.Id == methodicsGroupId && x.Curator.Id == curatorId);
if (CMG == null)
{
throw new MethodicsGroupDoesNotExistException();
}
GroupMethod foundedMethod =
groupMethodRepository.GetAllItems.FirstOrDefault(x => x.Id == groupMethodId);
if (foundedMethod == null)
{
throw new GroupMethodDoesNotExistException();
}
if (!groupMethodRepository.Delete(foundedMethod).Status)
{
throw new DeleteException();
}
}
}
示例13: DeleteCuratorPerson
public void DeleteCuratorPerson(long curatorId, long personId)
{
using (var personRepository = new BaseRepository<Person>())
{
Client curator = personRepository.Context.Clients.FirstOrDefault(x => x.Id == curatorId);
if (curator == null)
{
throw new UserDoesNotExistException();
}
Person foundedPerson = personRepository.GetAllItems.FirstOrDefault(x => x.Id == personId && x.Curator.Id == curatorId);
if (foundedPerson == null)
{
throw new PersonDoesNotExistException();
}
if (!personRepository.Delete(foundedPerson).Status)
{
throw new DeleteException();
}
}
}
示例14: DeleteCuratorMethodicsGroup
public void DeleteCuratorMethodicsGroup(long curatorId, long methodicsGroupId)
{
using (var methodicsGroupsRepository = new BaseRepository<CuratorMethodicsGroup>())
{
Client curator = methodicsGroupsRepository.Context.Clients.FirstOrDefault(x => x.Id == curatorId);
if (curator == null)
{
throw new UserDoesNotExistException();
}
CuratorMethodicsGroup foundedMethodicsGroup =
methodicsGroupsRepository.GetAllItems.FirstOrDefault(
x => x.Id == methodicsGroupId && x.Curator.Id == curatorId);
if (foundedMethodicsGroup == null)
{
throw new MethodicsGroupDoesNotExistException();
}
List<GroupMethod> groupMethods =
methodicsGroupsRepository.Context.GroupMethods.Where(x => x.CMG.Id == foundedMethodicsGroup.Id).
ToList();
foreach (var groupMethod in groupMethods)
{
methodicsGroupsRepository.Context.GroupMethods.Remove(groupMethod);
}
methodicsGroupsRepository.Context.SaveChanges();
foundedMethodicsGroup.GroupMethods = null;
if (!methodicsGroupsRepository.Delete(foundedMethodicsGroup).Status)
{
throw new DeleteException();
}
}
}