public string SaveInvitedUsers(int UserProfileId, string UserType, PromotionEmail PromotionEmail) { try { string status = ""; if (PromotionEmail.Id == 0) { PromotionEmail PromotionEmailsForSave = new PromotionEmail(); PromotionEmailsForSave = _db.PromotionEmails.Where(x => x.Email == PromotionEmail.Email).FirstOrDefault(); List <PromotionEmail> PromotionEmailsForSaveList = new List <PromotionEmail>(); PromotionEmailsForSaveList = _db.PromotionEmails.Where(x => x.InvitedBy == UserProfileId).ToList(); if (PromotionEmailsForSave == null) { if (UserType == "SuperAdmin" && PromotionEmailsForSaveList.Count >= 4000) { status = "InvitationExceeded"; } else if (UserType == "Customer" && PromotionEmailsForSaveList.Count >= 10) { status = "InvitationExceeded"; } else if (UserType == "Sub Customer") { status = "NotPermission"; } else { _db.PromotionEmails.Add(PromotionEmail); _db.SaveChanges(); status = "Success"; } } else { status = "AlreadyExists"; } } else { PromotionEmail PromotionEmails = new PromotionEmail(); PromotionEmails = _db.PromotionEmails.Where(x => x.Id == PromotionEmail.Id).FirstOrDefault(); PromotionEmails.UserFullName = PromotionEmail.UserFullName; PromotionEmails.Email = PromotionEmail.Email; PromotionEmails.Message = PromotionEmail.Message; _db.SaveChanges(); } return(status); } catch (Exception ex) { throw; } }
public ActionResult RegisterUser(string Email, string AuthToken) { Logout(null); PromotionEmail PromotionEmail = new PromotionEmail(); LoginDAL DAL = new LoginDAL(); LoginViewModel ViewModel = new LoginViewModel(); PromotionEmail = DAL.CheckUserIsAuhenticatedForRegistration(Email, AuthToken); ViewModel.RegisterUserEmail = Email; return(View(ViewModel)); }
public PromotionEmail CheckUserIsAuhenticatedForRegistration(string Email, string AuthToken) { try { PromotionEmail PromotionEmail = new PromotionEmail(); if (!String.IsNullOrEmpty(Email) && !String.IsNullOrEmpty(AuthToken)) { PromotionEmail = _db.PromotionEmails.Where(x => x.Email.ToLower().Equals(Email.ToLower()) && x.AuthToken == AuthToken).FirstOrDefault(); } return(PromotionEmail); } catch (Exception) { throw; } }
public ActionResult SaveInvitedUsers(PromotionEmail PromotionEmail) { try { string status = ""; string LimitationMessage = ""; SuperAdminDAL DAL = new SuperAdminDAL(); SuperAdminViewModel viewModel = new SuperAdminViewModel(); int UserProfileId = Convert.ToInt32(Session["UserProfileId"]); string UserType = Convert.ToString(Session["UserType"]); string AuthToken = Guid.NewGuid().ToString(); if (UserType == "SuperAdmin") { AuthToken = AuthToken + "~10"; PromotionEmail.AllowedInvitations = 10; } else { AuthToken = AuthToken + "~0"; PromotionEmail.AllowedInvitations = 0; } PromotionEmail.AuthToken = AuthToken; PromotionEmail.InvitedBy = UserProfileId; PromotionEmail.RegistrationLink = "https://moments.fooddesignbrazil.com/Login/RegisterUser?Email=" + PromotionEmail.Email + "&AuthToken=" + AuthToken; status = DAL.SaveInvitedUsers(UserProfileId, UserType, PromotionEmail); if (status == "AlreadyExists") { LimitationMessage = "This User Is Already Invited."; } else if (status == "Success") { //sending email SendInvitationEmail(PromotionEmail.Email, PromotionEmail.RegistrationLink); //sending email end LimitationMessage = "Record Save Successfully."; } else if (status == "InvitationExceeded") { LimitationMessage = "Your Invitation Count Reached To Limit."; } else if (status == "NotPermission") { LimitationMessage = "Your have Not Permission To Invite."; } else { LimitationMessage = ""; } viewModel.PromotionEmailList = DAL.GetInvitedUsers(UserProfileId); var ManageInvitedUsers = RenderRazorViewToString(this.ControllerContext, "_ManageInvitedUsers", viewModel); string data = JsonConvert.SerializeObject(new { LimitationMessage, ManageInvitedUsers }); return(Json(data, JsonRequestBehavior.AllowGet)); // return PartialView("_ManageInvitedUsers", viewModel); } catch (Exception ex) { throw; } }