Esempio n. 1
0
 public int UploadImageInDataBase(HttpPostedFileBase file, string _empNo)
 {
     using (var context = new TAS2013Entities())
     {
         List <EmpPhoto> _empPhotoList = new List <EmpPhoto>();
         EmpPhoto        _EmpPhoto     = new EmpPhoto();
         Emp             _Emp          = new Emp();
         int             empPhotoID    = 0;
         _Emp             = context.Emps.First(aa => aa.EmpNo == _empNo);
         _empPhotoList    = context.EmpPhotoes.Where(aa => aa.EmpID == _Emp.EmpID).ToList();
         _EmpPhoto.EmpPic = ConvertToBytes(file);
         if (_empPhotoList.Count > 0)
         {
             //Update Existing Image
             _EmpPhoto.EmpID   = _empPhotoList.FirstOrDefault().EmpID;
             _EmpPhoto.PhotoID = _empPhotoList.FirstOrDefault().PhotoID;
         }
         else
         {
             //Add New Image
             _EmpPhoto.EmpID = _Emp.EmpID;
             context.EmpPhotoes.Add(_EmpPhoto);
         }
         try
         {
             empPhotoID = _EmpPhoto.PhotoID;
             context.SaveChanges();
             return(empPhotoID);
         }
         catch (Exception ex)
         {
             return(empPhotoID);
         }
     }
 }
Esempio n. 2
0
        private string ProcessUploadedFile()
        {
            string uniqueFileName = null;

            if (EmpPhoto != null)

            {
                string uploadsfolder = Path.Combine(webHostEnvironment.WebRootPath, "images");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + EmpPhoto.FileName;
                string filepath = Path.Combine(uploadsfolder, uniqueFileName);
                using (var filestream = new FileStream(filepath, FileMode.Create))
                {
                    EmpPhoto.CopyTo(filestream);
                }
            }
            return(uniqueFileName);
        }
Esempio n. 3
0
        public int UploadImageInDataBase(HttpPostedFileBase file, Emp _Emp)
        {
            using (var context = new TAS2013Entities())
            {
                List <EmpPhoto> _empPhotoList = new List <EmpPhoto>();
                EmpPhoto        _EmpPhoto     = new EmpPhoto();
                int             empPhotoID    = 0;

                _empPhotoList    = context.EmpPhotoes.Where(aa => aa.EmpID == _Emp.EmpID).ToList();
                _EmpPhoto.EmpPic = ConvertToBytes(file);
                if (_empPhotoList.Count > 0)
                {
                    _EmpPhoto.PhotoID = _empPhotoList.FirstOrDefault().PhotoID;
                    _empPhotoList.FirstOrDefault().EmpPic = _EmpPhoto.EmpPic;
                    context.EmpPhotoes.Attach(_empPhotoList.FirstOrDefault());
                    context.Entry(_empPhotoList.FirstOrDefault()).State = EntityState.Modified;
                    context.SaveChanges();
                }
                else
                {
                    //Add New Image
                    _EmpPhoto.EmpID = _Emp.EmpID;
                    context.EmpPhotoes.Add(_EmpPhoto);
                }
                try
                {
                    empPhotoID = _EmpPhoto.PhotoID;
                    context.SaveChanges();
                    return(empPhotoID);
                }
                catch (Exception ex)
                {
                    return(empPhotoID);
                }
            }
        }