本文整理汇总了C#中oikonomosEntities.DeleteObject方法的典型用法代码示例。如果您正苦于以下问题:C# oikonomosEntities.DeleteObject方法的具体用法?C# oikonomosEntities.DeleteObject怎么用?C# oikonomosEntities.DeleteObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oikonomosEntities
的用法示例。
在下文中一共展示了oikonomosEntities.DeleteObject方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemovePermissionsFromRole
public static void RemovePermissionsFromRole(Person currentPerson, int roleId, List<int> permissionIds)
{
if (!currentPerson.HasPermission(Permissions.EditPermissions))
return;
using (oikonomosEntities context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
{
var permissionRoles = (from p in context.PermissionRoles
where p.RoleId == roleId
&& permissionIds.Contains(p.PermissionId)
select p).ToList();
if (permissionRoles != null)
{
foreach (var permissionRole in permissionRoles)
{
context.DeleteObject(permissionRole);
}
}
context.SaveChanges();
}
}
示例2: RemovePersonFromChurchSpecificTables
private static bool RemovePersonFromChurchSpecificTables(int personId, Person currentPerson, oikonomosEntities context)
{
const int tableId = (int)Tables.Person;
//If this person has created or changed any events - change to the person deleting them
foreach (var createdEvent in context.OldEvents.Where(e => e.CreatedByPersonId == personId))
createdEvent.CreatedByPersonId = currentPerson.PersonId;
foreach (var changedEvent in context.OldEvents.Where(e => e.ChangedByPersonId == personId))
changedEvent.ChangedByPersonId = currentPerson.PersonId;
var events = (from e in context.OldEvents
where e.Reference == personId
&& e.TableId == tableId
&& e.ChurchId == currentPerson.ChurchId
select e);
foreach (var eventToDelete in events)
{
context.DeleteObject(eventToDelete);
}
//Remove them from groups
var groups = (from g in context.Groups
from pg in g.PersonGroups
where pg.PersonId == personId
&& g.ChurchId == currentPerson.ChurchId
select pg);
foreach (PersonGroup personGroup in groups)
{
context.DeleteObject(personGroup);
}
//Remove them from roles
var personRoles = (from r in context.Roles
from pr in r.PersonChurches
where pr.PersonId == personId
&& r.ChurchId == currentPerson.ChurchId
select pr);
foreach (var personRole in personRoles)
{
context.DeleteObject(personRole);
}
//Remove them from any leadership or admin roles in Home Groups
var groupsThePersonLeadsOrAdministrates = (from g in context.Groups
where (g.AdministratorId == personId ||
g.LeaderId == personId)
&& g.ChurchId == currentPerson.ChurchId
select g);
foreach (var group in groupsThePersonLeadsOrAdministrates)
{
if (group.LeaderId == personId)
group.LeaderId = null;
if (group.AdministratorId == personId)
group.AdministratorId = null;
}
var person = context.People.FirstOrDefault(p => p.PersonId == personId);
return person.PersonChurches.Count == 0;
}
示例3: SaveRole
private static void SaveRole(PersonViewModel person, Person currentPerson, oikonomosEntities context, Person personToSave)
{
if (person.RoleId == 0)
return;
var personRole = context.PersonChurches.FirstOrDefault(pr => (pr.Role.ChurchId == currentPerson.ChurchId) && (pr.PersonId == personToSave.PersonId));
if (personRole == null)
{
SavePersonRole(context, personToSave, person.RoleId);
return;
}
if (personRole.RoleId == person.RoleId)
return;
context.DeleteObject(personRole);
SavePersonRole(context, personToSave, person.RoleId);
}
示例4: AddPersonToGroup
private static bool AddPersonToGroup(PersonViewModel person, Person currentPerson, oikonomosEntities context, Person personToSave)
{
if (person.IsInMultipleGroups)
return false;
if (personToSave.PersonGroups.Count == 1 && personToSave.PersonGroups.First().GroupId != person.GroupId)
{
if (person.GroupId == 0)
{
context.DeleteObject(personToSave.PersonGroups.First());
return false;
}
else
{
personToSave.PersonGroups.First().GroupId = person.GroupId;
return true;
}
}
if (personToSave.PersonGroups.Count == 0 && person.GroupId > 0)
{
SavePersonGroup(personToSave, person.GroupId);
return true;
}
return false;
}
示例5: DeletePerson
private static void DeletePerson(int personId, oikonomosEntities context)
{
//Check to see if this address is being used
var address = (from p in context.People
join f in context.Families
on p.FamilyId equals f.FamilyId
join a in context.Addresses
on f.AddressId equals a.AddressId
where p.PersonId != personId
select p).ToList();
if (address.Count == 0)
{
var addressToDelete = (from a in context.Addresses
join f in context.Families
on a.AddressId equals f.AddressId
join p in context.People
on f.FamilyId equals p.FamilyId
where p.PersonId == personId
select a).FirstOrDefault();
context.DeleteObject(addressToDelete);
}
//Delete comments related to this person
var comments = (from c in context.Comments
where c.AboutPersonId == personId
select c);
foreach (var comment in comments)
{
context.DeleteObject(comment);
}
//Remove all the relationships
var relationships = (from pr in context.PersonRelationships
where pr.PersonId == personId
select pr);
foreach (PersonRelationship relationship in relationships)
{
context.DeleteObject(relationship);
}
var relatedTo = (from pr in context.PersonRelationships
where pr.PersonRelatedToId == personId
select pr);
foreach (PersonRelationship rel in relatedTo)
{
context.DeleteObject(rel);
}
var optionalFields = (from pc in context.PersonOptionalFields
where pc.PersonId == personId
select pc);
foreach (PersonOptionalField optionalField in optionalFields)
{
context.DeleteObject(optionalField);
}
var person = (from p in context.People
where p.PersonId == personId
select p).FirstOrDefault();
//Check to see if they were the last one in their family
var familyMembers = (from p in context.People
where p.PersonId != personId
&& p.FamilyId == person.FamilyId
select p).ToList();
context.DeleteObject(person);
if (familyMembers.Count == 0)
{
var familyToDelete = (from f in context.Families
join p in context.People
on f.FamilyId equals p.FamilyId
where p.PersonId == personId
select f).FirstOrDefault();
context.DeleteObject(familyToDelete);
}
}
示例6: DeleteRelationships
private static void DeleteRelationships(int personId, oikonomosEntities context)
{
//Remove all the relationships
var relationships = (from pr in context.PersonRelationships
where pr.PersonId == personId
select pr);
foreach (PersonRelationship relationship in relationships)
{
context.DeleteObject(relationship);
}
var relatedTo = (from pr in context.PersonRelationships
where pr.PersonRelatedToId == personId
select pr);
foreach (PersonRelationship rel in relatedTo)
{
context.DeleteObject(rel);
}
}
示例7: CheckToSeeIfEventAlreadyExists
public static void CheckToSeeIfEventAlreadyExists(PersonEventViewModel personEvents, oikonomosEntities context, EventViewModel personEvent, OldEvent pe)
{
string groupId = personEvent.GroupId.ToString();
//Check to see if this event already exists
OldEvent duplicateEvent = null;
var check = (from e in context.OldEvents
where e.TableId == (int)Tables.Person
&& e.Reference == personEvents.PersonId
&& e.EventDate == personEvent.Date
&& e.Description.StartsWith(personEvent.Name) //Caters for the attended homegroup (blah)
select e);
if (personEvent.GroupId != 0)
{
duplicateEvent = (from e in check
where e.Value == groupId
select e).FirstOrDefault();
}
else
{
duplicateEvent = (from e in check select e).FirstOrDefault();
}
if (duplicateEvent == null)
{
context.OldEvents.AddObject(pe);
}
if (personEvent.Name == EventNames.AttendedGroup)
{
//Remove a "did not attend event on the same date"
var atCheck = (from e in context.OldEvents
where e.TableId == (int)Tables.Person
&& e.Reference == personEvents.PersonId
&& e.EventDate == personEvent.Date
&& e.Description.StartsWith(EventNames.DidNotAttendGroup)
select e);
if (personEvent.GroupId != 0)
{
duplicateEvent = (from e in atCheck
where e.Value == groupId
select e).FirstOrDefault();
}
else
{
duplicateEvent = (from e in check select e).FirstOrDefault();
}
if (duplicateEvent != null)
{
context.DeleteObject(duplicateEvent);
}
}
if (personEvent.Name == EventNames.DidNotAttendGroup)
{
//Remove an "attended" event on the same date
var atCheck = (from e in context.OldEvents
where e.TableId == (int)Tables.Person
&& e.Reference == personEvents.PersonId
&& e.EventDate == personEvent.Date
&& e.Description.StartsWith(EventNames.AttendedGroup)
select e);
if (personEvent.GroupId != 0)
{
duplicateEvent = (from e in atCheck
where e.Value == groupId
select e).FirstOrDefault();
}
else
{
duplicateEvent = (from e in check select e).FirstOrDefault();
}
if (duplicateEvent != null)
{
context.DeleteObject(duplicateEvent);
}
}
}
示例8: DeletePerson
private static void DeletePerson(int personId, oikonomosEntities context, Person currentPerson)
{
UpdateCommentsMadeByThisPerson(personId, context, currentPerson);
DeleteAddressIfNotBeingUsed(personId, context);
DeleteCommentsAboutPerson(personId, context);
DeleteRelationships(personId, context);
DeleteOptionalFields(personId, context);
DeleteMessages(personId, context, currentPerson.PersonId);
var person = (from p in context.People
where p.PersonId == personId
select p).FirstOrDefault();
var familyMembers = (from p in context.People
where p.PersonId != personId
&& p.FamilyId == person.FamilyId
select p).ToList();
context.DeleteObject(person);
if (familyMembers.Count != 0) return;
var familyToDelete = (from f in context.Families
join p in context.People
on f.FamilyId equals p.FamilyId
where p.PersonId == personId
select f).FirstOrDefault();
context.DeleteObject(familyToDelete);
}
示例9: DeleteOptionalFields
private static void DeleteOptionalFields(int personId, oikonomosEntities context)
{
var optionalFields = (from pc in context.PersonOptionalFields
where pc.PersonId == personId
select pc);
foreach (PersonOptionalField optionalField in optionalFields)
{
context.DeleteObject(optionalField);
}
}
示例10: DeleteMessages
private static void DeleteMessages(int personId, oikonomosEntities context, int currentPersonId)
{
var messageRecepients = context.MessageRecepients.Where(m => m.MessageTo == personId);
foreach (var messageRecepient in messageRecepients)
{
var message = context.Messages.FirstOrDefault(m=>m.MessageId == messageRecepient.MessageId);
context.DeleteObject(messageRecepient);
if (message == null) continue;
var remainingMessageRecepients = message.MessageRecepients.Count();
if (remainingMessageRecepients == 0)
context.DeleteObject(message);
}
context.SaveChanges();
//Change the messages that have been sent from the person being deleted to the person deleting them
var messagesSent = context.Messages.Where(m => m.MessageFrom == personId);
foreach (var m in messagesSent)
{
m.MessageFrom = currentPersonId;
}
context.SaveChanges();
}
示例11: DeleteCommentsAboutPerson
private static void DeleteCommentsAboutPerson(int personId, oikonomosEntities context)
{
var comments = context.Comments.Where(c => c.AboutPersonId == personId);
foreach (var comment in comments)
{
context.DeleteObject(comment);
}
}
示例12: DeleteAddressIfNotBeingUsed
private static void DeleteAddressIfNotBeingUsed(int personId, oikonomosEntities context)
{
//Check to see if this address is being used
var address = (from p in context.People
join f in context.Families
on p.FamilyId equals f.FamilyId
join a in context.Addresses
on f.AddressId equals a.AddressId
where p.PersonId != personId
select p).ToList();
if (address.Count == 0)
{
var addressToDelete = (from a in context.Addresses
join f in context.Families
on a.AddressId equals f.AddressId
join p in context.People
on f.FamilyId equals p.FamilyId
where p.PersonId == personId
select a).FirstOrDefault();
context.DeleteObject(addressToDelete);
}
}