Beispiel #1
0
        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;
        }
Beispiel #2
0
        public void SendSmsNotification(int eventId)
        {
            var evt = _db.Events.Include(e => e.Invitees).Single(e => e.EventId == eventId);
            var user = _db.Users.Find(CurrUserId);
            var comment = new EventComment
            {
                Text = "SMS notification send by " + user.FullName,
                SenderId = user.UserId,
                SenderName = user.FullName,
                EventId = eventId
            };
            _db.EventComments.Add(comment);
            _db.SaveChanges();

            var users = _db.Users.ToList();
            var ivtIds = evt.Invitees.Select(i => i.UserId).ToList();
            var code = evt.GetVisibilityCode();
            var invitees = users.Where(u => ivtIds.Contains(u.UserId) || ((u.GetVisibilityCode() & code)) > 0).ToList();
            using (var srv = new SmsSrv(invitees, evt.SmsMessage))
            {
                srv.SendSMSAsync();
            }
        }
Beispiel #3
0
        public void SendEmailNotification(int eventId)
        {
            var evt = _db.Events.Include(e => e.Invitees).Single(e => e.EventId == eventId);
            var user = _db.Users.Find(CurrUserId);
            var comment = new EventComment
            {
                Text = "Email notification send by " + user.FullName,
                SenderId = user.UserId,
                SenderName = user.FullName,
                EventId = eventId
            };
            _db.EventComments.Add(comment);
            _db.SaveChanges();

            var users = _db.Users.ToList();
            var ivtIds = evt.Invitees.Select(i => i.UserId).ToList();
            var code = evt.GetVisibilityCode();
            var invitees = users.Where(u => ivtIds.Contains(u.UserId) || ((u.GetVisibilityCode() & code)) > 0).ToList();
            MailSrv.SendMailToManyAsync(invitees, evt.EmailMessage, "NITCAA Event | " + evt.EventName);
        }