public ActionResult Edit([Bind(Include = "StudentAccount")] ViewStudentAccount objViewStudentAccount, FormCollection collection, HttpPostedFileBase image)
        {
            SMS.Models.MediaModels.Image objImage = new SMS.Models.MediaModels.Image();
            if (image != null)
            {
                ////attach the uploaded image to the object before saving to Database
                //objImage.ImageMimeType = image.ContentLength;
                objImage.ImageFile = new byte[image.ContentLength];
                image.InputStream.Read(objImage.ImageFile, 0, image.ContentLength);
                //Save image to file
                var    filename          = image.FileName;
                var    filePathOriginal  = Server.MapPath("/Data/Image");
                var    filePathThumbnail = Server.MapPath("/Data/Thumbnails");
                string savedFileName     = Path.Combine(filePathOriginal, filename);
                image.SaveAs(savedFileName);

                //Read image back from file and create thumbnail from it
                var imageFile = Path.Combine(Server.MapPath("~/Data/Image"), filename);
                using (var srcImage = System.Drawing.Image.FromFile(imageFile))
                    using (var newImage = new Bitmap(100, 100))
                        using (var graphics = Graphics.FromImage(newImage))
                            using (var stream = new MemoryStream())
                            {
                                graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                graphics.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                                graphics.DrawImage(srcImage, new Rectangle(0, 0, 200, 200));
                                newImage.Save(stream, ImageFormat.Png);
                                var thumbNew = File(stream.ToArray(), "image/png");
                                //artwork.ArtworkThumbnail = thumbNew.FileContents;
                            }

                SMS.Models.MediaModels.Image objImg = imagedb.Images.FirstOrDefault(p => p.TrackingId == objViewStudentAccount.StudentAccount.NidOrBirtgRegNo);
                if (objImg == null)
                {
                    objImage.TrackingId = objViewStudentAccount.StudentAccount.NidOrBirtgRegNo;
                    imagedb.Images.Add(objImage);
                    imagedb.SaveChanges();
                }
                else
                {
                    objImg.TrackingId           = objViewStudentAccount.StudentAccount.NidOrBirtgRegNo;
                    objImg.ImageFile            = objImage.ImageFile;
                    imagedb.Entry(objImg).State = EntityState.Modified;
                    imagedb.SaveChanges();
                }
            }

            if (ModelState.IsValid)
            {
                db.Entry(objViewStudentAccount.StudentAccount).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            objViewStudentAccount.StudentEducationalQualifications = db.StudentEducationalQualifications.Where(s => s.NidOrBirtgRegNo == objViewStudentAccount.StudentAccount.NidOrBirtgRegNo).ToList();
            objViewStudentAccount.Class = new SelectList(db.ClassOrYears, "Code", "Name", objViewStudentAccount.StudentAccount.ClassOrYearId);
            objViewStudentAccount.Group = new SelectList(db.Groups, "GroupCode", "Name", objViewStudentAccount.StudentAccount.GroupId);
            return(View(objViewStudentAccount));
        }
        // GET: StudentAccount/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ViewStudentAccount objViewStudentAccount = new ViewStudentAccount();

            objViewStudentAccount.StudentAccount = db.StudentAccounts.Find(id);
            // StudentAccount studentAccount = db.StudentAccounts.Find(id);
            if (objViewStudentAccount.StudentAccount == null)
            {
                return(HttpNotFound());
            }
            objViewStudentAccount.StudentEducationalQualifications = db.StudentEducationalQualifications.Where(s => s.NidOrBirtgRegNo == objViewStudentAccount.StudentAccount.NidOrBirtgRegNo).ToList();
            objViewStudentAccount.Class = new SelectList(db.ClassOrYears, "Code", "Name", objViewStudentAccount.StudentAccount.ClassOrYearId);
            objViewStudentAccount.Group = new SelectList(db.Groups, "GroupCode", "Name", objViewStudentAccount.StudentAccount.GroupId);
            return(View(objViewStudentAccount));
        }
        // GET: StudentAccount/Create
        public ActionResult Create()
        {
            ViewStudentAccount objStudentAccount = new ViewStudentAccount();

            objStudentAccount.Class = new SelectList(db.ClassOrYears, "Code", "Name");
            objStudentAccount.Group = new SelectList(db.Groups, "GroupCode", "Name");

            if (TempData["Student"] != null)
            {
                var stdudentData = (ApplicationUser)TempData["Student"];
                //  objStudentAccount = (ApplicationUser)TempData["Student"];
                objStudentAccount.AccountId   = stdudentData.Id;
                objStudentAccount.Nid         = stdudentData.NidOrBirthRegNo;
                objStudentAccount.FirstName   = stdudentData.FirstName;
                objStudentAccount.LastName    = stdudentData.LastName;
                objStudentAccount.Phone       = stdudentData.PhoneNumber;
                objStudentAccount.DateOfBirth = stdudentData.DateOfBirth;

                //objStudentAccount = stdudentData;
            }
            return(View(objStudentAccount));
        }
        public ActionResult Create([Bind(Include = "StudentAccount,Nid,FirstName,LastName,Phone,AccountId,DateOfBirth")]  ViewStudentAccount objStudentAccount, FormCollection collection, HttpPostedFileBase image)
        {
            SMS.Models.MediaModels.Image    objImage = new SMS.Models.MediaModels.Image();
            StudentEducationalQualification objStudentEducationalQualification = new StudentEducationalQualification();


            var exam      = collection["Exam"].Split(',');
            var institute = collection["Institute"].Split(',');
            var regNo     = collection["Registration"].Split(',');
            var rollNo    = collection["Roll"].Split(',');
            var group     = collection["Group"].Split(',');
            var year      = collection["Year"].Split(',');
            var grade     = collection["Grade"].Split(',');

            //var registration = collection["Registration"].Split(',');


            if (image != null)
            {
                ////attach the uploaded image to the object before saving to Database
                //objImage.ImageMimeType = image.ContentLength;
                objImage.ImageFile = new byte[image.ContentLength];
                image.InputStream.Read(objImage.ImageFile, 0, image.ContentLength);

                //Save image to file
                var    filename          = image.FileName;
                var    filePathOriginal  = Server.MapPath("/Data/Image");
                var    filePathThumbnail = Server.MapPath("/Data/Thumbnails");
                string savedFileName     = Path.Combine(filePathOriginal, filename);
                image.SaveAs(savedFileName);

                //Read image back from file and create thumbnail from it
                var imageFile = Path.Combine(Server.MapPath("~/Data/Image"), filename);
                using (var srcImage = System.Drawing.Image.FromFile(imageFile))
                    using (var newImage = new Bitmap(100, 100))
                        using (var graphics = Graphics.FromImage(newImage))
                            using (var stream = new MemoryStream())
                            {
                                graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                graphics.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                                graphics.DrawImage(srcImage, new Rectangle(0, 0, 200, 200));
                                newImage.Save(stream, ImageFormat.Png);
                                var thumbNew = File(stream.ToArray(), "image/png");
                                //artwork.ArtworkThumbnail = thumbNew.FileContents;
                            }

                objImage.TrackingId = objStudentAccount.Nid;
                //Save model object to database
                imagedb.Images.Add(objImage);
                imagedb.SaveChanges();
            }

            objStudentAccount.StudentAccount.NidOrBirtgRegNo = objStudentAccount.Nid;
            objStudentAccount.StudentAccount.AccountId       = objStudentAccount.AccountId;
            objStudentAccount.StudentAccount.FirstName       = objStudentAccount.FirstName;
            objStudentAccount.StudentAccount.LasttName       = objStudentAccount.LastName;
            objStudentAccount.StudentAccount.MobileNumber    = objStudentAccount.Phone;
            objStudentAccount.StudentAccount.DateOfBirth     = objStudentAccount.DateOfBirth;



            for (int i = 0; i < exam.Count(); i++)
            {
                if (exam[i] != "")
                {
                    objStudentEducationalQualification.NidOrBirtgRegNo = objStudentAccount.StudentAccount.NidOrBirtgRegNo;
                    objStudentEducationalQualification.ExamOrDegree    = exam[i];
                    objStudentEducationalQualification.RegNumber       = regNo[i];
                    objStudentEducationalQualification.RollNumber      = rollNo[i];
                    objStudentEducationalQualification.InstituteName   = institute[i];
                    objStudentEducationalQualification.PassingYear     = year[i];
                    objStudentEducationalQualification.Group           = group[i];
                    objStudentEducationalQualification.GpaOrDivison    = grade[i];
                    db.StudentEducationalQualifications.Add(objStudentEducationalQualification);
                    db.SaveChanges();
                }
            }
            if (ModelState.IsValid)
            {
                db.StudentAccounts.Add(objStudentAccount.StudentAccount);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            objStudentAccount.Class = new SelectList(db.ClassOrYears, "Code", "Name", objStudentAccount.StudentAccount.ClassOrYearId);
            objStudentAccount.Group = new SelectList(db.Groups, "GroupCode", "Name", objStudentAccount.StudentAccount.GroupId);
            return(View(objStudentAccount));
        }