public static bool SetAvailabilityForEvent(Guid calendarId, Guid eventId, Guid memberId, string note, AvailibilityEnum avail) { try { var dc = new ManagementContext(); var self = (from xx in dc.CalendarEvents where xx.Calendar.CalendarId == calendarId where xx.CalendarItemId == eventId select xx).FirstOrDefault(); if (self == null) return false; if (self.Attendees.Where(x => x.Attendant.MemberId == memberId).FirstOrDefault() == null) { DataModels.Calendar.CalendarAttendance att = new DataModels.Calendar.CalendarAttendance(); att.Attendant = dc.Members.Where(x => x.MemberId == memberId).FirstOrDefault(); att.CalendarItem = self; att.AvailabilityNote = note; att.AvailibityEnum = (byte)avail; dc.CalendarAttendance.Add(att); int c = dc.SaveChanges(); return c > 0; } else { var mem = self.Attendees.Where(x => x.Attendant.MemberId == memberId).FirstOrDefault(); mem.AvailabilityNote = note; mem.AvailibityEnum = (byte)avail; int c = dc.SaveChanges(); return c > 0; } } catch (Exception exception) { Error.ErrorDatabaseManager.AddException(exception, exception.GetType()); } return false; }
/// <summary> /// checks the person into event. Allows the person to check them selves into the event. /// </summary> /// <param name="calendarId"></param> /// <param name="eventId"></param> /// <param name="memberId"></param> /// <param name="note"></param> /// <param name="pointType"></param> /// <returns></returns> public static bool CheckSelfIn(Guid calendarId, Guid eventId, Guid memberId, string note, CalendarEventPointTypeEnum pointType, bool isTardy, int additionalPoints) { try { var dc = new ManagementContext(); var self = (from xx in dc.CalendarEvents where xx.Calendar.CalendarId == calendarId where xx.CalendarItemId == eventId select xx).FirstOrDefault(); if (self == null) return false; if (self.Attendees.Where(x => x.Attendant.MemberId == memberId).FirstOrDefault() == null) { DataModels.Calendar.CalendarAttendance att = new DataModels.Calendar.CalendarAttendance(); att.Attendant = dc.Members.Where(x => x.MemberId == memberId).FirstOrDefault(); att.CalendarItem = self; att.Note = note; att.PointTypeEnum = Convert.ToInt32(pointType); att.AdditionalPoints = additionalPoints; if (isTardy) att.SecondaryPointTypeEnum = Convert.ToInt32(CalendarEventPointTypeEnum.Tardy); dc.CalendarAttendance.Add(att); dc.SaveChanges(); } else { var mem = self.Attendees.Where(x => x.Attendant.MemberId == memberId).FirstOrDefault(); mem.PointTypeEnum = Convert.ToInt32(pointType); mem.Note = note; mem.AdditionalPoints = additionalPoints; if (isTardy) mem.SecondaryPointTypeEnum = Convert.ToInt32(CalendarEventPointTypeEnum.Tardy); dc.SaveChanges(); } return true; } catch (Exception exception) { Error.ErrorDatabaseManager.AddException(exception, exception.GetType()); } return false; }