Example #1
0
        public int VerifyAccountForMobile(VerifyAccountForMobileRequest verifyAccountForMobileRequest)
        {
            using (DemsifyEntities dataContext = new DemsifyEntities())
            {
                ObjectParameter result = new ObjectParameter("Result", typeof(int));

                dataContext.VerifyAccountForMobile(Utility.TrimString(verifyAccountForMobileRequest.UserName), Utility.TrimString(verifyAccountForMobileRequest.Mobile), Utility.TrimString(verifyAccountForMobileRequest.MobileOTP), Utility.TrimString(verifyAccountForMobileRequest.EmailOTP), result);

                return(Convert.ToInt32(result.Value));
            }
        }
        public IHttpActionResult VerifyAccountForMobile(VerifyAccountForMobileRequest verifyAccountForMobileRequest)
        {
            var responses = new Responses();

            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                int result = iAccount.VerifyAccountForMobile(verifyAccountForMobileRequest);
                if (result > 0)
                {
                    try
                    {
                        var verifyAccountHtmlCode = System.IO.File.ReadAllText(string.Format("{0}", HttpContext.Current.Server.MapPath(string.Format("{0}{1}", ConfigurationManager.AppSettings["EmailTemplatePath"], ConfigurationManager.AppSettings["VerifiedAccountEmailTemplate"]))));

                        verifyAccountHtmlCode = verifyAccountHtmlCode.Replace("[EMAILID]", verifyAccountForMobileRequest.UserName);
                        verifyAccountHtmlCode = verifyAccountHtmlCode.Replace("[SITEURL]", ConfigurationManager.AppSettings["SiteUrl"]);
                        verifyAccountHtmlCode = verifyAccountHtmlCode.Replace("[SITENAME]", ConfigurationManager.AppSettings["SiteName"]);

                        var mainTemplateHtmlCode = System.IO.File.ReadAllText(string.Format("{0}", HttpContext.Current.Server.MapPath(string.Format("{0}{1}", ConfigurationManager.AppSettings["EmailTemplatePath"], ConfigurationManager.AppSettings["MainEmailTemplate"]))));
                        mainTemplateHtmlCode = mainTemplateHtmlCode.Replace("[SITEURL]", ConfigurationManager.AppSettings["SiteUrl"]);
                        mainTemplateHtmlCode = mainTemplateHtmlCode.Replace("[SITENAME]", ConfigurationManager.AppSettings["SiteName"]);
                        mainTemplateHtmlCode = mainTemplateHtmlCode.Replace("[PAGECONTENT]", verifyAccountHtmlCode);

                        string subject     = "Verified Account";
                        string mailTo      = verifyAccountForMobileRequest.UserName;
                        string CC          = string.Empty;
                        string BCC         = string.Empty;
                        string body        = mainTemplateHtmlCode;
                        string displayName = ConfigurationManager.AppSettings["SiteName"];
                        string attachments = string.Empty;
                        Utility.SendMail(mailTo, CC, BCC, subject, body, displayName, attachments, true);
                    }
                    catch (Exception ex)
                    {
                        Utility.WriteLog("VerifyAccount", verifyAccountForMobileRequest, "Error while sending verification email. (AccountController)", ex.ToString());
                    }

                    responses.Status      = Utility.SUCCESS_STATUS_RESPONSE;
                    responses.Description = "User verified successfully.";
                }
                else
                {
                    if (result == -1)
                    {
                        responses.Status      = Utility.ERROR_STATUS_RESPONSE;
                        responses.Description = "Invalid OTP.";
                    }
                    else
                    {
                        responses.Status      = Utility.ERROR_STATUS_RESPONSE;
                        responses.Description = "Error while verifying user.";
                    }
                }
            }
            catch (Exception ex)
            {
                responses.Status      = Utility.ERROR_STATUS_RESPONSE;
                responses.Description = "Error while verifying user.";

                Utility.WriteLog("VerifyAccountForMobile", verifyAccountForMobileRequest, "Error while verifying user. (AccountGuestController)", ex.ToString());
            }
            return(Ok(responses));
        }