public ActionResult Edit([Bind(Include = "TP_ID,image_url,is_Admin,tp_password,tp_fname,tp_lname,tp_email,tp_posting")] TraficPolice traficPolice, HttpPostedFileBase profilepic, string State)
        {
            if (ModelState.IsValid)
            {
                if (profilepic != null)
                {
                    if (profilepic.ContentType == "image/jpg" || profilepic.ContentType == "image/jpeg" || profilepic.ContentType == "image/png")
                    {
                        string ext = System.IO.Path.GetExtension(profilepic.FileName);
                        profilepic.SaveAs(Server.MapPath("/") + "/Content/PolicememberProfilePhoto/" + traficPolice.TP_ID + ext);

                        traficPolice.image_url = traficPolice.TP_ID + ext;
                    }
                    else
                    {
                        TempData["ErrorMsg"] = "image must be in formate of jpg/png/jpeg only";
                        return(RedirectToAction("Edit", new { id = traficPolice.TP_ID }));
                    }
                }
                else
                {
                }

                traficPolice.tp_posting      = State.Substring(2).ToUpper();
                traficPolice.tp_fname        = traficPolice.tp_fname.ToUpper();
                traficPolice.tp_lname        = traficPolice.tp_lname.ToUpper();
                db.Entry(traficPolice).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(traficPolice));
        }
        public ActionResult changepass(string password, string repassword)
        {
            if (Request.Cookies.Get("sotp") != null)
            {
                if (password.Equals(repassword))
                {
                    string       email = Request.Cookies["temail"].Value.ToString();
                    TraficPolice pu    = db.TPs.Where(p => p.tp_email == email).FirstOrDefault();
                    pu.tp_password = password;

                    db.SaveChanges();

                    Response.Cookies["rotp"].Expires   = DateTime.Now.AddDays(-1);
                    Response.Cookies["temail"].Expires = DateTime.Now.AddDays(-1);
                    ViewBag.msg1 = "Password Changed Successfully. Login by New Password";
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.msg = "Both password must be same!!!";
                    return(View());
                }
            }
            else
            {
                return(RedirectToAction("forgot", "PULogin"));
            }
        }
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TraficPolice traficPolice = db.TPs.Find(id);

            if (traficPolice == null)
            {
                return(HttpNotFound());
            }
            List <SelectListItem> StateList = new List <SelectListItem>();

            StateList.Add(new SelectListItem {
                Text = "Gujrat", Value = "GJgujrat"
            });
            StateList.Add(new SelectListItem {
                Text = "Maharashtra", Value = "MHMaharashtra"
            });
            StateList.Add(new SelectListItem {
                Text = "Rajsthan", Value = "RJRajsthan"
            });
            ViewBag.State = StateList;
            return(View(traficPolice));
        }
        public ActionResult DeleteConfirmed(string id)
        {
            TraficPolice traficPolice = db.TPs.Find(id);

            db.TPs.Remove(traficPolice);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TraficPolice traficPolice = db.TPs.Find(id);

            if (traficPolice == null)
            {
                return(HttpNotFound());
            }
            return(View(traficPolice));
        }
        public async System.Threading.Tasks.Task <ActionResult> Create([Bind(Include = "tp_fname,tp_lname,is_Admin,tp_email")] TraficPolice traficPolice, HttpPostedFileBase profilepic, string State)
        {
            if (ModelState.IsValid)
            {
                Random       r     = new Random();
                string       state = State.Substring(0, 2);
                TraficPolice tp;
                do
                {
                    string id = "TP" + state + r.Next(10000, 100000);
                    traficPolice.TP_ID = id;
                    tp = db.TPs.Find(id);
                } while (tp != null);


                traficPolice.tp_password = traficPolice.tp_fname.Substring(0, 3) + "@" + State.Substring(2, 5) + "1";
                traficPolice.tp_posting  = State.Substring(2).ToUpper();
                traficPolice.tp_fname    = traficPolice.tp_fname.ToUpper();
                traficPolice.tp_lname    = traficPolice.tp_lname.ToUpper();
                if (profilepic != null)
                {
                    if (profilepic.ContentType == "image/jpg" || profilepic.ContentType == "image/jpeg" || profilepic.ContentType == "image/png")
                    {
                        string ext = System.IO.Path.GetExtension(profilepic.FileName);
                        profilepic.SaveAs(Server.MapPath("/") + "/Content/PolicememberProfilePhoto/" + traficPolice.TP_ID + ext);
                        traficPolice.image_url = traficPolice.TP_ID + ext;
                    }
                    else
                    {
                        TempData["ErrorMsg"] = "image must be in formate of jpg/png/jpeg only";
                        return(RedirectToAction("Create"));
                    }
                }

                db.TPs.Add(traficPolice);
                db.SaveChanges();
                var user = new ApplicationUser {
                    UserName = traficPolice.TP_ID, Email = traficPolice.tp_email
                };
                var result = await UserManager.CreateAsync(user, traficPolice.tp_password);

                if (result.Succeeded)
                {
                }
                return(RedirectToAction("Index"));
            }

            return(View(traficPolice));
        }
        public ActionResult forgot(string email)
        {
            TraficPolice pu = db.TPs.Where(p => p.tp_email == email).FirstOrDefault();

            if (pu == null)
            {
                ViewBag.msg = "Account does not exist for given email!!!";
                return(View());
            }
            else
            {
                try
                {
                    Random rnd = new Random();
                    string se, sp, sub, body;
                    long   otp = rnd.Next(100000, 999999);
                    Session["sotp"] = otp;

                    se   = "*****@*****.**";
                    sp   = "Devendra@285";
                    sub  = "OTP for CHANGE PASSWORD in e-Parivahan";
                    body = "<h3>Welcome " + pu.tp_fname + " " + pu.tp_lname + "</h3><p><b>OTP is " + otp.ToString() + "</b> for verify your email in e-Parivahan account.Please do not share with anyone.</p><p>Thank You!!</p>";
                    SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                    client.EnableSsl             = true;
                    client.Timeout               = 100000;
                    client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                    client.UseDefaultCredentials = false;
                    client.Credentials           = new NetworkCredential(se, sp);

                    MailMessage mm = new MailMessage(se, pu.tp_email, sub, body);
                    mm.IsBodyHtml   = true;
                    mm.BodyEncoding = UTF8Encoding.UTF8;

                    client.Send(mm);
                }
                catch (Exception e)
                {
                    throw e;
                }

                Response.Cookies.Add(new HttpCookie("temail", email));
                Response.Cookies.Add(new HttpCookie("rotp", "forgot"));
                return(RedirectToAction("OTP", "TrafficLogin"));
            }
        }
        public ActionResult Search()
        {
            List <SelectListItem> StateList = new List <SelectListItem>();

            StateList.Add(new SelectListItem {
                Text = "Gujrat", Value = "Gujrat"
            });
            StateList.Add(new SelectListItem {
                Text = "Maharashtra", Value = "Maharashtra"
            });
            StateList.Add(new SelectListItem {
                Text = "Rajsthan", Value = "Rajsthan"
            });
            ViewBag.State = StateList;
            TraficPolice traficPolice = null;

            return(View(traficPolice));
        }
        public ActionResult Index(string id, string password)
        {
            TraficPolice pu = db.TPs.Where(p => p.TP_ID == id && p.tp_password == password).FirstOrDefault();

            if (pu == null)
            {
                ViewBag.err = "Invalid Username / Password!!";
                return(View());
            }
            else
            {
                if (pu.is_Admin == true)
                {
                    Response.Cookies.Add(new HttpCookie("tAdmin", "Yes"));
                }
                Response.Cookies.Add(new HttpCookie("tpid", pu.TP_ID));
                Response.Cookies.Add(new HttpCookie("tname", pu.tp_fname));

                return(RedirectToAction("Index", "TPHome"));
            }
        }