public bool AnswerEvent(int userId, int eventId, bool answer) { EventToUserRelation relation = database.GetEventToUserRelation(eventId, userId); if (relation == null) { relation = new EventToUserRelation(); relation.Active = true; relation.EventId = eventId; relation.AttendeeId = userId; relation.Answer = answer; return database.CreateEventToUserRelation(ref relation); } if (relation.Answer != answer) { relation.Answer = answer; return database.Save(); } return true; }
public void Initialize() { MockDb mock = new MockDb(); #region Users User user1 = new User { UserID = 1, Active = true, UserName = "******", DisplayName = "xXx$w4gM4$t3r420xXx", BirthYear = 9000, Gender = Gender.MALE, Email = "[email protected]" }; User user2 = new User { UserID = 2, Active = true, UserName = "******", DisplayName = "Sultumenni500", BirthYear = 1337, Gender = Gender.MALE, Email = "*****@*****.**" }; User user3 = new User { UserID = 3, Active = true, UserName = "******", DisplayName = "Pulsmeister99", BirthYear = 9000, Gender = Gender.FEMALE, Email = "*****@*****.**" }; mock.UserList.Add(user1); mock.UserList.Add(user2); mock.UserList.Add(user3); #endregion #region Groups Group group1 = new Group { GroupID = 1, Active = true, OwnerId = 1, Name = "Team Gulli" }; Group group2 = new Group { GroupID = 2, Active = true, OwnerId = 3, Name = "Pulsuvagninn" }; mock.Groups.Add(group1); mock.Groups.Add(group2); #endregion #region Events Event event1 = new Event { EventID = 1, Active = true, GroupId = null, OwnerId = 1, Name = "Lan", Photo = "", Description = "Quake 4 lyfe", CreationTime = new DateTime(2015, 5, 6, 12, 30, 1), TimeOfEvent = new DateTime(2015, 5, 9, 12, 30, 0), Minutes = 60, Location = "the internet", Min = 0, Max = 5, }; Event event2 = new Event { EventID = 2, Active = true, GroupId = 2, OwnerId = 3, Name = "Pulsuparty", Photo = "", Description = "pulsulíf", CreationTime = new DateTime(2015, 5, 6, 12, 30, 1), TimeOfEvent = new DateTime(2015, 5, 9, 12, 30, 0), Minutes = 60, Location = "bæjarins bestu", Min = 0, Max = 5, }; mock.Events.Add(event1); mock.Events.Add(event2); #endregion #region Comments Comment comment1 = new Comment { CommentID = 1, Active = true, OwnerId = 2, Content = "FOKK PULSUR, SULTA IS SUPERIOR", CreationTime = new DateTime(2015, 5, 6, 12, 35, 1) }; mock.Comments.Add(comment1); #endregion #region GroupToUserRelations GroupToUserRelation groupUser1 = new GroupToUserRelation { GroupToUserRelationID = 1, Active = true, GroupId = 1, MemberId = 1 }; GroupToUserRelation groupUser2 = new GroupToUserRelation { GroupToUserRelationID = 2, Active = true, GroupId = 2, MemberId = 3 }; GroupToUserRelation groupUser3 = new GroupToUserRelation { GroupToUserRelationID = 3, Active = true, GroupId = 2, MemberId = 2 }; GroupToUserRelation groupUser4 = new GroupToUserRelation { GroupToUserRelationID = 4, Active = true, GroupId = 1, MemberId = 2 }; mock.GroupToUserRelations.Add(groupUser1); mock.GroupToUserRelations.Add(groupUser2); mock.GroupToUserRelations.Add(groupUser3); mock.GroupToUserRelations.Add(groupUser4); #endregion #region GroupsToEventRelations GroupToEventRelation groupEvent1 = new GroupToEventRelation { GroupToEventRelationID = 1, Active = true, EventId = 2, GroupId = 2 }; mock.GroupToEventRelations.Add(groupEvent1); #endregion #region UserToUserRelations UserToUserRelation friendship1 = new UserToUserRelation { UserToUserRelationID = 1, Active = true, SenderId = 2, ReceiverId = 3, Answer = true }; UserToUserRelation friendship2 = new UserToUserRelation { UserToUserRelationID = 2, Active = true, SenderId = 1, ReceiverId = 2, Answer = true }; mock.UserToUserRelations.Add(friendship1); mock.UserToUserRelations.Add(friendship2); #endregion #region EventToUserRelations EventToUserRelation eventUser1 = new EventToUserRelation { EventToUserRelationID = 1, Active = true, EventId = 1, AttendeeId = 1, Answer = true }; EventToUserRelation eventUser2 = new EventToUserRelation { EventToUserRelationID = 2, Active = true, EventId = 1, AttendeeId = 2, Answer = null }; EventToUserRelation eventUser3 = new EventToUserRelation { EventToUserRelationID = 3, Active = true, EventId = 2, AttendeeId = 3, Answer = true }; EventToUserRelation eventUser4 = new EventToUserRelation { EventToUserRelationID = 4, Active = true, EventId = 2, AttendeeId = 2, Answer = false }; mock.EventToUserRelations.Add(eventUser1); mock.EventToUserRelations.Add(eventUser2); mock.EventToUserRelations.Add(eventUser3); mock.EventToUserRelations.Add(eventUser4); #endregion #region EventToCommentRelations EventToCommentRelation eventComment1 = new EventToCommentRelation { EventToCommentRelationID = 1, EventId = 2, CommentId = 1, Active = true }; mock.EventToCommentRelations.Add(eventComment1); #endregion DbTest = new Database(mock); ServiceTest = new Service(DbTest); }
public bool CreateEvent(ref Event newEvent) { if (database.CreateEvent(ref newEvent)) { EventToUserRelation relation = new EventToUserRelation(); relation.EventId = newEvent.EventID; relation.AttendeeId = newEvent.OwnerId; relation.Active = true; relation.Answer = true; if (database.CreateEventToUserRelation(ref relation)) { if (newEvent.GroupId.HasValue) { GroupToEventRelation relation2 = new GroupToEventRelation(); relation2.EventId = newEvent.EventID; relation2.GroupId = newEvent.GroupId.Value; relation2.Active = true; if (database.CreateGroupToEventRelation(ref relation2)) { return true; } throw new Exception("The Event was created but an error occured when creation the GroupToUserRelation"); } return true; } throw new Exception("The Event was created but an error occured when creation the EventToUserRelation"); } return false; }
public bool CreateEventToUserRelation(ref EventToUserRelation relation) { context.EventToUserRelations.Add(relation); context.SaveChanges(); return true; }