示例#1
0
        public JsonResult SaveDoctorEntry(DoctorsEntryViewModel vModel, IEnumerable <HttpPostedFileBase> files)
        {
            string personImg       = "";
            int    operationStatus = -1;
            string ImgPaths        = Server.MapPath("~/Image/Doctors/");

            if (!Directory.Exists(ImgPaths))
            {
                Directory.CreateDirectory(ImgPaths);
            }
            DoctorsEntryModel model = new DoctorsEntryModel
            {
                DoctorsId          = Guid.NewGuid(),
                DoctorName         = vModel.DoctorName,
                DegreeOne          = vModel.DegreeOne,
                DegreeTwo          = vModel.DegreeTwo,
                DegreeThree        = vModel.DegreeThree,
                TrainingInstitute  = vModel.TrainingInstitute,
                TrainingPeriod     = vModel.TrainingPeriod,
                SpecialTraining    = vModel.TrainingPeriod,
                BMAMembershipNo    = vModel.BMAMembershipNo,
                BranceCode         = vModel.TrainingPeriod,
                MembershipCategory = vModel.MembershipCategory,
                BcsRegNo           = vModel.BcsRegNo,
                NID           = vModel.NID,
                Gender        = vModel.Gender,
                MaritalStatus = vModel.MaritalStatus,
                CreateDate    = now
            };

            if (files != null)
            {
                int i = 0;
                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         = "DImg" + model.NID + fileName + random + extension;
                    model.DoctorImage = personImg;
                    ImgPaths          = Path.Combine(Server.MapPath("~/Image/Doctors/"), personImg);
                    file.SaveAs(ImgPaths);
                    i++;
                }
            }
            try
            {
                db.DoctorsEntryModels.Add(model);
                db.SaveChanges();
                operationStatus = 1;
            }
            catch (Exception)
            {
                operationStatus = -1;
            }

            if (operationStatus == 1)
            {
                return(Json("Success", JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("Error", JsonRequestBehavior.AllowGet));
            }
        }
示例#2
0
        public JsonResult DoctorInfoUpdate(DoctorsEntryViewModel vModel, IEnumerable <HttpPostedFileBase> files)
        {
            string            doctorImg       = "";
            int               operationStatus = 1;
            string            ImagePath       = "";
            DoctorsEntryModel model           = db.DoctorsEntryModels.Find(vModel.DoctorsId);

            if (model.DoctorsId != null)
            {
                if (model.DoctorImage != null)
                {
                    doctorImg = Path.Combine(Server.MapPath("~/Image/Doctors/"), model.DoctorImage);
                }

                if (files != null)
                {
                    if (System.IO.File.Exists(doctorImg))
                    {
                        System.IO.File.Delete(doctorImg);
                    }

                    foreach (var file in files)
                    {
                        if (file != null)
                        {
                            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);

                            doctorImg         = "DocImg" + vModel.BMAMembershipNo + fileName + random + extension;
                            model.DoctorImage = doctorImg;
                            ImagePath         = Path.Combine(Server.MapPath("~/Image/Doctors/"), doctorImg);
                            file.SaveAs(ImagePath);
                        }
                    }
                }
                model.DoctorsId          = vModel.DoctorsId;
                model.DoctorName         = vModel.DoctorName;
                model.DegreeOne          = vModel.DegreeOne;
                model.DegreeTwo          = vModel.DegreeTwo;
                model.DegreeThree        = vModel.DegreeThree;
                model.TrainingInstitute  = vModel.TrainingInstitute;
                model.TrainingPeriod     = vModel.TrainingPeriod;
                model.SpecialTraining    = vModel.TrainingPeriod;
                model.BMAMembershipNo    = vModel.BMAMembershipNo;
                model.BranceCode         = vModel.TrainingPeriod;
                model.MembershipCategory = vModel.MembershipCategory;
                model.BcsRegNo           = vModel.BcsRegNo;
                model.NID             = vModel.NID;
                model.Gender          = vModel.Gender;
                model.MaritalStatus   = vModel.MaritalStatus;
                db.Entry(model).State = EntityState.Modified;
                try
                {
                    db.SaveChanges();
                    operationStatus = 1;
                }
                catch (Exception)
                {
                    operationStatus = -1;
                    throw;
                }
            }
            if (operationStatus == 1)
            {
                return(Json("Success", JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("Error", JsonRequestBehavior.AllowGet));
            }
        }