Пример #1
0
        /// <summary>
        /// updates shared user data
        /// </summary>
        /// <param name="sam"> SharedAccount Model </param>
        public SharedAccount UpdateSharedAccount(SharedAccountModel sam)
        {
            try
            {
                SharedAccount sharedAccount = null;
                if (sam != null)
                {
                    using (var _ctx = new ChinmayaEntities())
                    {
                        sharedAccount = _ctx.SharedAccounts.Where(x => x.From_UserId == sam.From_UserId).FirstOrDefault();

                        if (sharedAccount != null)
                        {
                            sharedAccount.IsApproved        = sam.IsApproved;
                            sharedAccount.IsDeclined        = sam.IsDeclined;
                            sharedAccount.UpdatedDate       = DateTime.Now;
                            _ctx.Entry(sharedAccount).State = EntityState.Modified;
                            _ctx.SaveChanges();
                        }
                    }
                }
                return(sharedAccount);
            }
            catch
            {
                throw;
            }
        }
Пример #2
0
        /// <summary>
        /// adds shared user data
        /// </summary>
        /// <param name="sam"> SharedAccount Model </param>
        public void PostSharedAccount(SharedAccountModel sam)
        {
            using (var _ctx = new ChinmayaEntities())
            {
                try
                {
                    var config = new MapperConfiguration(cfg =>
                    {
                        cfg.CreateMap <SharedAccountModel, SharedAccount>();
                    });
                    IMapper mapper = config.CreateMapper();

                    SharedAccount sa = new SharedAccount();
                    mapper.Map(sam, sa);

                    _ctx.SharedAccounts.Add(sa);
                    _ctx.SaveChanges();
                }

                catch
                {
                    throw;
                }
            }
        }
Пример #3
0
 public SharedAccount UpdateSharedAccount(SharedAccountModel obj)
 {
     try
     {
         return(_user.UpdateSharedAccount(obj));
     }
     catch
     {
         throw;
     }
 }
Пример #4
0
 public IHttpActionResult PostSharedAccount(SharedAccountModel obj)
 {
     try
     {
         _user.PostSharedAccount(obj);
         return(Ok("Success"));
     }
     catch
     {
         throw;
     }
 }
        public async Task <JsonResult> SharedAccountRequest(ApproveRejectModel arm)
        {
            UserModel um = await _user.GetUserInfo(arm.Email);

            um.IsApproved     = arm.IsApproved;
            um.Status         = arm.IsApproved ? true : false;
            um.EmailConfirmed = um.Status;

            HttpResponseMessage userResponseMessage = await Utility.GetObject("/api/User/PostUser", um, true);

            string status = arm.IsApproved ? "Approved" : "Rejected";

            if (userResponseMessage.IsSuccessStatusCode)
            {
                EmailTemplateModel etm = await _account.GetEmailTemplate(3);

                string primaryAccountEmail = await _account.GetFamilyPrimaryAccountEmail(arm.Email);

                string fromUserFullname = await _user.GetUserFullName(primaryAccountEmail);

                string emailSubject = etm.Subject
                                      .Replace("[Status]", status);
                etm.Subject = emailSubject;

                string emailBody = etm.Body
                                   .Replace("[FromUsername]", fromUserFullname)
                                   .Replace("[ToUsername]", arm.FullName)
                                   .Replace("[AcceptanceStatus]", status);
                etm.Body = emailBody;

                EmailManager em = new EmailManager
                {
                    Body    = etm.Body,
                    To      = arm.Email,
                    Subject = etm.Subject,
                    From    = ConfigurationManager.AppSettings["SMTPUsername"]
                };
                em.Send();

                SharedAccountModel sam = new SharedAccountModel();
                sam.From_UserId = await _account.GetUserIdByEmail(um.Email);

                if (status == "Approved")
                {
                    sam.IsApproved = true;
                }
                else
                {
                    sam.IsDeclined = true;
                }
                sam.UpdatedDate = DateTime.Now;
                HttpResponseMessage userResponseMessage2 = await Utility.GetObject("/api/User/UpdateSharedAccount", sam, true);

                var user = await Utility.DeserializeObject <SharedAccountModel>(userResponseMessage2);


                if (arm.AreAddressDetailsMatched && arm.IsApproved)
                {
                    FamilyMemberModel fm = new FamilyMemberModel();
                    fm.CellPhone         = um.CellPhone;
                    fm.DOB               = um.DOB;
                    fm.Email             = um.Email;
                    fm.FirstName         = um.FirstName;
                    fm.GenderData        = um.GenderId;
                    fm.LastName          = um.LastName;
                    fm.RelationshipData  = 6;
                    fm.MonthlyNewsLetter = false;
                    fm.UpdatedBy         = await _account.GetUserIdByEmail(um.Email);

                    HttpResponseMessage addFamilyMemberRes = await Utility.GetObject("/api/User/PostFamilyMember", fm, true);
                }
            }
            return(Json(new { IsSuccess = userResponseMessage.IsSuccessStatusCode }));
        }
        public async Task <ActionResult> AccountDetails(AccountDetails data, string prevBtn, string nextBtn)
        {
            UserModel              obj = GetUser();
            ToastModel             tm  = new ToastModel();
            SecurityQuestionsModel Sqm = new SecurityQuestionsModel();

            ContactDetails cd = new ContactDetails();

            cd.Address = obj.Address;
            cd.Country = obj.CountryId;
            ViewBag.SelectedCountry = obj.CountryId;
            cd.State = obj.StateId;
            ViewBag.SelectedState = obj.StateId;
            cd.City      = obj.City;
            cd.ZipCode   = obj.ZipCode;
            cd.HomePhone = obj.HomePhone;
            cd.CellPhone = obj.CellPhone;

            if (prevBtn != null)
            {
                TempData["ContactDetails"] = cd;
                return(RedirectToAction("ContactDetails"));
            }
            if (nextBtn != null)
            {
                Dictionary <int, string> SecurityQuestions = new Dictionary <int, string>();

                for (int i = 0; i < 5; i++)
                {
                    if ((Request.Form["AnswerTextbox_" + (i + 1)]) != "")
                    {
                        SecurityQuestions.Add((i + 1), Request.Form["AnswerTextbox_" + (i + 1)]);
                    }
                }

                AccountDetails Ad = new AccountDetails();
                Ad.Email                  = data.Email;
                Ad.Password               = data.Password;
                Ad.RetypePassword         = data.RetypePassword;
                Ad.AccountType            = data.AccountType;
                Ad.SecurityQuestionsModel = await _common.GetSecurityQuestions();

                ViewBag.SecurityQuestions = await _common.GetSecurityQuestions();

                foreach (var item in SecurityQuestions)
                {
                    Ad.SecurityQuestionsModel.ForEach(sq =>
                    {
                        if (sq.Id == item.Key)
                        {
                            sq.Value = item.Value;
                        }
                    });
                }

                if (SecurityQuestions.Count < 2)
                {
                    return(View("AccountDetails", Ad));
                }

                else
                {
                    if (ModelState.IsValid)
                    {
                        bool userRejected  = false;
                        bool isEmailExists = await _account.IsActiveUser(data.Email);

                        bool isFamilyMember = await _account.IsFamilyMember(data.Email);

                        int isAddressOrHomePhoneMatched = await _account.IsAddressOrHomePhoneMatched(cd);

                        if (isEmailExists)
                        {
                            tm.IsSuccess  = false;
                            tm.Message    = "Email already registered";
                            ViewBag.Toast = tm;
                            return(View("AccountDetails", Ad));
                        }

                        obj.Email    = data.Email;
                        obj.Password = data.Password;
                        EncryptDecrypt objEncryptDecrypt = new EncryptDecrypt();
                        obj.Password              = objEncryptDecrypt.Encrypt(data.Password, WebConfigurationManager.AppSettings["ServiceAccountPassword"]);
                        obj.IsIndividual          = Convert.ToBoolean(data.AccountType);
                        obj.UserSecurityQuestions = SecurityQuestions;
                        obj.Status = false;

                        // case: If user is added as a member of someone else's family
                        // send approval mail to primary account holder and user should be in inactive status until request has approved.
                        if (isFamilyMember || isAddressOrHomePhoneMatched != 0)
                        {
                            obj.IsIndividual      = true;
                            obj.IsApproveMailSent = true;
                            string primaryAccountEmail = string.Empty;

                            int emailTemplateId = isFamilyMember ? 2 : 9;
                            // if user has already requested for logins and again trying to get register
                            UserModel um = await _user.GetUserInfo(data.Email);

                            if (!string.IsNullOrEmpty(um.Id))
                            {
                                // if primary a/c holder Rejected the user request
                                if ((bool)um.IsApproveMailSent && um.IsApproved != null)
                                {
                                    userRejected = true;
                                    // so we have to reset the approval request
                                    um.IsApproved = null;
                                    // we need to update the user
                                    HttpResponseMessage userResponseMessage = await Utility.GetObject("/api/User/PostUser", um, true);
                                }

                                // approval mail sent to primary a/c and not yet decided
                                if ((bool)um.IsApproveMailSent && um.IsApproved == null && !userRejected)
                                {
                                    ViewBag.ApproveMailSent = true;
                                    ViewBag.ApproveContent  = "An approval email has been already sent to primary account holder of your family..! Please be patient until your request has been approved.";
                                    return(View("AccountDetails", Ad));
                                }
                            }

                            ViewBag.IsFamilyMember = true;
                            EmailTemplateModel etm1 = await _account.GetEmailTemplate(emailTemplateId);

                            string toUserFullname = string.IsNullOrEmpty(um.Id) ? obj.FirstName + " " + obj.LastName : await _user.GetUserFullName(data.Email);

                            if (isAddressOrHomePhoneMatched == 0)
                            {
                                primaryAccountEmail = await _account.GetFamilyPrimaryAccountEmail(data.Email);
                            }
                            else
                            {
                                primaryAccountEmail =
                                    isAddressOrHomePhoneMatched == 1
                                                                ? await _account.GetPrimaryAccountEmailByHomePhone(obj.HomePhone)
                                                                : await _account.GetPrimaryAccountEmailByAddress(cd);
                            }

                            string fromUserFullname = await _user.GetUserFullName(primaryAccountEmail);

                            string approvalLink1 = configMngr["SharedAccountRequestLink"]
                                                   + objEncryptDecrypt.Encrypt(data.Email, configMngr["ServiceAccountPassword"])
                                                   + "&aadm="
                                                   + isAddressOrHomePhoneMatched;

                            string emailBody1 = etm1.Body
                                                .Replace("[ToUsername]", toUserFullname)
                                                .Replace("[FromUsername]", fromUserFullname)
                                                .Replace("[URL]", approvalLink1);
                            etm1.Body = emailBody1;

                            EmailManager em1 = new EmailManager
                            {
                                Body    = etm1.Body,
                                To      = primaryAccountEmail,
                                Subject = etm1.Subject,
                                From    = ConfigurationManager.AppSettings["SMTPUsername"]
                            };
                            em1.Send();

                            obj.Id = null;
                            ViewBag.ApproveContent = "An approval email has been sent to primary account holder of your family..! Your account will be activated once your request has been approved.";
                            if (!userRejected)
                            {
                                HttpResponseMessage userResponseMessage = await Utility.GetObject("/api/User/PostUser", obj, true);

                                SharedAccountModel sam = new SharedAccountModel();
                                sam.To_UserId = await _account.GetUserIdByEmail(primaryAccountEmail);

                                sam.From_UserId = await _account.GetUserIdByEmail(obj.Email);

                                sam.CreatedDate = DateTime.Now;
                                HttpResponseMessage userResponseMessage2 = await Utility.GetObject("/api/User/PostSharedAccount", sam, true);
                            }

                            return(View("AccountDetails", Ad));
                        }

                        // If user is not a family member, allow him to register normally
                        HttpResponseMessage userResponseMessage1 = await Utility.GetObject("/api/User/PostUser", obj, true);

                        // if user registered successfully, then send an activation link
                        if (userResponseMessage1.IsSuccessStatusCode)
                        {
                            EmailTemplateModel etm = await _account.GetEmailTemplate(1);

                            string approvalLink = configMngr["UserActivationLink"]
                                                  + objEncryptDecrypt.Encrypt(data.Email, configMngr["ServiceAccountPassword"]);
                            string fullname  = obj.FirstName + " " + obj.LastName;
                            string emailBody = etm.Body
                                               .Replace("[Username]", fullname)
                                               .Replace("[URL]", approvalLink);
                            etm.Body = emailBody;

                            EmailManager em = new EmailManager
                            {
                                Body    = etm.Body,
                                To      = data.Email,
                                Subject = etm.Subject,
                                From    = ConfigurationManager.AppSettings["SMTPUsername"]
                            };
                            em.Send();
                            ViewBag.Message = "An email has been sent to registered email. Please activate your account";
                        }
                        return(View());
                    }
                }
            }
            return(View());
        }