public Event CreateOrUpdateEvent(Event info) { info.RemoveOffset(); List<int> newUserIds = info.AcSeleUserIds; var currUser = _db.Users.Find(UserSession.CurrentUserId); newUserIds.Add(currUser.UserId); newUserIds = newUserIds.Distinct().ToList(); info.UserGroups = info.GetVisibilityCode(); info.CreatedUserId = currUser.UserId; info.CreatedUserName = currUser.FullName; if (info.EventId == 0) { info.Invitees = CreateInvitees(newUserIds); _db.Events.Add(info); var comment = new EventComment { SenderId = currUser.UserId, SenderName = currUser.FullName, Text = "Event created by " + currUser.FullName }; info.Comments = new List<EventComment> { comment }; } else { UpdateInvitees(info, newUserIds); var comment = new EventComment { SenderId = currUser.UserId, SenderName = currUser.FullName, Text = info.IsDeleted ? "Event was cancelled by " + currUser.FullName : "Event updated by " + currUser.FullName, EventId = info.EventId }; _db.EventComments.Add(comment); _db.Entry(info).State = System.Data.EntityState.Modified; } _db.SaveChanges(); return info; }