public ActionResult Edit(int?id, DoctorEditViewModel viewModel, HttpPostedFileBase upload)
        {
            Doctor doctorToUpdate = db.Doctors
                                    .Include(d => d.Image)
                                    .SingleOrDefault(d => d.ID == id);

            viewModel.Image.ID = doctorToUpdate.ImageID;
            var validImageTypes = new string[]
            {
                "image/gif",
                "image/jpeg",
                "image/png"
            };

            FileManipulation editImage = new FileManipulation();

            if (ModelState.IsValid)
            {
                if (viewModel.Image.ImgUpload != null && viewModel.Image.ImgUpload.ContentLength > 0)
                {
                    if (!validImageTypes.Contains(viewModel.Image.ImgUpload.ContentType))
                    {
                        ModelState.AddModelError("ImgUpload", "Please, choose either GIF, JPG, or PNG type of files.");
                    }
                    if (viewModel.Image.ID == 1)
                    {
                        File image = new File
                        {
                            ContentType = viewModel.Image.ImgUpload.ContentType
                        };
                        editImage.FileUpload(image, viewModel.Image.ImgUpload);
                        //call for upload with file-system:
                        //EditImageUpload(viewModel.Image.ID, doctorToUpdate, image, viewModel);
                        db.Files.Add(image);
                        doctorToUpdate.Image = image;
                    }
                    else
                    {
                        File image = db.Files.Single(i => i.ID == doctorToUpdate.ImageID);

                        editImage.FileUpload(image, viewModel.Image.ImgUpload);
                    }
                }
                doctorToUpdate.FirstName   = viewModel.Doctor.FirstName;
                doctorToUpdate.LastName    = viewModel.Doctor.LastName;
                doctorToUpdate.Address     = viewModel.Doctor.Address;
                doctorToUpdate.PhoneNumber = viewModel.Doctor.PhoneNumber;
                doctorToUpdate.Email       = viewModel.Doctor.Email;
                doctorToUpdate.Position    = viewModel.Doctor.Position;

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(viewModel));
        }
Example #2
0
        public ActionResult Edit(int?id, ExaminationCRUViewModel viewModel)
        {
            Examination examToUpdate = db.Examinations
                                       .Include(e => e.Doctor)
                                       .Include(e => e.Patient)
                                       .Include(e => e.Files)
                                       .SingleOrDefault(e => e.ID == id);
            FileManipulation editFile = new FileManipulation();
            List <File>      files    = new List <File>();

            if (ModelState.IsValid)
            {
                //if (viewModel.File.FileUpload != null)
                //{
                editFile.FileUpload(files, viewModel.File.MultipleFileUpload);
                foreach (File file in files)
                {
                    db.Files.Add(file);
                }
                examToUpdate.Files = files;
                //}
                //examToUpdate = examTranslator.ToExaminationDataModel(viewModel, files);
                examToUpdate.DateOfVisit  = viewModel.ExamDate;
                examToUpdate.DiagnoseCode = viewModel.Diagnose;
                examToUpdate.LabResults   = viewModel.LabResult;
                examToUpdate.ExamResults  = viewModel.ExamResult;
                examToUpdate.DoctorID     = viewModel.SelectedDoctorID;
                examToUpdate.PatientID    = viewModel.SelectedPatientID;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            viewModel.ExamDoctorID = new SelectList(db.Doctors, "ID", "FullName", examToUpdate.DoctorID);
            viewModel.PatientID    = new SelectList(db.Patients, "ID", "FullName", examToUpdate.PatientID);
            return(View(viewModel));
        }
Example #3
0
        public ActionResult Create(ExaminationCRUViewModel viewModel)
        {
            //var file = new file
            //{
            //    id = viewmodel.examfile.id,
            //    contenttype = viewmodel.examfile.fileupload.contenttype
            //};
            ExaminationTranslator examTranslator = new ExaminationTranslator();
            List <File>           files          = new List <File>();
            Examination           exam           = examTranslator.ToExaminationDataModel(viewModel, files);

            viewModel.ExamDoctorID = new SelectList(db.Doctors, "ID", "FullName", exam.DoctorID);
            viewModel.PatientID    = new SelectList(db.Patients, "ID", "FullName", exam.PatientID);
            if (ModelState.IsValid)
            {
                FileManipulation fileUploader = new FileManipulation();

                fileUploader.FileUpload(files, viewModel.File.MultipleFileUpload);
                foreach (File file in files)
                {
                    db.Files.Add(file);
                }
                exam.Files = files;

                exam.DoctorID  = viewModel.SelectedDoctorID;
                exam.PatientID = viewModel.SelectedPatientID;

                db.Examinations.Add(exam);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(viewModel));
        }
        public ActionResult Create(DoctorCreateViewModel viewModel)
        {
            var validImageTypes = new string[]
            {
                "image/gif",
                "image/jpeg",
                "image/png"
            };

            if (ModelState.IsValid)
            {
                var image = new File
                {
                    ID          = viewModel.Image.ID,
                    ContentType = viewModel.Image.ImgUpload.ContentType
                };
                DoctorTranslator doctorDataTranslator = new DoctorTranslator();
                Doctor           doctor            = doctorDataTranslator.ToDoctorDataModel(viewModel, image);
                FileManipulation imageUploadHelper = new FileManipulation();

                if (viewModel.Image.ImgUpload != null && viewModel.Image.ImgUpload.ContentLength > 0)
                {
                    if (!validImageTypes.Contains(viewModel.Image.ImgUpload.ContentType))
                    {
                        ModelState.AddModelError("ImgUpload", "Please, choose either GIF, JPG, or PNG type of files.");
                    }
                    //upload with file-system, make sure that folder Uploads in DoctorsOffice exist
                    //var imgFileName = Guid.NewGuid().ToString() + GetExtension(viewModel.Image.ImgUpload.ContentType);
                    //var uploadDir = "~/Uploads";
                    //var imagePath = System.IO.Path.Combine(Server.MapPath(uploadDir), imgFileName);
                    //var imageUrl = System.IO.Path.Combine(uploadDir, imgFileName);
                    //viewModel.Image.ImgUpload.SaveAs(imagePath);

                    imageUploadHelper.FileUpload(image, viewModel.Image.ImgUpload);
                    //imageUploadHelper.ResizeImage(viewModel.Image.ImgUpload);-don't work yet!!!
                    //db.Files.Add(image);
                }
                else
                {
                    imageUploadHelper.DefaultImage(doctor);
                }

                db.Doctors.Add(doctor);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(viewModel));
        }