public ActionResult Edit([Bind(Include = "id,name,gender,emailid,address,mobileno,qualification,dob,photo,storeid,password,dateofjoining,dateofleave,status")] storeemployee storeemployee, HttpPostedFileBase Photo)
        {
            if (storeemployee.dateofleave == null)
            {
                storeemployee.dateofleave = "";
            }

            if (ModelState.IsValid)
            {
                try
                {
                    string photoname = Photo.FileName;
                    Photo.SaveAs(Server.MapPath("~/uploads/" + photoname));
                    storeemployee.photo = "~/uploads/" + photoname;
                }
                catch (Exception e)
                {
                }
                db.Entry(storeemployee).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.storeid = new SelectList(db.stores, "storeid", "storename", storeemployee.storeid);
            return(View(storeemployee));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            storeemployee storeemployee = db.storeemployees.Find(id);

            db.storeemployees.Remove(storeemployee);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: storeemployees/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            storeemployee storeemployee = db.storeemployees.Find(id);

            if (storeemployee == null)
            {
                return(HttpNotFound());
            }
            return(View(storeemployee));
        }
        public ActionResult Create([Bind(Include = "id,name,gender,emailid,address,mobileno,qualification,dob,photo,storeid,dateofjoining")] storeemployee storeemployee, HttpPostedFileBase Photo)
        {
            string rand = new Random().Next(1111, 9999).ToString();

            storeemployee.password    = rand;
            storeemployee.status      = "Active";
            storeemployee.dateofleave = "";
            if (ModelState.IsValid)
            {
                string photoname = Photo.FileName;
                Photo.SaveAs(Server.MapPath("~/uploads/" + photoname));
                storeemployee.photo = "~/uploads/" + photoname;
                db.storeemployees.Add(storeemployee);
                db.SaveChanges();

                var query = (from emp in db.storeemployees
                             orderby emp.id descending
                             select emp).First();

                MailMessage mailmsg = new MailMessage();
                mailmsg.To.Add(storeemployee.emailid);
                mailmsg.From       = new MailAddress("*****@*****.**");
                mailmsg.Subject    = "Employee Login Details For " + Session["storename"];
                mailmsg.Body       = "<div style='text-align:center'><img src='https://www.walmartbrandcenter.com/uploadedImages/BrandCenter/Content/downloads/Logos/specifications/specifications-logo2.jpg?n=4490' /> </br></div>" + "Login ID is : " + query.id + Environment.NewLine + "Password : "******"smtp.gmail.com";
                client.Port        = 587;
                client.EnableSsl   = true;
                client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Female123");
                try
                {
                    client.Send(mailmsg);
                    ViewBag.Message = "Mail Sent Successfully!!";
                }
                catch (Exception ex)
                {
                    ViewBag.Message = ex.Message;
                }


                return(RedirectToAction("Index"));
            }
            ViewBag.storeid = new SelectList(db.stores, "storeid", "storename", storeemployee.storeid);
            return(View(storeemployee));
        }
        // GET: storeemployees/Edit/5
        public ActionResult Edit(int?id)
        {
            if (Session["storeid"] == null)
            {
                return(RedirectToAction("storelogin", "stores"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            storeemployee storeemployee = db.storeemployees.Find(id);

            if (storeemployee == null)
            {
                return(HttpNotFound());
            }
            ViewBag.storeid = new SelectList(db.stores, "storeid", "storename", storeemployee.storeid);
            return(View(storeemployee));
        }