コード例 #1
0
        public ActionResult Accept(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Meeting meeting = db.Meetings.Find(id);

            if (meeting == null)
            {
                return(HttpNotFound());
            }

            MeetingsStatu sts = db.MeetingsStatus.Where(x => x.MeetingId == id && x.UserId == User.Identity.Name).FirstOrDefault();

            if (sts == null)
            {
                sts = new MeetingsStatu();
            }

            sts.UserId     = User.Identity.Name;
            sts.MeetingId  = id;
            sts.IsAccepted = sts.IsAccepted == null || sts.IsAccepted == false ? true : false;
            if (sts.IsAccepted == true)
            {
                sts.AcceptedOn = DateTime.Now;
            }
            else
            {
                sts.RejectedOn = DateTime.Now;
            }
            if (sts.Id > 0)
            {
                db.Entry(sts).State = EntityState.Modified;
            }
            else
            {
                db.MeetingsStatus.Add(sts);
            }
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public async Task <ActionResult> Accept(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Meeting meeting = db.Meetings.Find(id);

            if (meeting == null)
            {
                return(HttpNotFound());
            }

            var           UserId = User.Identity.GetUserId();
            MeetingsStatu sts    = db.MeetingsStatus.Where(x => x.MeetingId == id && x.UserId == UserId).FirstOrDefault();

            if (sts == null)
            {
                sts = new MeetingsStatu();
            }
            var body = "";

            sts.UserId     = UserId;
            sts.MeetingId  = id;
            sts.IsAccepted = sts.IsAccepted == null || sts.IsAccepted == false ? true : false;
            var loginUser = GetUserInfoByUserId(UserId);

            if (sts.IsAccepted == true)
            {
                sts.AcceptedOn = DateTime.Now;
                body           = meeting.MeetingTitle + " meeting is accepted by " + loginUser.FullName;
            }
            else
            {
                sts.RejectedOn = DateTime.Now;
                body           = meeting.MeetingTitle + " meeting is rejected by " + loginUser.FullName;
            }
            if (sts.Id > 0)
            {
                db.Entry(sts).State = EntityState.Modified;
            }
            else
            {
                db.MeetingsStatus.Add(sts);
            }
            db.SaveChanges();

            var preference = GetUserNotificationPreference("meeting", meeting.UserId);
            var userModel  = GetUserInfoByUserId(sts.Meeting.UserId);


            if (preference.IsSms)
            {
                SendSmsViaClickaTell("+16475372344", body);
            }

            if (preference.IsEmail)
            {
                var recipients = new List <EmailAddress>();
                recipients.Add(new EmailAddress(userModel.Email, userModel.FullName));
                SendEmailViaSendGrid("Meeting " + (sts.IsAccepted == true ? "Accepted" : "Rejected"), body, recipients);
            }


            return(RedirectToAction("Index"));
        }