Example #1
0
        public ActionResult Create(ImageCreateViewModel imageCreateViewModel, FormCollection form)
        {
            if (ModelState.IsValid)
            {
                if (imageCreateViewModel.File != null)
                {
                    var image = new Image();
                    var now   = DateTime.Now;

                    var filename = now.ToString("yyyy-MM-dd-HH-mm-ss") + "-" + Guid.NewGuid() +
                                   Path.GetExtension(imageCreateViewModel.File.FileName);

                    image.Description = imageCreateViewModel.Description;
                    image.UpdateDate  = now;
                    image.InsertDate  = now;
                    image.Path        = filename;
                    image.Name        = imageCreateViewModel.File.FileName;

                    var path = Path.Combine(Server.MapPath(@"~\Content\Images"), filename);
                    imageCreateViewModel.File.SaveAs(path);

                    _imageRepository.Insert(image);
                    _unitOfWork.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }
            return(View(imageCreateViewModel));
        }
Example #2
0
        public IActionResult Upload(ImageCreateViewModel image)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.RedirectToAction("Upload"));
            }

            this.imageService.Create(this.userManager.GetUserId(this.User), image.Title, image.Category, image.Image);
            return(this.RedirectToAction("Index", "Home"));
        }
Example #3
0
        public ActionResult Create(int pageId, int?id)
        {
            var image = id.HasValue ? _service.GetImages().Single(i => i.Id == id.Value) : new Image {
            };
            var model = new ImageCreateViewModel {
                Image = image
            };

            model.NavigationModel = HomeIndexViewModelLoader.Create(pageId, _service);
            return(View(model));
        }
Example #4
0
        public IActionResult Upload()
        {
            var image = new ImageCreateViewModel
            {
                Categories = this.categoryService.GetAll().Select(c => new SelectListItem
                {
                    Text  = c.Name,
                    Value = c.Id.ToString()
                })
            };

            return(this.View(image));
        }
Example #5
0
        public ActionResult PatientImagesCreate(ImagesViewModel imagesViewModel, string name, IEnumerable <HttpPostedFileBase> files, FormCollection coll)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (files != null)
                    {
                        List <HttpPostedFileBase> list = files.ToList();
                        if (list[0] != null)
                        {
                            imagesViewModel.PatientID = getCurrentPatientID();

                            string imageCategoryName = imageRepository.getIMageCategoryNameByID(imagesViewModel.ImageCategoryID);

                            ImagesDrawing ob = new ImagesDrawing();
                            ob.PatientImageSaver(System.Drawing.Image.FromStream(list[0].InputStream), Server.MapPath(@"~/Content/Images/") + imageCategoryName, @"../../Content/Images/" + imageCategoryName, imagesViewModel);

                            return(RedirectToAction("patientImagesList", new { patientID = imagesViewModel.PatientID }));
                        }
                    }
                    else
                    {
                        ViewBag.patientID = imagesViewModel.PatientID;
                        return(View());
                    }
                }
                else
                {
                    ViewBag.patientID = imagesViewModel.PatientID;
                    ImageCreateViewModel imageCreateViewModel = new ImageCreateViewModel();

                    imageCreateViewModel.imageCategoryList = imageRepository.getImagesCategoryList();
                    imageCreateViewModel.appointmentList   = appointmentRepository.getPatientAppountmentList(imagesViewModel.PatientID);
                    return(View(imageCreateViewModel));
                }

                return(RedirectToAction("patientImagesList", new { patientID = imagesViewModel.PatientID }));
            }
            catch
            {
                ViewBag.patientID = imagesViewModel.PatientID;
                ImageCreateViewModel imageCreateViewModel = new ImageCreateViewModel();

                imageCreateViewModel.imageCategoryList = imageRepository.getImagesCategoryList();
                imageCreateViewModel.appointmentList   = appointmentRepository.getPatientAppountmentList(imagesViewModel.PatientID);
                return(View(imageCreateViewModel));
            }
        }
Example #6
0
        public ActionResult PatientImagesCreate(int patientID = 0)
        {
            if (patientID == 0)
            {
                patientID = getCurrentPatientID();
            }

            ImageCreateViewModel imageCreateViewModel = new ImageCreateViewModel();

            imageCreateViewModel.imageCategoryList = imageRepository.getImagesCategoryList();
            imageCreateViewModel.appointmentList   = appointmentRepository.getPatientAppountmentList(patientID);

            ViewBag.patientID = patientID;
            return(View(imageCreateViewModel));
        }
Example #7
0
        public ActionResult Create(ImageCreateViewModel model)
        {
            string bitMapName = String.Empty;

            if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
            {
                var fileName  = this.Request.Files[0].FileName;
                var extension = Path.GetExtension(fileName);
                model.Image.FileName = String.Format("{0}{1}", Guid.NewGuid(), extension);
                bitMapName           = String.Format("bitmap-{0}", model.Image.FileName);
                //delete the old file
                if (!model.Image.IsNew())
                {
                    var oldImage     = _service.GetImages().Single(i => i.Id == model.Image.Id).FileName;
                    var oldImagePath = this.Server.MapPath(String.Format("~/user_images/{0}", oldImage));
                    var oldBitMap    = this.Server.MapPath(String.Format("~/user_images/bitmap-{0}", oldImage));
                    if (System.IO.File.Exists(oldImagePath))
                    {
                        System.IO.File.Delete(oldImagePath);
                    }
                    if (System.IO.File.Exists(oldBitMap))
                    {
                        System.IO.File.Delete(oldBitMap);
                    }
                }
                var saveTo       = this.Server.MapPath(String.Format("~/user_images/{0}", model.Image.FileName));
                var saveToBitMap = this.Server.MapPath(String.Format("~/user_images/{0}", bitMapName));
                this.Request.Files[0].SaveAs(saveTo);
                ResizeImage(saveTo, 500, 500);
                System.IO.File.Copy(saveTo, saveToBitMap);
                ResizeImage(saveToBitMap, 50, 50);
            }

            _service.SaveImage(model.Image);

            TempData["message"] = "Image Saved";
            return(RedirectToAction("List", new { id = model.NavigationModel.Page.PageNavigation.Id }));
        }
Example #8
0
 public ActionResult AddImage(ImageCreateViewModel model)
 {
     throw new NotImplementedException();
 }
Example #9
0
        public ActionResult AddProfileImage(HttpPostedFileBase file, ImageCreateViewModel model)
        {
            Account      account      = GetAccount();
            ProfileImage profileImage = new ProfileImage();

            if (file != null)
            {
                byte[] uploadedImage = new byte[file.InputStream.Length];
                string pic           = System.IO.Path.GetFileName(file.FileName);
                string path          = System.IO.Path.Combine(
                    Server.MapPath("~/content/images/profileImages"), pic);
                string extension = Path.GetExtension(file.FileName).ToLower();

                //ensures that only the correct file format is uploaded
                if (extension == ".png")
                {
                    file.SaveAs(path);
                }
                else if (extension == ".jpg")
                {
                    file.SaveAs(path);
                }
                else if (extension == ".gif")
                {
                    file.SaveAs(path);
                }
                // file is uploaded
                else
                {
                    TempData["errorMessage"] = "We only accept .png, .jpg, and .gif!";
                    return(RedirectToAction("AddProfileImage"));
                }

                // save the image path path to the database or you can send image
                // directly to database
                // in-case if you want to store byte[] ie. for DB
                if (file.ContentLength / 1000 < 1000)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        file.InputStream.Read(uploadedImage, 0, uploadedImage.Length);

                        profileImage.image      = uploadedImage;
                        profileImage.accountID  = account.accountID;
                        profileImage.caption    = model.caption;
                        profileImage.createDate = DateTime.Now;
                        profileImage.type       = "profileImages";
                    }
                }

                else
                {
                    TempData["errorMessage"] = @"The file you uploaded exceeds the size limit. 
                                              Please reduce the size of your file and try again.";
                }
            }

            /*if (profileImage.image.Count() > 5)
             * {
             *  TempData["errorMessage"] = @"Upload limit is 5";
             *  return RedirectToAction("AddProfileImage");
             * }*/

            profileImageDAL.Create(profileImage);
            return(RedirectToAction("AddProfileImage"));
        }
Example #10
0
        public ActionResult AddProfileImage()
        {
            ImageCreateViewModel model = new ImageCreateViewModel();

            return(View(model));
        }
Example #11
0
        public ActionResult Create([Bind(Include = "id,image_Type,doctor_id,patient_id,specialist_id,report_id,comment_id,create_datetime,file")] ImageCreateViewModel model)
        {
            string photoName = model.file.FileName;
            string savedName = Path.Combine(Server.MapPath("~/image"), photoName);
            image  image     = new image();

            try
            {
                if (ModelState.IsValid)
                {
                    //再新增圖片的時候report and comment也要跟著加入
                    report report = new report();
                    report.specialist_id = model.specialist_id;
                    report.annotation    = "Please enter content.";
                    report.create_date   = DateTime.Now;
                    report.type          = model.image_Type;
                    report.patient_id    = model.patient_id;
                    status r_status = new status();
                    r_status.type    = "report";
                    r_status.status1 = "new";
                    db.status.Add(r_status);
                    db.reports.Add(report);
                    db.SaveChanges();

                    comment comment = new comment();
                    comment.content    = "Please enter content.";
                    comment.doctor_Id  = model.doctor_id;
                    comment.patient_id = model.patient_id;
                    status c_status = new status();
                    c_status.type    = "comment";
                    c_status.status1 = "new";
                    db.status.Add(c_status);
                    db.comments.Add(comment);



                    image.id              = model.id;
                    image.image_Type      = model.image_Type;
                    image.doctor_id       = model.doctor_id;
                    image.patient_id      = model.patient_id;
                    image.specialist_id   = model.specialist_id;
                    image.report_id       = report.id;
                    image.comment_id      = comment.id;
                    image.create_datetime = model.create_datetime;
                    image.file_Path       = Path.Combine(Server.MapPath("~/image"), photoName).ToString();
                    image.file_Name       = photoName;

                    db.images.Add(image);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "Administrators"));
                }
            }
            catch (Exception ex)
            {
                return(View(ex.ToString()));
            }

            //ViewBag.doctor_id = new SelectList(db.doctors, "user_id", "user_id", image.doctor_id);
            //ViewBag.patient_id = new SelectList(db.patients, "id", "first_Name", image.patient_id);
            //ViewBag.specialist_id = new SelectList(db.stomatologists, "user_id", "user_id", image.specialist_id);
            return(View(image));
        }
Example #12
0
        /// <summary>
        /// Factory for creating Images
        /// </summary>
        /// <param name="imagesToAdd">images model to be added</param>
        /// <param name="imageType">PropertyImages/SightImages/UserImages/CityImages</param>
        public ISet <Images> CreateImagesFactory(ImageCreateViewModel imagesToAdd, string imageType, string userName)
        {
            string callerName;

            switch (imageType) // Caller Determining
            {
            case "PropertyImages":
                int propertyId = int.Parse(imagesToAdd.ForeignKey);
                callerName = unitOfWork.PropertiesRepository
                             .Where(p => p.Id == propertyId).Select(p => p.Owner.UserName)
                             .FirstOrDefault();
                //If property not found
                if (string.IsNullOrEmpty(callerName))
                {
                    throw new ArgumentException("No such Property");
                }
                break;

            case "SightImages":
                int sightId = int.Parse(imagesToAdd.ForeignKey);
                callerName = unitOfWork.SightsRepository
                             .Where(p => p.SightId == sightId).Select(p => p.SightName)
                             .FirstOrDefault();
                //If property not found
                if (string.IsNullOrEmpty(callerName))
                {
                    throw new ArgumentException("No such Sight");
                }
                break;

            case "UserImages":
                callerName = userName;
                //If property not found
                if (string.IsNullOrEmpty(callerName))
                {
                    throw new ArgumentException("No such user");
                }
                break;

            case "CityImages":
                int cityId = int.Parse(imagesToAdd.ForeignKey);
                callerName = unitOfWork.CitiesRepository
                             .Where(p => p.CityId == cityId).Select(p => p.CityName)
                             .FirstOrDefault();
                //If property not found
                if (string.IsNullOrEmpty(callerName))
                {
                    throw new ArgumentException("No such city");
                }
                break;

            default:
                throw new ArgumentException("No such image type");
            }

            ISet <Images> images = new HashSet <Images>();

            foreach (HttpPostedFileBase imageToAdd in imagesToAdd.ImageFiles)
            {
                Images image = null;
                switch (imageType)
                {
                case "PropertyImages":
                    image = new PropertyImages
                    {
                        ImagePath  = PathManager.CreateUserPropertyImagePath(callerName, imageToAdd.FileName),
                        PropertyId = int.Parse(imagesToAdd.ForeignKey)
                    };
                    break;

                case "SightImages":
                    image = new SightImages
                    {
                        ImagePath = PathManager.CreateSightImagePath(callerName, imageToAdd.FileName),
                        SightId   = int.Parse(imagesToAdd.ForeignKey)
                    };
                    break;

                case "UserImages":
                    image = new UserImages
                    {
                        ImagePath = PathManager.CreateUserProfileImagePath(callerName, imageToAdd.FileName),
                        UserId    = (string)imagesToAdd.ForeignKey
                    };
                    break;

                case "CityImages":
                    image = new CityImages
                    {
                        ImagePath = PathManager.CreateCityImagePath(callerName, imageToAdd.FileName),
                        CityId    = int.Parse(imagesToAdd.ForeignKey)
                    };
                    break;

                default:
                    throw new ArgumentException("No such image type");
                }
                image.ImageType = imageToAdd.ContentType;

                var physicalPath    = Path.Combine(HttpRuntime.AppDomainAppPath.TrimEnd('\\'), image.ImagePath.TrimStart('\\'));
                var physicalDirPath = Path.GetDirectoryName(physicalPath);
                if (!Directory.Exists(physicalDirPath))
                {
                    DirectoryHelpers.CreateDirectory(physicalDirPath);
                }
                imageToAdd.SaveAs(physicalPath);

                //Add Image to FileSystem
                Image img = Image.FromStream(imageToAdd.InputStream);
                image.ImageRatio = (float)img.Width / img.Height;

                //Adding image to DataBase
                unitOfWork.ImagesRepository.Add(image);
                unitOfWork.Save();

                //Add Image to returned set
                images.Add(image);
            }

            return(images);
        }