public async Task <ActionResult> DeleteConfirmed(int id)
        {
            studentdetail studentdetail = await db.studentdetails.FindAsync(id);

            db.studentdetails.Remove(studentdetail);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        // GET: studentdetails/Create
        public ActionResult Create()
        {
            studentdetail student = new studentdetail();

            student.date      = System.DateTime.Now;
            student.dob       = System.DateTime.Now;
            ViewBag.AgentId   = new SelectList(db.Agents, "AgentId", "AgentName");
            ViewBag.CountryId = new SelectList(db.Countries, "CountryId", "Name");
            return(View(student));
        }
        public async Task <ActionResult> Edit([Bind(Include = "StudentId,name,dob,gender,fathername,mothername,address,phone,phone2,email,married,board,qualification,marks,gap,gapdetail,refusal,refusaldetail,filetype,CountryId,intake,year,note,itr,uid,TrackingID,date,Editingdate,Status,AgentId")] studentdetail studentdetail)
        {
            if (ModelState.IsValid)
            {
                db.Entry(studentdetail).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.AgentId   = new SelectList(db.Agents, "AgentId", "AgentName", studentdetail.AgentId);
            ViewBag.CountryId = new SelectList(db.Countries, "CountryId", "Name", studentdetail.CountryId);
            return(View(studentdetail));
        }
        // GET: studentdetails/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            studentdetail studentdetail = await db.studentdetails.FindAsync(id);

            if (studentdetail == null)
            {
                return(HttpNotFound());
            }
            return(View(studentdetail));
        }
        // GET: studentdetails/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            studentdetail studentdetail = await db.studentdetails.FindAsync(id);

            if (studentdetail == null)
            {
                return(HttpNotFound());
            }
            ViewBag.AgentId   = new SelectList(db.Agents, "AgentId", "AgentName", studentdetail.AgentId);
            ViewBag.CountryId = new SelectList(db.Countries, "CountryId", "Name", studentdetail.CountryId);

            return(View(studentdetail));
        }
        public async Task <ActionResult> Create([Bind(Include = "StudentId,name,dob,gender,fathername,mothername,address,phone,phone2,email,married,board,qualification,marks,gap,gapdetail,refusal,refusaldetail,filetype,CountryId,intake,year,note,itr,uid,TrackingID,date,Editingdate,Status,AgentId")] studentdetail studentdetail)
        {
            if (ModelState.IsValid)
            {
                if (Session["User"] != null)
                {
                    studentdetail student = db.studentdetails.FirstOrDefault();
                    if (student == null)
                    {
                        studentdetail.TrackingID = "TRK_1001";
                    }
                    else
                    {
                        var valc = db.studentdetails.Max(x => x.TrackingID);

                        string[] rec = valc.Split('_');
                        var      ab  = rec[1].ToString();
                        studentdetail.TrackingID = "TRK_" + (Convert.ToInt32(ab) + 1).ToString();
                    }
                    studentdetail.Status      = true;
                    studentdetail.Editingdate = System.DateTime.Now;
                    studentdetail.uid         = Convert.ToInt32(Session["User"].ToString());
                    db.studentdetails.Add(studentdetail);
                    db.SaveChanges();
                    TempData["Success"] = "Saved Successfully";

                    ViewBag.AgentId   = new SelectList(db.Agents, "AgentId", "AgentName", studentdetail.AgentId);
                    ViewBag.CountryId = new SelectList(db.Countries, "CountryId", "Name", studentdetail.CountryId);
                }
                else
                {
                    return(RedirectToAction("Login", "Accounts"));
                }
            }
            return(RedirectToAction("Index"));
        }