コード例 #1
0
        public ActionResult SaveNewDoctor([Bind(Exclude = "DoctorPhoto")] Doctor doctor)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new NewDoctorViewModel
                {
                    Doctor      = doctor,
                    Cities      = _context.Cities.ToList(),
                    Specialties = _context.Specialties.ToList()
                };

                return(View("NewDoctor", viewModel));
            }

            string saveMessage = "";

            if (doctor.Id == 0)
            {
                _context.Doctors.Add(doctor);
                saveMessage = "Добавихте нов запис в таблицата!";
            }
            else
            {
                var doctorInDb = _context.Doctors.Single(c => c.Id == doctor.Id);

                doctorInDb.FullName            = doctor.FullName;
                doctorInDb.CityId              = doctor.CityId;
                doctorInDb.AddressLine         = doctor.AddressLine;
                doctorInDb.SpecialtyId         = doctor.SpecialtyId;
                doctorInDb.WorksWithNHIF       = doctor.WorksWithNHIF;
                doctorInDb.DoctorInfo          = doctor.DoctorInfo;
                doctorInDb.WorktimeStart       = doctor.WorktimeStart;
                doctorInDb.WorktimeEnd         = doctor.WorktimeEnd;
                doctorInDb.PriceForExamination = doctor.PriceForExamination;

                // To convert the doctor uploaded Photo as Byte Array before save to DB
                byte[] imageData = null;
                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase poImgFile = Request.Files["DoctorPhoto"];

                    using (var binary = new BinaryReader(poImgFile.InputStream))
                    {
                        imageData = binary.ReadBytes(poImgFile.ContentLength);
                    }
                }

                doctorInDb.DoctorPhoto = imageData;

                saveMessage = "Успешно направени промени!";
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Doctors", new { message = saveMessage }));
        }
コード例 #2
0
        public ActionResult Edit(int id)
        {
            var viewModel = new NewDoctorViewModel
            {
                Doctor      = _context.Doctors.SingleOrDefault(d => d.Id == id),
                DoctorTypes = _context.DoctorTypes.ToList()
            };

            return(View("NewDoctor", viewModel));
        }
コード例 #3
0
        public ActionResult NewDoctor()
        {
            var viewModel = new NewDoctorViewModel
            {
                Doctor      = new Doctor(),
                DoctorTypes = _context.DoctorTypes.ToList()
            };


            return(View(viewModel));
        }
コード例 #4
0
        public ActionResult NewDoctor()
        {
            var cities      = _context.Cities.ToList();
            var specialties = _context.Specialties.ToList();

            var viewModel = new NewDoctorViewModel
            {
                Doctor      = new Doctor(),
                Cities      = cities,
                Specialties = specialties
            };

            return(View(viewModel));
        }
コード例 #5
0
        public ActionResult CreateDoctor(NewDoctorViewModel model)
        {
            var newDoctor = new Doctor();

            newDoctor.Nume      = model.Nume;
            newDoctor.Prenume   = model.Prenume;
            newDoctor.Email     = model.Email;
            newDoctor.Telefon   = model.Telefon;
            newDoctor.CodParafa = model.CodParafa;
            newDoctor.Cabinet   = model.Cabinet;
            newDoctor.Parola    = model.Parola;

            DoctorServices.ClassObject.SaveDoctor(newDoctor);

            return(RedirectToAction("DoctorsTable"));
        }
コード例 #6
0
        public ActionResult EditDoctor(int id)
        {
            var doctor = _context.Doctors.Include(c => c.Specialty).Include(c => c.City).SingleOrDefault(c => c.Id == id);

            if (doctor == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new NewDoctorViewModel
            {
                Doctor      = doctor,
                Cities      = _context.Cities.ToList(),
                Specialties = _context.Specialties.ToList()
            };

            if (User.IsInRole(RoleName.CanManageDoctors))
            {
                return(View("NewDoctor", viewModel));
            }
            ;

            string userId = User.Identity.GetUserId();

            if (userId == null)
            {
                return(HttpNotFound());
            }

            // get the current user
            var currentUser = _context.Users.Where(x => x.Id == userId).FirstOrDefault();

            var isSecuredByNHIF = currentUser.IsSecuredByNHIF;

            ViewBag.isSecured = isSecuredByNHIF;
            return(View("ReadOnlyDoctor", viewModel));
        }
コード例 #7
0
        public ActionResult SaveDoctor(Doctor doctor, string massage)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new NewDoctorViewModel
                {
                    Doctor      = doctor,
                    DoctorTypes = _context.DoctorTypes.ToList()
                };

                return(View("NewDoctor", viewModel));
            }

            if (doctor.Id == 0)
            {
                if (User.IsInRole(UserRoles.CanApproveAndDeleteRecord))
                {
                    doctor.IsApproved = true;
                    _context.Doctors.Add(doctor);
                }
                else
                {
                    doctor.IsApproved = false;
                    _context.Doctors.Add(doctor);
                }
            }
            else
            {
                var doctorInDB = _context.Doctors.SingleOrDefault(d => d.Id == doctor.Id);

                Mapper.Map(doctor, doctorInDB);
            }

            _context.SaveChanges();
            return(RedirectToAction("Index", new { massage = massage }));
        }
コード例 #8
0
 public NewDoctorPage()
 {
     InitializeComponent();
     BindingContext = new NewDoctorViewModel();
 }