public async Task <IActionResult> Create([Bind("AdId,StId,StdId,FTId,FeeYear,PaidAmount,Totalfees,Pendingamt")] Admission1 admission1)

        {
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("Session1")))
            {
                return(RedirectToAction("UserLogin", "Login"));
            }
            if (ModelState.IsValid)
            {
                //if(ViewBag.StId1 != null && admission1.StId==null)
                //{
                //    admission1.StdId=
                //}
                _context.Add(admission1);
                await _context.SaveChangesAsync();

                var routeValues = new RouteValueDictionary {
                    { "ID", admission1.AdId }
                };
                return(RedirectToAction("AdmissionPay", "Admission", routeValues));
                //   return RedirectToAction(nameof(Index));
            }

            ViewData["FTId"]  = new SelectList(_context.FeeType, "FTId", "Feetype1");
            ViewData["StId"]  = new SelectList(_context.Student, "StId", "StName", admission1.StId);
            ViewData["StdId"] = new SelectList(_context.Std, "StdId", "Stname", admission1.StdId);
            return(View(admission1));
        }
        public IActionResult selectstudent(ListModel listModel)
        {
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("Session1")))
            {
                return(RedirectToAction("UserLogin", "Login"));
            }
            Admission1 admission = _context.Admission1.Find(listModel.AdId);
            Student    student   = _context.Student.Find(admission.StId);

            listModel.EnrollModel = new EnrollModel()
            {
                AdId = admission.AdId, StId = student.StId, POB = student.POB, StName = student.StName, Dob = student.Dob, EmailId = student.EmailId, Gender = student.Gender, MotherName = student.MotherName, MotherOccu = student.MotherOccu, MotherPhone = student.MotherPhone, MotherQualification = student.MotherQualification, MotherWhatsapp = student.MotherWhatsapp, Nationality = student.Nationality, Occupation = student.Occupation, ParentMobile = student.ParentMobile, ParentName = student.ParentName, ParentWhatsappNo = student.ParentWhatsappNo, Qualification = student.Qualification, Address = student.Address, Pic = student.Id
            };
            ViewBag.enrolldata = listModel.EnrollModel;
            ViewBag.display    = "div2";
            ViewBag.studentdiv = "div3";
            List <EnrollModel> list = Fill_Adlist(student.StName);

            listModel.UserSearch = new UserSearch()
            {
                St_Name = student.StName
            };
            listModel.EnrollModels = list;

            fillinitialdata();

            return(View("Indexdemo", listModel));
        }
        public IActionResult Index(int?id, string name)
        {
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("Session1")))
            {
                return(RedirectToAction("UserLogin", "Login"));
            }
            if (id.HasValue)
            {
                var res = _context.Admission1.Include(k => k.Std).Include(n => n.Admissiopay).Include(n => n.FT).ToList <Models.Admission1>();
                res = res.Where(d => d.AdId == id).ToList <Admission1>();
                Admission1 admissiopay = res.First();

                return(View(admissiopay));
            }

            return(View());
        }
        public async Task <IActionResult> Edit(int id, [Bind("AdId,StId,StdId,FTId,FeeYear,PaidAmount,Totalfees,Pendingamt")] Admission1 admission1)
        {
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("Session1")))
            {
                return(RedirectToAction("UserLogin", "Login"));
            }
            if (id != admission1.AdId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var res = _context.Admissiopay.Where(k => k.AdId == admission1.AdId);
                    _context.Admissiopay.RemoveRange(res);

                    _context.Update(admission1);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Admission1Exists(admission1.AdId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FTId"]  = new SelectList(_context.FeeType, "FTId", "Feetype1", admission1.FTId);
            ViewData["StId"]  = new SelectList(_context.Student, "StId", "StName", admission1.StId);
            ViewData["StdId"] = new SelectList(_context.Std, "StdId", "Stname", admission1.StdId);
            return(View(admission1));
        }
        public IActionResult selectadmission(ListModel listModel, string id)
        {
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("Session1")))
            {
                return(RedirectToAction("UserLogin", "Login"));
            }

            Admission1 admission = _context.Admission1.Find(listModel.AdId);
            Student    student   = _context.Student.Find(admission.StId);
            var        res       = _context.Admissiopay.Where(d => d.AdId == admission.AdId);

            listModel.EnrollModel = new EnrollModel()
            {
                StdId = admission.StdId, FTId = admission.FTId, FeeYear = admission.FeeYear, AdId = admission.AdId, StId = student.StId, POB = student.POB, StName = student.StName, Dob = student.Dob, EmailId = student.EmailId, Gender = student.Gender, MotherName = student.MotherName, MotherOccu = student.MotherOccu, MotherPhone = student.MotherPhone, MotherQualification = student.MotherQualification, MotherWhatsapp = student.MotherWhatsapp, Nationality = student.Nationality, Occupation = student.Occupation, ParentMobile = student.ParentMobile, ParentName = student.ParentName, ParentWhatsappNo = student.ParentWhatsappNo, Qualification = student.Qualification, Address = student.Address
            };
            listModel.EnrollModel.paystatusid = "";
            foreach (var item in res)
            {
                if (item.Paystatus == true)
                {
                    listModel.EnrollModel.paystatusid += item.AdTId + "." + item.PayDate;
                    if (item.Pay_mode == "Cash")
                    {
                        listModel.EnrollModel.paystatusid += ".1";
                    }
                    else if (item.Pay_mode == "Cheque")
                    {
                        listModel.EnrollModel.paystatusid += ".2";
                        listModel.EnrollModel.paystatusid += "." + item.Chequeno;
                        listModel.EnrollModel.paystatusid += "." + item.Chequedt.ToString();
                        listModel.EnrollModel.paystatusid += "." + item.BankName;
                        listModel.EnrollModel.paystatusid += "." + item.BankBranch;
                    }
                    else if (item.Pay_mode == "netbanking")
                    {
                        listModel.EnrollModel.paystatusid += ".3";
                        listModel.EnrollModel.paystatusid += "." + item.Transactionno;
                    }
                    listModel.EnrollModel.paystatusid += ",";
                }
            }


            ViewBag.enrolldata = listModel.EnrollModel;
            ViewBag.display    = "div2";
            ViewBag.studentdiv = "div3";
            List <EnrollModel> list = Fill_Adlist(student.StName);

            listModel.UserSearch = new UserSearch()
            {
                St_Name = student.StName
            };
            listModel.EnrollModels = list;

            fillinitialdata();
            if (id == "update")
            {
                return(View("UpdateStudent", listModel));
            }
            else
            {
                return(View("FeePay", listModel));
            }
        }
        public async Task <IActionResult> Create(ListModel data, string ctrl)
        {
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("Session1")))
            {
                return(RedirectToAction("UserLogin", "Login"));
            }
            if (ModelState.IsValid)
            {
                using (var transaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        Student student;
                        if (data.EnrollModel.StId.HasValue)
                        {
                            if (data.EnrollModel.files != null)
                            {
                                IFormFile    uploadedImage = null;
                                MemoryStream ms            = null;
                                uploadedImage = data.EnrollModel.files;
                                System.Drawing.Image image = null;
                                if (uploadedImage != null || uploadedImage.ContentType.ToLower().StartsWith("image/"))
                                {
                                    ms = new MemoryStream();
                                    uploadedImage.OpenReadStream().CopyTo(ms);

                                    image = System.Drawing.Image.FromStream(ms);
                                }

                                data.ctrl1                  = 1;
                                ViewBag.display             = "div2";
                                student                     = _context.Student.Find(data.EnrollModel.StId);
                                student.Dob                 = data.EnrollModel.Dob;
                                student.EmailId             = data.EnrollModel.EmailId;
                                student.Gender              = data.EnrollModel.Gender;
                                student.MotherName          = data.EnrollModel.MotherName;
                                student.MotherOccu          = data.EnrollModel.MotherOccu;
                                student.MotherPhone         = data.EnrollModel.MotherPhone;
                                student.MotherQualification = data.EnrollModel.MotherQualification;
                                student.MotherWhatsapp      = data.EnrollModel.MotherWhatsapp;
                                student.Nationality         = data.EnrollModel.Nationality;
                                student.Occupation          = data.EnrollModel.Occupation;
                                student.ParentMobile        = data.EnrollModel.ParentMobile;
                                student.ParentName          = data.EnrollModel.ParentName;
                                student.ParentWhatsappNo    = data.EnrollModel.ParentWhatsappNo;
                                student.POB                 = data.EnrollModel.POB;
                                student.Qualification       = data.EnrollModel.Qualification;
                                student.StId                = data.EnrollModel.StId.Value;
                                student.StName              = data.EnrollModel.StName;
                                student.Address             = data.EnrollModel.Address;
                                if (uploadedImage != null)
                                {
                                    student.Id          = Guid.NewGuid();
                                    student.Name        = uploadedImage.FileName;
                                    student.Data        = ms.ToArray();
                                    student.Width       = image.Width;
                                    student.Height      = image.Height;
                                    student.ContentType = uploadedImage.ContentType;
                                }
                                _context.Entry(student).State = EntityState.Modified;
                                _context.SaveChanges();
                            }
                        }
                        else
                        {
                            data.ctrl1      = 0;
                            ViewBag.display = "div1";
                            IFormFile uploadedImage = data.EnrollModel.files;
                            if (uploadedImage != null || uploadedImage.ContentType.ToLower().StartsWith("image/"))
                            {
                                MemoryStream ms = new MemoryStream();
                                uploadedImage.OpenReadStream().CopyTo(ms);

                                System.Drawing.Image image = System.Drawing.Image.FromStream(ms);


                                // fillinitialdata();
                                student = new Student()
                                {
                                    StName              = data.EnrollModel.StName,
                                    ParentName          = data.EnrollModel.ParentName,
                                    Dob                 = data.EnrollModel.Dob,
                                    EmailId             = data.EnrollModel.EmailId,
                                    ParentMobile        = data.EnrollModel.ParentMobile,
                                    Gender              = data.EnrollModel.Gender,
                                    MotherName          = data.EnrollModel.MotherName,
                                    MotherOccu          = data.EnrollModel.MotherOccu,
                                    MotherPhone         = data.EnrollModel.MotherPhone,
                                    MotherQualification = data.EnrollModel.MotherQualification,
                                    MotherWhatsapp      = data.EnrollModel.MotherWhatsapp,
                                    Nationality         = data.EnrollModel.Nationality,
                                    Occupation          = data.EnrollModel.Occupation,
                                    ParentWhatsappNo    = data.EnrollModel.ParentWhatsappNo,
                                    POB                 = data.EnrollModel.POB,
                                    Qualification       = data.EnrollModel.Qualification,
                                    Address             = data.EnrollModel.Address,
                                    Id          = Guid.NewGuid(),
                                    Name        = uploadedImage.FileName,
                                    Data        = ms.ToArray(),
                                    Width       = image.Width,
                                    Height      = image.Height,
                                    ContentType = uploadedImage.ContentType
                                };
                                _context.Student.Add(student);
                                _context.SaveChanges();
                                data.EnrollModel.StId = student.StId;
                            }
                        }
                        Admission1 admission = new Admission1()
                        {
                            StId = data.EnrollModel.StId, StdId = data.EnrollModel.StdId,
                            FTId = data.EnrollModel.FTId, FeeYear = data.EnrollModel.FeeYear
                        };
                        _context.Admission1.Add(admission);
                        _context.SaveChanges();
                        data.AdId = admission.AdId;
                        data.EnrollModel.paystatusid = data.EnrollModel.paystatusid.Remove(data.EnrollModel.paystatusid.Length - 1, 1);
                        string[] paidid = data.EnrollModel.paystatusid.Split(",");
                        //var res= _context.Admissiopay.Where(p => p.AdId == admission.AdId);
                        // foreach (var item in res)
                        // {
                        foreach (var item1 in paidid)
                        {
                            string[] modes = item1.Split(".");
                            var      res   = _context.Admissiopay.Find(admission.AdId, Convert.ToInt32(modes[0]));
                            res.Paystatus = true;
                            res.PayDate   = Convert.ToDateTime(modes[1]);
                            if (modes[2].ToString() == "1")
                            {
                                res.Pay_mode = "Cash";
                            }
                            else if (modes[2].ToString() == "2")
                            {
                                res.Pay_mode   = "Cheque";
                                res.Chequeno   = modes[3].ToString();
                                res.Chequedt   = Convert.ToDateTime(modes[4]);
                                res.BankName   = modes[5].ToString();
                                res.BankBranch = modes[6].ToString();
                            }
                            else if (modes[2].ToString() == "3")
                            {
                                res.Pay_mode      = "netbanking";
                                res.Transactionno = modes[3].ToString();
                            }
                            _context.SaveChanges();
                        }
                        transaction.Commit();
                        // TempData["emodel"] = data;
                        ViewBag.display = "div4";
                        ViewBag.ADID    = data.AdId;

                        return(View("Indexdemo", data));
                        //return RedirectToAction("printreceiptdemo", "Admission", new { ID1 = data.AdId});
                    }
                    catch (SqlException e)
                    {
                        transaction.Rollback();
                        fillinitialdata();

                        return(View("Indexdemo", data));
                    }
                    catch (Exception e1)
                    {
                        fillinitialdata();

                        return(View("Indexdemo", data));
                    }
                }
            }
            else
            {
                if (data.EnrollModel.StId.HasValue)
                {
                    List <EnrollModel> list = Fill_Adlist(data.EnrollModel.StName);
                    data.AdId       = data.EnrollModel.AdId.Value;
                    data.UserSearch = new UserSearch()
                    {
                        St_Name = data.EnrollModel.StName
                    };
                    data.EnrollModels = list;
                    fillinitialdata();
                    data.ctrl1 = 1;
                    var res1 = _context.FeeType.Where(d => d.FTId == data.EnrollModel.FTId);
                    ViewData["FTId"]   = new SelectList(res1, "FTId", "Feetype1");
                    ViewBag.display    = "div2";
                    ViewBag.studentdiv = "div3";
                    //  return View("Indexdemo", data);
                }
                else
                {
                    data.ctrl1      = 0;
                    ViewBag.display = "div1";
                    var res1 = _context.FeeType.Where(d => d.FTId == data.EnrollModel.FTId);
                    ViewData["FTId"] = new SelectList(res1, "FTId", "Feetype1");
                    fillinitialdata();
                }

                ViewBag.domdata = data.EnrollModel.divdata;
                return(View("Indexdemo", data));
            }
        }