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));
            }
        }
 public void Update(T entity)
 {
     context.Entry(entity).State = EntityState.Modified;
     context.SaveChanges();
 }