public async Task SendRecallMessageAsync(ApplicationUserManager UserManager, AppMember user, string unSubscribeCallBack, string medicineName)
        {
            String msgBody = "This notification is to let you know this " + medicineName + " medecine has been recalled";

            /*
             * Get the message template for communication preference
             */
            var result = template_manager.findTemplateByTypeAndCommPref((int)MessageTypeId.Recall, user.CommunicationType);

            if (user.CommunicationType == (int)CommunicationPreferenceId.Email)
            {
                await UserManager.SendEmailAsync(user.Id,
                                                 subject : "PPOK Refill System: Recall Notification",
                                                 body : "This notification is to let you know this medecine: " + medicineName + " has been recalled" +
                                                 "<br /><br />" +
                                                 "To unsubscribe, click here " + "<a href=\"" + unSubscribeCallBack + "\">unsubscribe</a>");
            }

            if (user.CommunicationType == (int)CommunicationPreferenceId.TextMessage)
            {
                var recallText = new MessageController();
                recallText.SendSms("+1" + user.PhoneNumber, msgBody);
            }

            if (user.CommunicationType == (int)CommunicationPreferenceId.PhoneCall)
            {
                var recallVoiceCall = new MessageController();
                recallVoiceCall.SendVoiceCall("+1" + user.PhoneNumber);
            }
        }
 private async Task SignInAsync(AppMember AppMember, bool isPersistent)
 {
     AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.TwoFactorCookie);
     AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, await AppMember.GenerateUserIdentityAsync(UserManager));
 }
        public async Task <bool> SendRefillMessageAsync(ApplicationUserManager UserManager, AppMember user, string callbackUrl, string unSubscribeCallBack, string code, string medicineName)
        {
            String msgBody = "Please confirm your refill by clicking!";

            /*
             * Get the message template for communication preference
             */
            var result = template_manager.findTemplateByTypeAndCommPref((int)MessageTypeId.Refill, user.CommunicationType);

            if (user.CommunicationType == (int)CommunicationPreferenceId.Email)
            {
                await UserManager.SendEmailAsync(user.Id,
                                                 subject : "PPOK Refill System: Refill Notification",
                                                 body : "Please confirm your refill by clicking <a href=\"" + callbackUrl + "\">here</a><br />Or" +
                                                 " click on the copy the following link on the browser: " + HttpUtility.HtmlEncode(callbackUrl) +
                                                 "<br /> Use the following code to access the confirmation page: <h3>" + HttpUtility.HtmlEncode(code) + "</h3>" +
                                                 "To unsubscribe, click here " + "<a href=\"" + HttpUtility.HtmlEncode(unSubscribeCallBack) + "\">unsubscribe</a>");
            }

            // Need to implement text message and phone call
            if (user.CommunicationType == (int)CommunicationPreferenceId.TextMessage)
            {
                var refillText = new MessageController();
                refillText.SendSms("+1" + user.PhoneNumber, msgBody);
            }

            if (user.CommunicationType == (int)CommunicationPreferenceId.PhoneCall)
            {
                var refillVoiceCall = new MessageController();
                refillVoiceCall.SendVoiceCall("+1" + user.PhoneNumber);
            }

            return(true);
        }
        public async Task SendBirthdayMessageAsync(ApplicationUserManager UserManager, AppMember user, string unSubscribeCallBack)
        {
            string msgBody = "HAPPY BIRTHDAY TO YOU TODAY";

            /*
             * Get the message template for communication preference
             */
            var result = template_manager.findTemplateByTypeAndCommPref((int)MessageTypeId.Birthday, user.CommunicationType);

            if (user.CommunicationType == (int)CommunicationPreferenceId.Email)
            {
                string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                await UserManager.SendEmailAsync(user.Id,
                                                 subject : "PPOK Refill System: Birthday Notification",
                                                 body : "HAPPY BIRTHDAY TO YOU TODAY!!!" +
                                                 "<br /><br />" +
                                                 "To unsubscribe, click here " + "<a href=\"" + HttpUtility.HtmlEncode(unSubscribeCallBack) + "\">unsubscribe</a>");
            }

            if (user.CommunicationType == (int)CommunicationPreferenceId.TextMessage)
            {
                var birthdayText = new MessageController();
                birthdayText.SendSms("+1" + user.PhoneNumber, msgBody);
            }

            if (user.CommunicationType == (int)CommunicationPreferenceId.PhoneCall)
            {
                var birthdayVoiceCall = new MessageController();
                birthdayVoiceCall.SendVoiceCall("+1" + user.PhoneNumber);
            }
        }
        public async Task <bool> SendPickUpMessageAsync(ApplicationUserManager UserManager, AppMember user, string unSubscribeCallBack, string medicineName)
        {
            String msgBody = "This notification is to let you know your " + medicineName + " medecine is ready for pick up.";

            /*
             * Get the message template for communication preference
             */
            var result = template_manager.findTemplateByTypeAndCommPref((int)MessageTypeId.PickUp, user.CommunicationType);

            if (user.CommunicationType == (int)CommunicationPreferenceId.Email)
            {
                string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                await UserManager.SendEmailAsync(user.Id,
                                                 subject : "PPOK Refill System: Pick Up Notification",
                                                 body : "This notification is to let you know your medecine: " + medicineName + " is ready for pick up." +
                                                 "<br /><br />" +
                                                 "To unsubscribe, click here " + "<a href=\"" + HttpUtility.HtmlEncode(unSubscribeCallBack) + "\">unsubscribe</a>");
            }

            if (user.CommunicationType == (int)CommunicationPreferenceId.TextMessage)
            {
                var pickupText = new MessageController();
                pickupText.SendSms("+1" + user.PhoneNumber, msgBody);
            }

            if (user.CommunicationType == (int)CommunicationPreferenceId.PhoneCall)
            {
                var pickupVoiceCall = new MessageController();
                pickupVoiceCall.SendVoiceCall("+1" + user.PhoneNumber);
            }

            return(true);
        }
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the AppMember from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var AppMember = new AppMember { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(AppMember);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(AppMember.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(AppMember, isPersistent: false, rememberBrowser: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var AppMember = new AppMember { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(AppMember, model.Password);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(AppMember, isPersistent:false, rememberBrowser:false);
                    
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(AppMember.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = AppMember.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(AppMember.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }