예제 #1
0
        public PartialViewResult FileDetails()
        {
            EmployeeImageService      imgService = new EmployeeImageService();
            List <EmployeeImageModel> DetList    = imgService.GetAllFiles();

            return(PartialView("FileDetails", DetList));
        }
예제 #2
0
        public ActionResult UploadPhoto(EmployeeImageModel image, HttpPostedFileBase file)
        {
            try
            {
                //if (file != null && file.ContentLength > 0)
                //    try
                //    {
                //        string path = Path.Combine(Server.MapPath("~/Images"),
                //                                   Path.GetFileName(file.FileName));
                //        file.SaveAs(path);
                //        ViewBag.Message = "File uploaded successfully";


                //        image.EmployeeImage= new byte[file.ContentLength];
                //        file.InputStream.Read(image.EmployeeImage, 0, file.ContentLength);
                //        ImageService imageService = new ImageService();

                //        imageService.SaveImage(image);

                //        return Json("Uploaded Successful");

                //    }
                //    catch (Exception ex)
                //    {
                //        ViewBag.Message = "ERROR:" + ex.Message.ToString();
                //    }
                //else
                //{
                //    ViewBag.Message = "You have not specified a file.";
                //}
                //return View();
                String FileExt = Path.GetExtension(file.FileName).ToUpper();
                EmployeeImageService imageService = new EmployeeImageService();
                if (FileExt == ".JPG")
                {
                    Stream       str     = file.InputStream;
                    BinaryReader Br      = new BinaryReader(str);
                    Byte[]       FileDet = Br.ReadBytes((Int32)str.Length);

                    image.EmployeeNumber  = (Int64)Session["empId"];
                    image.FileDescription = "EmployeeImage";
                    image.FileName        = file.FileName;
                    image.FileContent     = FileDet;
                    imageService.SaveEmployeeImage(image);
                    return(Json("Photo Uploaded Successfully"));
                }
                else
                {
                    return(Json("Invalid file format"));
                }
            }
            catch (Exception ex)
            {
                return(Json("Upload failed"));
            }
        }
예제 #3
0
        public FileResult DownLoadFile()
        {
            EmployeeImageService      imgService = new EmployeeImageService();
            List <EmployeeImageModel> ObjFiles   = imgService.GetAllFiles();

            var FileById = (from FC in ObjFiles
                            where FC.EmployeeNumber.Equals((Int64)Session["empId"])
                            select new { FC.FileName, FC.FileContent }).ToList().FirstOrDefault();

            return(File(FileById.FileContent, "image/jpg"));
        }