Exemplo n.º 1
0
        public ActionResult CancelMeeting(int meetingId, string title, DateTime startDate)
        {
            var    ctx              = new OruBloggenDbContext();
            var    appCtx           = new ApplicationDbContext();
            var    userMeetings     = ctx.UserMeetings.Where(m => m.MeetingID == meetingId);
            var    applicationUsers = appCtx.Users.ToList();
            var    emails           = new List <string>();
            var    phoneNumbers     = new List <string>();
            var    notification     = new NotificationController();
            string ebody            = "";

            var userList = ctx.Users.ToList() as IEnumerable <UserModel>;

            //var meetingActive = ctx.Meetings.FirstOrDefault(m => m.MeetingID == meetingId).MeetingActive;

            if (ctx.Meetings.FirstOrDefault(m => m.MeetingID == meetingId).MeetingActive)
            {
                ctx.Meetings.FirstOrDefault(m => m.MeetingID == meetingId).MeetingActive = false;

                foreach (var user in userMeetings)
                {
                    userList = userList.Where(u => u.UserID == user.UserID);

                    var body = "Följande möte har blivit inställt: " + user.MeetingModel.MeetingTitle + Environment.NewLine +
                               "Startdatum: " + user.MeetingModel.MeetingStartDate.ToShortDateString() + " "
                               + user.MeetingModel.MeetingStartDate.ToShortTimeString() + Environment.NewLine +

                               "Slutdatum: " + user.MeetingModel.MeetingEndDate.ToShortDateString() + " "
                               + user.MeetingModel.MeetingEndDate.ToShortTimeString() + Environment.NewLine +

                               "Beskrivning: " + user.MeetingModel.MeetingDesc;
                    ebody = body;

                    foreach (var userModel in userList)
                    {
                        if (userModel.UserEmailNotification == true)
                        {
                            emails.Add(applicationUsers.FirstOrDefault(e => e.Id == userModel.UserID).Email);
                        }

                        if (userModel.UserSmsNotification == true)
                        {
                            phoneNumbers.Add(userModel.UserPhoneNumber.ToString());
                            notification.SendSms(userModel.UserPhoneNumber.ToString(), body);
                        }

                        if (userModel.UserPmNotification == true)
                        {
                            notification.SendReminderPM(user.UserID, user.MeetingModel.MeetingTitle, user.MeetingModel.MeetingDesc, body, user.MeetingModel.MeetingStartDate, user.MeetingModel.MeetingEndDate);
                        }
                    }
                }
                ctx.SaveChanges();

                var notificationController = new NotificationController();
                notificationController.SendEmail(emails, "Mötet är inställt", title + " " + startDate.ToShortDateString() + " är inställt.");
            }
            return(RedirectToAction("ShowInfo"));
        }
Exemplo n.º 2
0
        /// <summary>
        /// //////////////////////////////////////////////////////////////////////////////
        /// </summary>
        /// <param name="meetingId"></param>
        /// <param name="title"></param>
        /// <param name="startDate"></param>
        /// <returns></returns>
        public ActionResult CancelMeeting(int meetingId, string title, DateTime startDate)
        {
            var ctx          = new OruBloggenDbContext();
            var appCtx       = new ApplicationDbContext();
            var notification = new NotificationController();
            var emails       = new List <string>();
            var phoneNumbers = new List <string>();

            //var meetingActive = ctx.Meetings.FirstOrDefault(m => m.MeetingID == meetingId).MeetingActive;

            if (ctx.Meetings.FirstOrDefault(m => m.MeetingID == meetingId).MeetingActive)
            {
                ctx.Meetings.FirstOrDefault(m => m.MeetingID == meetingId).MeetingActive = false;

                var    userMeetings = ctx.UserMeetings.Where(m => m.MeetingID == meetingId);
                string ebody        = "";
                foreach (var user in userMeetings)

                {
                    var body = "Du har blivit inbjuden till " + user.MeetingModel.MeetingTitle + Environment.NewLine +
                               "Startdatum: " + user.MeetingModel.MeetingStartDate.ToShortDateString() + " "
                               + user.MeetingModel.MeetingStartDate.ToShortTimeString() + Environment.NewLine +

                               "Slutdatum: " + user.MeetingModel.MeetingEndDate.ToShortDateString() + " "
                               + user.MeetingModel.MeetingEndDate.ToShortTimeString() + Environment.NewLine +

                               "Beskrivning: " + user.MeetingModel.MeetingDesc;
                    ebody = body;

                    if (user.UserModel.UserEmailNotification == true)
                    {
                        emails.Add(appCtx.Users.FirstOrDefault(u => u.Id.Equals(user.UserID)).Email);
                    }

                    if (user.UserModel.UserSmsNotification == true)
                    {
                        phoneNumbers.Add(ctx.Users.FirstOrDefault(u => u.UserID.Equals(user.UserID)).UserPhoneNumber.ToString());
                        notification.SendSms(ctx.Users.FirstOrDefault(u => u.UserID.Equals(user.UserID)).UserPhoneNumber.ToString(), body);
                    }

                    if (user.UserModel.UserPmNotification == true)
                    {
                        notification.SendReminderPM(user.UserID, user.MeetingModel.MeetingTitle, user.MeetingModel.MeetingDesc, body, user.MeetingModel.MeetingStartDate, user.MeetingModel.MeetingEndDate);
                    }
                }
                ctx.SaveChanges();

                var notificationController = new NotificationController();
                notificationController.SendEmail(emails, "Mötet är inställt", ebody);
            }
            return(RedirectToAction("ListCreatedMeetings"));
        }
Exemplo n.º 3
0
        public ActionResult AddPost(HomePostViewModel post, HttpPostedFileBase[] file)
        {
            var ctx    = new OruBloggenDbContext();
            var userID = User.Identity.GetUserId();

            if (!string.IsNullOrEmpty(post.AddPostViewModel.PostTitle) && !string.IsNullOrEmpty(post.AddPostViewModel.PostText))
            {
                ctx.Posts.Add(new PostModel
                {
                    PostTitle      = post.AddPostViewModel.PostTitle,
                    PostText       = post.AddPostViewModel.PostText,
                    PostDate       = DateTime.Now,
                    PostFormal     = post.AddPostViewModel.PostFormal,
                    PostUserID     = userID,
                    PostCategoryID = int.Parse(post.AddPostViewModel.PostCategory)
                });

                ctx.SaveChanges();

                if (file != null)
                {
                    foreach (var oneFile in file)
                    {
                        SaveFile(oneFile);
                    }
                }
            }
            NotificationController notificationController = new NotificationController();

            notificationController.SendPostPm(userID, post.AddPostViewModel.PostTitle, post.AddPostViewModel.PostText, DateTime.Now, post.AddPostViewModel.PostFormal, int.Parse(post.AddPostViewModel.PostCategory));

            if (post.AddPostViewModel.PostFormal)
            {
                return(RedirectToAction("FormalPost"));
            }

            else
            {
                return(RedirectToAction("InformalPost"));
            }
        }
Exemplo n.º 4
0
        public ActionResult CreateMeeting(MeetingViewModel model)
        {
            var ctx    = new OruBloggenDbContext();
            var userId = User.Identity.GetUserId();

            var notification = new NotificationController();
            var body         = "Du har blivit inbjuden till " + model.Meeting.MeetingTitle + Environment.NewLine +
                               "Startdatum: " + model.Meeting.MeetingStartDate.ToShortDateString() + " "
                               + model.Meeting.MeetingStartDate.ToShortTimeString() + Environment.NewLine +

                               "Slutdatum: " + model.Meeting.MeetingEndDate.ToShortDateString() + " "
                               + model.Meeting.MeetingEndDate.ToShortTimeString() + Environment.NewLine +

                               "Beskrivning: " + model.Meeting.MeetingDesc;

            var meeting = ctx.Meetings.Add(new MeetingModel
            {
                MeetingTitle     = model.Meeting.MeetingTitle,
                MeetingDesc      = model.Meeting.MeetingDesc,
                MeetingStartDate = model.Meeting.MeetingStartDate,
                MeetingEndDate   = model.Meeting.MeetingEndDate,
                MeetingUserID    = User.Identity.GetUserId()
            });

            ctx.SaveChanges();

            var appCtx       = new ApplicationDbContext();
            var emails       = new List <string>();
            var phoneNumbers = new List <string>();
            var pmReceivers  = new List <UserModel>();

            if (model.SelectedUserIds != null)
            {
                foreach (var item in model.SelectedUserIds)
                {
                    ctx.UserMeetings.Add(new UserMeetingModel
                    {
                        MeetingID = ctx.Meetings.OrderByDescending(m => m.MeetingID).First().MeetingID,
                        UserID    = item
                    });
                    var user = ctx.Users.FirstOrDefault(u => u.UserID.Equals(item));


                    if (user.UserEmailNotification == true)
                    {
                        emails.Add(appCtx.Users.FirstOrDefault(u => u.Id.Equals(user.UserID)).Email);
                    }

                    if (user.UserSmsNotification == true)
                    {
                        phoneNumbers.Add(ctx.Users.FirstOrDefault(u => u.UserID.Equals(user.UserID)).UserPhoneNumber.ToString());
                        notification.SendSms(ctx.Users.FirstOrDefault(u => u.UserID.Equals(user.UserID)).UserPhoneNumber.ToString(), body);
                    }

                    if (user.UserPmNotification == true)
                    {
                        notification.SendReminderPM(user.UserID, meeting.MeetingTitle, meeting.MeetingDesc, body, meeting.MeetingStartDate, meeting.MeetingEndDate);
                    }
                }
            }

            ctx.SaveChanges();


            notification.SendEmail(emails, "Inbjudan till möte", body);

            //foreach (var number in phoneNumbers)
            //{
            //    notificationController.SendSms(number, body);
            //}
            //notificationController.SendMeetingPm(userId, pmReceivers, model.Meeting.MeetingTitle, model.Meeting.MeetingDesc, model.Meeting.MeetingStartDate, model.Meeting.MeetingEndDate);

            //return RedirectToAction("MeetingDetails", new { id = meeting.MeetingID});
            return(RedirectToAction("Index", "MeetingCalendar"));
        }