// GET: SSI/Edit/5
        public ActionResult Edit(Guid?id)
        {
            SSIViewModel model = new SSIViewModel();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SSIModel sSIModel = db.SSIModels.Find(id);

            if (sSIModel.SSIId != null)
            {
                model = new SSIViewModel
                {
                    SSIId             = sSIModel.SSIId,
                    FirstName         = sSIModel.FirstName,
                    MiddleName        = sSIModel.MiddleName,
                    LastName          = sSIModel.LastName,
                    BirthFirstName    = sSIModel.BirthFirstName,
                    BirthMiddleName   = sSIModel.BirthMiddleName,
                    BirthLastName     = sSIModel.BirthLastName,
                    ThanaCode         = sSIModel.ThanaCode,
                    PostalCode        = sSIModel.PostalCode,
                    NidLastdigit      = sSIModel.NidLastdigit,
                    PlaceOfBirth      = sSIModel.PlaceOfBirth,
                    City              = sSIModel.City,
                    Thana             = sSIModel.Thana,
                    DateOfBirth       = sSIModel.DateOfBirth,
                    CitizenShip       = sSIModel.CitizenShip,
                    Ethnicity         = sSIModel.Ethnicity,
                    Race              = sSIModel.Race,
                    ParentsFirstName  = sSIModel.ParentsFirstName,
                    ParentsMiddleName = sSIModel.ParentsMiddleName,
                    ParentsLastName   = sSIModel.ParentsLastName,
                    ParentsSSINo      = sSIModel.ParentsSSINo,
                    PhoneNumber       = sSIModel.PhoneNumber,
                    MailingAddress    = sSIModel.MailingAddress,
                    NID         = sSIModel.NID,
                    PersonImage = sSIModel.PersonImage,
                    PassportNo  = sSIModel.PassportNo,
                    Gender      = sSIModel.Gender,
                    Division    = sSIModel.Division,
                    Address     = sSIModel.Address
                };
            }
            ViewBag.CitizenCategory   = db.CitizenShipModels.ToList();
            ViewBag.EthnicityCategory = db.EthnicityModels.ToList();
            ViewBag.RaceCategory      = db.RaceModels.ToList();
            ViewBag.GenderCategory    = db.SexModels.ToList();

            if (sSIModel == null)
            {
                return(HttpNotFound());
            }
            return(View(model));
        }
        public JsonResult SSIEntrySave(SSIViewModel sSIModel, IEnumerable <HttpPostedFileBase> files)
        {
            string personImg       = "";
            int    operationStatus = 1;
            string ImagePath       = Server.MapPath("~/Image/SSI/");

            if (!Directory.Exists(ImagePath))
            {
                Directory.CreateDirectory(ImagePath);
            }
            SSIModel model = new SSIModel
            {
                SSIId             = Guid.NewGuid(),
                FirstName         = sSIModel.FirstName,
                MiddleName        = sSIModel.MiddleName,
                LastName          = sSIModel.LastName,
                BirthFirstName    = sSIModel.BirthFirstName,
                BirthMiddleName   = sSIModel.BirthMiddleName,
                BirthLastName     = sSIModel.BirthLastName,
                ThanaCode         = sSIModel.ThanaCode,
                PostalCode        = sSIModel.PostalCode,
                NidLastdigit      = sSIModel.NidLastdigit,
                PlaceOfBirth      = sSIModel.PlaceOfBirth,
                City              = sSIModel.City,
                Thana             = sSIModel.Thana,
                DateOfBirth       = sSIModel.DateOfBirth,
                CitizenShip       = sSIModel.CitizenShip,
                Ethnicity         = sSIModel.Ethnicity,
                Race              = sSIModel.Race,
                ParentsFirstName  = sSIModel.ParentsFirstName,
                ParentsMiddleName = sSIModel.ParentsMiddleName,
                ParentsLastName   = sSIModel.ParentsLastName,
                ParentsSSINo      = sSIModel.ParentsSSINo,
                PhoneNumber       = sSIModel.PhoneNumber,
                MailingAddress    = sSIModel.MailingAddress,
                NID        = sSIModel.NID,
                PassportNo = sSIModel.PassportNo,
                Gender     = sSIModel.Gender,
                Division   = sSIModel.Division,
                Address    = sSIModel.Address,
                CreateDate = now
            };

            if (files != null)
            {
                foreach (var file in files)
                {
                    Random generator = new Random();
                    string random    = generator.Next(0, 900000).ToString("D6");
                    string s         = file.FileName;
                    int    idx       = s.LastIndexOf('.');
                    string fileName  = s.Substring(0, idx);
                    string extension = s.Substring(idx);
                    personImg         = "SSIImg" + sSIModel.NID + fileName + random + extension;
                    model.PersonImage = personImg;
                    ImagePath         = Path.Combine(Server.MapPath("~/Image/SSI/PersonImage/"), personImg);
                    file.SaveAs(ImagePath);
                }
            }
            try
            {
                db.SSIModels.Add(model);
                db.SaveChanges();
            }
            catch (Exception)
            {
                operationStatus = -1;
                throw;
            }

            if (operationStatus == 1)
            {
                return(Json("Success", JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("Error", JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult SSIEntryUpdate(SSIViewModel sSIModel, IEnumerable <HttpPostedFileBase> files)
        {
            string   personImg       = "";
            string   ImgPath         = "";
            int      operationStatus = 1;
            SSIModel model           = db.SSIModels.Find(sSIModel.SSIId);

            if (model.SSIId != null)
            {
                if (files != null)
                {
                    personImg = Path.Combine(Server.MapPath("~/Image/SSI/PersonImage/"), model.PersonImage);
                    if (System.IO.File.Exists(personImg))
                    {
                        System.IO.File.Delete(personImg);
                    }
                    foreach (var file in files)
                    {
                        Random generator = new Random();
                        string random    = generator.Next(0, 900000).ToString("D6");
                        string s         = file.FileName;
                        int    idx       = s.LastIndexOf('.');
                        string fileName  = s.Substring(0, idx);
                        string extension = s.Substring(idx);
                        personImg         = "SSIImg" + sSIModel.NID + fileName + random + extension;
                        model.PersonImage = personImg;
                        ImgPath           = Path.Combine(Server.MapPath("~/Image/SSI/PersonImage/"), personImg);
                        file.SaveAs(ImgPath);
                    }
                }
                model.SSIId             = sSIModel.SSIId;
                model.FirstName         = sSIModel.FirstName;
                model.MiddleName        = sSIModel.MiddleName;
                model.LastName          = sSIModel.LastName;
                model.BirthFirstName    = sSIModel.BirthFirstName;
                model.BirthMiddleName   = sSIModel.BirthMiddleName;
                model.BirthLastName     = sSIModel.BirthLastName;
                model.ThanaCode         = sSIModel.ThanaCode;
                model.PostalCode        = sSIModel.PostalCode;
                model.NidLastdigit      = sSIModel.NidLastdigit;
                model.PlaceOfBirth      = sSIModel.PlaceOfBirth;
                model.City              = sSIModel.City;
                model.Thana             = sSIModel.Thana;
                model.DateOfBirth       = sSIModel.DateOfBirth;
                model.CitizenShip       = sSIModel.CitizenShip;
                model.Ethnicity         = sSIModel.Ethnicity;
                model.Race              = sSIModel.Race;
                model.ParentsFirstName  = sSIModel.ParentsFirstName;
                model.ParentsMiddleName = sSIModel.ParentsMiddleName;
                model.ParentsLastName   = sSIModel.ParentsLastName;
                model.ParentsSSINo      = sSIModel.ParentsSSINo;
                model.PhoneNumber       = sSIModel.PhoneNumber;
                model.MailingAddress    = sSIModel.MailingAddress;
                model.NID             = sSIModel.NID;
                model.PassportNo      = sSIModel.PassportNo;
                model.Gender          = sSIModel.Gender;
                model.Division        = sSIModel.Division;
                model.Address         = sSIModel.Address;
                db.Entry(model).State = EntityState.Modified;
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception)
            {
                operationStatus = -1;
                throw;
            }

            if (operationStatus == 1)
            {
                return(Json("Success", JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("Error", JsonRequestBehavior.AllowGet));
            }
        }