Event Account Controller For login - B M SOLUTION
  • Event Account Controller For login

      public ActionResult Login()

            {

                MainModel itemnew = new MainModel();


                if (Request.Cookies["mysocietyCookies"] != null)

                {

                    string sid = Request.Cookies["mysocietyCookies"].Value;

                    string[] AllArray = sid.Split(',');

                    ViewBag.Id = AllArray[0];

                    ViewBag.UserName = AllArray[1];

                    ViewBag.Role = AllArray[2];

                    ViewBag.Pic = AllArray[3];

                    Guid RefId = Guid.Empty;

                    Guid.TryParse(AllArray[0], out RefId);

                    itemnew.PermissionList = PermissionManager.GetByUserId(RefId);


                    ViewBag.Msg = "";

                    ViewBag.Msg = (TempData[Constant.INFO_MESSAGE] != null ? TempData[Constant.INFO_MESSAGE] : string.Empty).ToString();

                    TempData[Constant.INFO_MESSAGE] = "";

                    ViewBag.TypeCss = "success";

                    ViewBag.MsgTitle = "Success!";

                    return View("~/Views/Admin/Index.cshtml", itemnew);

                }

                else

                {


                    return View("~/Views/Account/Login.cshtml");

                }


            }

            public ActionResult UserLogin(FormCollection coll)

            {

                MainModel itemnew = new MainModel();

                string Name = coll["mobile"];

                if (Name != null)

                {

                    //string Password = encryptpass(coll["pass1"]);

                    string Password = coll["password"];

                    Registration obj = RegistrationManager.Login(Name, Password);

                    if (obj != null)

                    {

                        HttpCookie GateCookies = new HttpCookie("mysocietyCookies");

                        GateCookies.Value = obj.Id.ToString() + "," + obj.Name + "," + obj.Role + "," + obj.Pic + "," + obj.MobileNo + "," + obj.SocietyId + "," + obj.Extra2;

                        GateCookies.Expires = DateTime.Now.AddMonths(2);

                        Response.Cookies.Add(GateCookies);

                        ViewBag.Name = obj.Name;

                        return RedirectToAction("DashBoard");

                    }

                    else

                        return View("~/Views/Account/Login.cshtml");

                }

                return View("~/Views/Account/Login_msg.cshtml");

            }

            private static string auto()

            {

                int count = 0;

                SqlConnection con = new SqlConnection(connection);

                SqlCommand com = new SqlCommand("select Max(code)as code from [Registration]", con);

                con.Open();

                var icount = com.ExecuteScalar();

                if (icount != DBNull.Value && icount != null)

                    count = Convert.ToInt32(icount) + 1;

                else

                    count = 1;


                con.Close();


                string chars = "MM00" + count.ToString();

                return chars;

            }

            private static string CreateRandomPassword(int length = 4)

            {

                // Create a string of characters, numbers, special characters that allowed in the password  

                string validChars = "0123456789";

                Random random = new Random();


                // Select one random character at a time from the string  

                // and create an array of chars  

                char[] chars = new char[length];

                for (int i = 0; i < length; i++)

                {

                    chars[i] = validChars[random.Next(0, validChars.Length)];

                }

                return new string(chars);

            }


            public string apicall(string url)

            {

                HttpWebRequest httpreq = (HttpWebRequest)WebRequest.Create(url);

                try

                {

                    HttpWebResponse httpres = (HttpWebResponse)httpreq.GetResponse();

                    StreamReader sr = new StreamReader(httpres.GetResponseStream());

                    string results = sr.ReadToEnd();

                    sr.Close();

                    return results;

                }

                catch

                {

                    return "0";

                }

            }


            public ActionResult Register()

            {


                MainModel itemnew = new MainModel();


                itemnew.RegistrationList = RegistrationManager.GetAll();


                ViewBag.UserType = new SelectList(Constant.UserType, "Text", "Value");



                ViewBag.Msg = "";

                ViewBag.Msg = (TempData[Constant.INFO_MESSAGE] != null ? TempData[Constant.INFO_MESSAGE] : string.Empty).ToString();

                TempData[Constant.INFO_MESSAGE] = "";

                ViewBag.TypeCss = "success";

                ViewBag.MsgTitle = "Success!";


                return View("~/Views/Account/Register.cshtml", itemnew);



            }

            public ActionResult SaveRegistration(FormCollection coll)

            {


                MainModel itemnew = new MainModel();


                List<Registration> AlredyExist = RegistrationManager.GetAll().Where(x => x.MobileNo == coll["mobile"]).ToList();

                if (AlredyExist.Count > 0)

                {

                    Session["alert"] = "Danger";

                    TempData[MYSociety.AppCode.Constant.INFO_MESSAGE] = "Record Already Exist!! You clicked more than once or trying to add duplicate entry.";

                    return RedirectToAction("Register");

                }

                else

                {

                    Guid Id = Guid.Empty;

                    Guid.TryParse(coll["Id"], out Id);

                    Registration obj = new Registration();

                    obj.Id = Guid.NewGuid();


                    obj.RegCode = auto();

                    obj.App_Date = DateTime.Now.ToString("dd-MM-yyyy");

                    obj.Name = coll["name"];

                    obj.Address = "";

                    obj.MobileNo = coll["mobile"];

                    obj.Category = coll["drpusertype"];

                    obj.Pic = string.Empty;

                    obj.Tower = "00000000-0000-0000-0000-000000000000";

                    obj.FlatNo = "00000000-0000-0000-0000-000000000000"; 

                    obj.SocietyId = Guid.Empty;

                    obj.EmailId = string.Empty;

                    obj.Password = coll["registerPassword"];

                    obj.DocUpload1 = string.Empty;

                    obj.DocUpload2 = string.Empty;

                    obj.Status = "Pending";

                    obj.InTime = DateTime.Now;

                    obj.OutTime = DateTime.Now;

                    obj.Extra1 = string.Empty;

                    obj.Extra2 = "User";

                    obj.Role = Guid.Empty; ;

                    obj.CreatedBy = "00000000-0000-0000-0000-000000000000";  

                    obj.UpdatedBy = "Admin";

                    obj.CreatedOn = obj.UpdatedOn = DateTime.Now;

                    obj.RefPerson = "";

                    obj.RefMobile = "";

                    obj.Extra3 = "";

                    obj.Extra4 = "";

                    obj.Bio = "";

                    RegistrationManager.Add(obj);


                    HttpCookie GateCookies = new HttpCookie("mysocietyCookies");

                    GateCookies.Value = obj.Id.ToString() + "," + obj.Name + "," + obj.Role + "," + obj.MobileNo + "," + obj.Extra2;

                    GateCookies.Expires = DateTime.Now.AddDays(2);//AddMonths(2);

                    Response.Cookies.Add(GateCookies);

                    ViewBag.Id = obj.Id;

                    //HttpCookie mbno = new HttpCookie("mbno");

                    //mbno.Value = obj.MobileNo + "," + obj.Id.ToString(); ;

                    //mbno.Expires = DateTime.Now.AddMinutes(5);

                    //Response.Cookies.Add(mbno);


                    #region OTP

                    //For generating OTP

                    Random r = new Random();

                    string OTP = r.Next(1000, 9999).ToString();


                    #region Send SMS API


                    if (obj.MobileNo != "")

                    {

                        string mobile = obj.MobileNo;

                        string message = "Your OTP code is - " + OTP;

                        itemnew.SMSList = SMSManager.GetAll().Take(1).ToList();

                        string result = apicall("http://" + itemnew.SMSList[0].DName + "//sendsms.jsp?user=" + itemnew.SMSList[0].UId + "&password=" + itemnew.SMSList[0].Pin + "&mobiles=" + mobile + "&sms=" + message + "&senderid=" + itemnew.SMSList[0].SenderId);

                    }

                   

                    #endregion


                    //Store the OTP in session to verify in next page.


                    Session["OTP"] = OTP;


                    #endregion

                    ViewBag.MsgL = "OPT Sent Successfully.";

                    ViewBag.MsgTitle = "Success!";


                    return PartialView("~/Views/Account/OTP.cshtml");


                    #region Emaid Send Studen Details

                    //TemplateEngineManager templateEngine = new TemplateEngineManager("UserRegistration.htm");


                    //if (!string.IsNullOrEmpty(obj.Name))

                    //    templateEngine.Variables.Add("MemberName", obj.Name);

                    //else

                    //    templateEngine.Variables.Add("MemberName", string.Empty);


                    //if (!string.IsNullOrEmpty(obj.EmailId))

                    //    templateEngine.Variables.Add("Email", string.Empty);

                    //else

                    //    templateEngine.Variables.Add("Email", string.Empty);


                    //if (!string.IsNullOrEmpty(obj.MobileNo))

                    //    templateEngine.Variables.Add("LoginId", obj.MobileNo);

                    //else

                    //    templateEngine.Variables.Add("LoginId", string.Empty);


                    //if (!string.IsNullOrEmpty(obj.Password))

                    //    templateEngine.Variables.Add("Password", obj.Password);

                    //else

                    //    templateEngine.Variables.Add("Password", string.Empty);


                    //string CustomerTo = "bmsolution42@gmail.com";// coll["email"];                        // Sender Mail Id 

                    //string subject = "no-reply";


                    //string from = ConfigurationManager.AppSettings["fromEmail"]; // Recive Mail Id

                    //ConstantEmail.SendMail(CustomerTo, from, subject, templateEngine.GetFileContent());


                    Session["alert"] = "";


                    ViewBag.Msg = "";

                    ViewBag.Msg = (TempData[MYSociety.AppCode.Constant.INFO_MESSAGE] != null ? TempData[MYSociety.AppCode.Constant.INFO_MESSAGE] : string.Empty).ToString();

                    TempData[MYSociety.AppCode.Constant.INFO_MESSAGE] = "";

                    ViewBag.TypeCss = "success";

                    ViewBag.MsgTitle = "Success!";


                    #endregion


                }

                return RedirectToAction("Register");


            }

            public ActionResult SubmitOTP(FormCollection coll)

            {

                if (Session["OTP"] != null)

                {

                    string sid = Request.Cookies["mysocietyCookies"].Value;

                    string[] AllArray = sid.Split(',');

                    ViewBag.Id = AllArray[0];

                    ViewBag.Name = AllArray[1];

                    Guid RefId = Guid.Empty;

                    Guid.TryParse(AllArray[0], out RefId);


                    string otpvalue1 = coll["v1"];

                    string otpvalue2 = coll["v2"];

                    string otpvalue3 = coll["v3"];

                    string otpvalue4 = coll["v4"];

                    string UserId = coll["UserId"];

                    Guid UId = Guid.Empty;

                    Guid.TryParse(UserId, out UId);


                    string OTPMatchValue = otpvalue1 + otpvalue2 + otpvalue3 + otpvalue4;


                    if (Session["OTP"].ToString() == OTPMatchValue)

                    {

                        MainModel itemnew = new MainModel();


                        itemnew.Registration = RegistrationManager.GetById(RefId);


                        Registration obj = RegistrationManager.Login(itemnew.Registration.MobileNo, itemnew.Registration.Password);

                        if (obj != null)

                        {

                            HttpCookie GateCookies = new HttpCookie("mysocietyCookies");

                            GateCookies.Value = obj.Id.ToString() + "," + obj.Name + "," + obj.Role + "," + obj.MobileNo + "," + obj.Extra2;

                            GateCookies.Expires = DateTime.Now.AddDays(2);//AddMonths(2);

                            Response.Cookies.Add(GateCookies);


                            ViewBag.MsgL = "You have enter correct OTP.";

                            Session["OTP"] = null;

                            return RedirectToAction("DashBoard");


                        }

                        else

                            return View("~/Views/Account/Login.cshtml");

                    }

                    else

                    {

                        ViewBag.MsgL = "Pleae enter correct OTP.";

                        return PartialView("~/Views/Account/OTP.cshtml");

                    }

                }

                else

                    return PartialView("~/Views/Account/OTP.cshtml");

            }


            public ActionResult DashBoard()

            {

                MainModel itemnew = new MainModel();


                if (Request.Cookies["mysocietyCookies"] != null)

                {

                    string sid = Request.Cookies["mysocietyCookies"].Value;

                    string[] AllArray = sid.Split(',');

                    ViewBag.Id = AllArray[0];

                    ViewBag.Name = AllArray[1];

                    Guid RefId = Guid.Empty;

                    Guid.TryParse(AllArray[0], out RefId);


                    itemnew.RegistrationList = RegistrationManager.GetAll().Where(x => x.Extra2 == ViewBag.RoleName).ToList();

                    Guid UId = Guid.Empty;

                    Guid.TryParse(AllArray[0], out UId);

                    itemnew.Registration = RegistrationManager.GetById(UId);

                    string Role = itemnew.Registration.Extra2;

                    string Status = itemnew.Registration.Status;

                    ViewBag.RoleName = itemnew.Registration.Extra2;

                    itemnew.PermissionList = PermissionManager.GetByUserId(RefId);


                    #region dropdownlist

                    List<Society> societyList = SocietyManager.GetAll().ToList();

                    List<Tower> towerList = TowerManager.GetAll().ToList();

                    List<Flower> floorList = FlowerManager.GetAll().ToList();

                    List<Flat> flatList = FlatManager.GetAll().ToList();


                    if (UId != Guid.Empty)

                    {

                        //itemnew.Registration = RegistrationManager.GetById(Id);

                        if (itemnew.Registration.SocietyId != Guid.Empty)

                        {

                            ViewBag.Society = new SelectList(societyList, "Id", "Name", itemnew.Registration.SocietyId);

                            ViewBag.Tower = new SelectList(towerList, "Id", "Name", itemnew.Registration.Tower);

                            ViewBag.Flower = new SelectList(towerList, "Id", "Name", itemnew.Registration.Extra1); // Floor

                            ViewBag.Flat = new SelectList(flatList, "Id", "Name", itemnew.Registration.FlatNo);

                            ViewBag.profileradio = new SelectList(Constant.profileradio, "Text", "Value", itemnew.Registration.CreatedBy);

                        }

                        else

                        {

                            towerList = new List<Tower>();

                            floorList = new List<Flower>();

                            flatList = new List<Flat>();

                            ViewBag.Society = new SelectList(societyList, "Id", "Name");

                            ViewBag.Tower = new SelectList(towerList, "Id", "Name");

                            ViewBag.Flower = new SelectList(floorList, "Id", "Name");

                            ViewBag.Flat = new SelectList(flatList, "Id", "Name");

                            ViewBag.profileradio = new SelectList(Constant.profileradio, "Text", "Value");

                        }


                    }


                    #endregion



                    if (Role == "Admin" && Status == "Active")

                        return View("~/Views/Admin/Index.cshtml", new MainModel { RegistrationList = itemnew.RegistrationList, PermissionList = itemnew.PermissionList });

                    else if (Role == "User" && Status == "Active")

                        return View("~/Views/Home/Index.cshtml", new MainModel { RegistrationList = itemnew.RegistrationList, PermissionList = itemnew.PermissionList });

                    else if (Role == "User" && Status == "Pending")

                        return View("~/Views/Account/UserProfile.cshtml", new MainModel { Registration = itemnew.Registration, RegistrationList = itemnew.RegistrationList, PermissionList = itemnew.PermissionList });

                    else

                        return View("~/Views/Account/Login.cshtml");

                }

                else

                    return View("~/Views/Account/Login.cshtml");

            }

  • You might also like

    No comments :

    Post a Comment