本文整理汇总了C#中EventContext.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# EventContext.SaveChanges方法的具体用法?C# EventContext.SaveChanges怎么用?C# EventContext.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventContext
的用法示例。
在下文中一共展示了EventContext.SaveChanges方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
public void Update()
{
WasLazyLoaded = false;
// need to make sure the event is saved
if (this.EventID == Guid.Empty)
{
throw new iONCalendarEventException(this, "Event ID Empty, cannot update");
}
using (var context = new EventContext(_credentials))
{
var e = context.Events.Find(this.EventID);
// someone else could have removed the event
if (e == null)
{
throw new iONCalendarEventException(this, "Event not found, cannot update");
}
e.Contents = this.Contents;
e.EndTime = this.EndTime;
e.ID = this.EventID;
e.IsAllDay = this.IsAllDay;
e.IsReoccuring = this.IsReoccuring;
e.Location = this.Location;
e.StartTime = this.StartTime;
e.Title = this.Title;
// update the reminders, need to see if they changed
foreach (var item in Reminders)
{
if (item.MarkedForRemoval)
{
context.EventReminders.Remove(item);
}
}
// update the invitees, need to see if they changed
foreach (var item in Invitees)
{
if (item.MarkedForRemoval)
{
context.EventInvitees.Remove(item);
}
}
// do an atomic save here
context.SaveChanges();
// need to save the date created and date edited
// need to do this here because we need the event id
EventHistory history = new EventHistory();
history.UserID = _credentials.UserID;
history.TransactionDate = DateTime.Now;
history.EventID = e.ID;
history.TransactionType = EventHistoryType.Edit;
context.EventHistory.Add(history);
// save the history
context.SaveChanges();
}
}
示例2: Insert
public void Insert(Guid calendarID)
{
using (var context = new EventContext(_credentials))
{
this.CalendarID = calendarID;
var e = new Event();
e.Contents = this.Contents;
e.EndTime = this.EndTime;
e.ID = this.EventID;
e.IsAllDay = this.IsAllDay;
e.IsReoccuring = this.IsReoccuring;
e.Location = this.Location;
e.StartTime = this.StartTime;
e.Title = this.Title;
e.Type = this.Type;
e.CalendarID = this.CalendarID;
e.AuthorID = _credentials.UserID;
// Add and save here so we have the event id
context.Events.Add(e);
context.SaveChanges();
// Grab the event ID after saved
this.EventID = e.ID;
// Add the reminders
foreach (var item in Reminders)
{
context.EventReminders.Add(item);
}
if (this.Type == EventType.None)
{
this.Type = EventType.Private;
}
// Do the calendar sharing
if (this.Type == EventType.Public || this.Type == EventType.EmployeesOnly)
{
// Add the individuals who are already invited to the calendar
// only if the event is made public
var employeeInvitees = (from c in context.CalendarInvitees
join u in context.Users on c.InviteeID equals u.ID
where c.Type == InviteeType.Employee
select new EventInvitee
{
EventID = this.EventID,
InviteeID = u.ID,
Type = InviteeType.Employee
}).ToList();
Invitees.AddRange(employeeInvitees);
// add the customers
if (this.Type == EventType.Public)
{
var customerInvitees = (from c in context.CalendarInvitees
join customers in context.Customers on c.InviteeID equals customers.ID
where c.Type == InviteeType.Employee
select new EventInvitee
{
EventID = this.EventID,
InviteeID = customers.ID,
Type = InviteeType.Customer
}).ToList();
Invitees.AddRange(customerInvitees);
}
}
// Add the invitees
foreach (var item in Invitees)
{
context.EventInvitees.Add(item);
}
// set the transaction dates
this.DateCreated = DateTime.Now;
this.DateEdied = this.DateCreated;
// need to save the date created and date edited
// need to do this here because we need the event id
EventHistory history = new EventHistory();
history.UserID = _credentials.UserID;
history.TransactionDate = this.DateCreated;
history.EventID = this.EventID;
history.TransactionType = EventHistoryType.Create;
context.EventHistory.Add(history);
// save the history
context.SaveChanges();
// set the creator
this.Creator = context.Users.Where(w => w.ID == e.AuthorID).First();
}
}