Exemplo n.º 1
0
        public ActionResult Create(ProductVM productVM, IFormFile FilePicture)
        {
            try
            {
                PictureVM imageEntity = GeneratePicture.CreatePicture(FilePicture, $"{productVM.Name} - {productVM.Description}");
                productVM.Picture = imageEntity;

                if (string.IsNullOrEmpty(productVM.DT_RowId))
                {
                    _productAppService.Add(productVM);
                }
                else
                {
                    _productAppService.Update(productVM);
                }

                if (_notificationContext.HasNotifications)
                {
                    ViewData["Notifications"] = _notificationContext.Notifications.ToList();
                    return(View());
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ActionResult PictureDetail(PictureVM modelPicture, HttpPostedFileBase resim)
        {
            Picture gelenPicture = _UnitOfWork.GetRepository <Picture>().GetById(modelPicture.Id);

            gelenPicture.CatId = modelPicture.CatId;
            if (resim == null && modelPicture.ImagePath != "default.png")
            {
                gelenPicture.ImagePath = modelPicture.ImagePath;
            }
            else if (resim == null)
            {
                gelenPicture.ImagePath = "default.png";
            }
            else
            {
                Image photoThumb                = Image.FromStream(resim.InputStream, true, true);
                ImageUploadService svc          = ImageUploadService.CreateService(resim);
                string             uniqFileName = svc.CreateUniqName(resim.FileName, OrgimagePath);

                svc.Upload(OrgimagePath, SmallimagePath, LargeimagePath, uniqFileName);
                gelenPicture.ImagePath = uniqFileName;
            }
            _UnitOfWork.GetRepository <Picture>().Update(gelenPicture);
            _UnitOfWork.SaveChanges();
            return(RedirectToAction("Index", "AdminPicture"));
        }
        public ActionResult InsertPicture(PictureVM gelenPicture, HttpPostedFileBase resim)
        {
            string OrgimagePath   = "~/Upload/Picture/OrjPath";
            string SmallimagePath = "~/Upload/Picture/SmallPath";
            string LargeimagePath = "~/Upload/Picture/LargePath";
            string uniqFileName   = "";

            ImageUploadService svc = ImageUploadService.CreateService(resim);

            uniqFileName = svc.CreateUniqName(resim.FileName, OrgimagePath);
            PictureVM vmodel = new PictureVM();

            Picture eklenecek = new Picture();

            if (ModelState.IsValid)
            {
                if (resim != null)
                {
                    svc.Upload(OrgimagePath, SmallimagePath, LargeimagePath, uniqFileName);
                }
                eklenecek.CatId     = gelenPicture.CatId;
                eklenecek.ImagePath = uniqFileName;
                _UnitOfWork.GetRepository <Picture>().Insert(eklenecek);
                _UnitOfWork.SaveChanges();
                return(RedirectToAction("Index", "AdminPicture"));
            }
            else
            {
                return(View(vmodel));
            }
        }
Exemplo n.º 4
0
        public IActionResult UploadImage(IList <IFormFile> files)
        {
            IFormFile uploadedImage = files.FirstOrDefault();

            if (uploadedImage == null || uploadedImage.ContentType.ToLower().StartsWith("image/"))
            {
                MemoryStream ms = new MemoryStream();
                uploadedImage.OpenReadStream().CopyTo(ms);

                Image image = Image.FromStream(ms);

                PictureVM imageEntity = new PictureVM()
                {
                    Name        = uploadedImage.FileName.Substring(0, uploadedImage.FileName.LastIndexOf(".")),
                    Data        = ms.ToArray(),
                    Width       = image.Width,
                    Height      = image.Height,
                    ContentType = uploadedImage.ContentType
                };

                _configurationApplicationService.Add(imageEntity);
            }

            return(RedirectToAction("Index"));
        }
Exemplo n.º 5
0
        public FileStreamResult ViewImage(Guid id)
        {
            PictureVM image = _configurationApplicationService.GetById(id);

            MemoryStream ms = new MemoryStream(image.Data);

            return(new FileStreamResult(ms, image.ContentType));
        }
        public ActionResult InsertPicture()
        {
            PictureVM picture = new PictureVM();

            picture.drpcategories = _CategoryService.getDrpCategories();
            picture.ImagePath     = "default.png";
            return(View(picture));
        }
Exemplo n.º 7
0
        public ActionResult ImageLoad(int id)
        {
            var       album   = _albumRepository.Get(id);
            PictureVM picture = Mapper.Map <PictureVM>(album);

            picture.Guid = album.Guid;
            return(View(picture));
        }
Exemplo n.º 8
0
        bool InitImages(PictureVM pictureVM, Album album)
        {
            if (pictureVM == null || album == null || pictureVM.files == null)
            {
                return(false);
            }
            string datetimeff = null;

            foreach (var file in pictureVM.files)
            {
                DAL.Image image = new DAL.Image();
                datetimeff = DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_";
                image.Name = datetimeff + Path.GetFileName(file.FileName.Replace(" ", string.Empty));
                var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, album.Path, album.Guid.ToString(), image.Name);

                using (var originalImage = System.Drawing.Image.FromStream(file.InputStream, true, true))                 /* Creates Image from specified data stream */
                {
                    int   newWidth    = 200;
                    int   newHeight   = 200;
                    float aspectRatio = originalImage.Width / (float)originalImage.Height;
                    if (originalImage.Width > originalImage.Height)
                    {
                        newWidth = (int)(200 * aspectRatio);
                    }
                    else
                    {
                        newHeight = (int)(200 / aspectRatio);
                    }
                    using (var thumb = originalImage.GetThumbnailImage(
                               newWidth,                   /* width*/
                               newHeight,                  /* height*/
                               () => false,
                               IntPtr.Zero))
                    {
                        var jpgInfo = ImageCodecInfo.GetImageEncoders().Where(codecInfo => codecInfo.MimeType == "image/png").First();                         /* Returns array of image encoder objects built into GDI+ */
                        using (var encParams = new EncoderParameters(1))
                        {
                            var appDataThumbnailPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, MVCManager.Controller.Main.DefaultThumbnailsPath, album.Guid.ToString());
                            if (!Directory.Exists(appDataThumbnailPath))
                            {
                                Directory.CreateDirectory(appDataThumbnailPath);
                            }
                            string outputPath = Path.Combine(appDataThumbnailPath, image.Name);
                            long   quality    = 100;
                            encParams.Param[0] = new EncoderParameter(Encoder.Quality, quality);
                            thumb.Save(outputPath, jpgInfo, encParams);
                        }
                    }
                }
                file.SaveAs(filePath);
                album.Image.Add(image);
            }
            _albumRepository.UnitOfWork.SaveChanges();
            return(true);
        }
        public void AddPic(Picture picture)
        {
            var pic = new PictureVM
            {
                Id      = picture.Id,
                MSource = PictureExtensions.ImagePath(picture.Id + picture.Extension, "m", picture.Created),
                SSource = PictureExtensions.ImagePath(picture.Id + picture.Extension, "s", picture.Created),
            };

            Pics.Add(pic);
        }
Exemplo n.º 10
0
 public static IEnumerable <PictureVM> PicturesToPictureVMs(IEnumerable <Picture> pictures, List <PictureVM> pictureVMs)
 {
     foreach (var picture in pictures)
     {
         var pictureVM = new PictureVM()
         {
             PictureId   = Encryptor.GetEncryptedString(picture.PictureId.ToString()),
             PictureName = picture.ImageName, PictureSize = picture.Size, ImageSrc = GetImageSrcFrom(picture)
         };
         pictureVMs.Add(pictureVM);
     }
     return(pictureVMs);
 }
 public void SavePicture(string Id)
 {
     if (!string.IsNullOrEmpty(Id))
     {
         var pic = new PictureVM
         {
             Id      = Guid.Parse(Id),
             MSource = PictureExtensions.ImagePath(Id + ".jpg", "m", DateTime.Now),
             SSource = PictureExtensions.ImagePath(Id + ".jpg", "s", DateTime.Now),
         };
         Pics.Add(pic);
     }
 }
Exemplo n.º 12
0
        public ActionResult UpdatePicture(PictureVM obj)
        {
            int userId = Convert.ToInt32(Session["UserId"]);

            if (userId == 0)
            {
                return(RedirectToAction("Login", "Regjistrohu"));
            }
            string[] allowedFileTypes = { ".png", ".jpeg", ".jpg" };
            var      file             = obj.Picture;
            bool     u_gjet           = false;
            var      extension        = Path.GetExtension(file.FileName);
            User     u = db.User.Find(userId);

            if (file != null)
            {
                for (int i = 0; i < 3; i++)
                {
                    if (extension.Equals(allowedFileTypes[i]))
                    {
                        u_gjet = true;
                    }
                }
                if (u_gjet == true)
                {
                    //Update Image
                    string id_and_extension = userId + extension;
                    string imgUrl           = "~/Profile Images/" + id_and_extension;
                    u.ImageUrl        = imgUrl;
                    db.Entry(u).State = EntityState.Modified;
                    db.SaveChanges();
                    var path = Server.MapPath("~/Profile Images/");
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    if ((System.IO.File.Exists(path + id_and_extension)))
                    {
                        System.IO.File.Delete(path + id_and_extension);
                    }
                    file.SaveAs((path + id_and_extension));
                    return(RedirectToAction("UserProfile"));
                }
                else
                {
                    ViewBag.Photo = ("Ju duhet te zgjidhni nje imazh");
                    return(RedirectToAction("UserProfile"));
                }
            }
            return(RedirectToAction("UserProfile"));
        }
        public ActionResult PictureDetail(int id)
        {
            Picture   gelenPicture = _PictureService.getPictureDetail(id);
            PictureVM gosterilen   = new PictureVM();

            gosterilen.Id            = gelenPicture.Id;
            gosterilen.ImagePath     = gelenPicture.ImagePath;
            gosterilen.drpcategories = _CategoryService.getAllCategories().Select(cat => new SelectListItem()
            {
                Text  = cat.Name,
                Value = cat.Id.ToString()
            }).ToList();
            return(View(gosterilen));
        }
Exemplo n.º 14
0
        public ActionResult ImageLoad(PictureVM picture)
        {
            var album = _albumRepository.GetAlbumByGuid(picture.Guid);

            if (InitImages(picture, album))
            {
                picture.Message = "Your photos have successfully uploaded";
            }
            else
            {
                picture.Message = "Something wrong, Your upload is not successful!";
            }
            return(View(picture));
        }
Exemplo n.º 15
0
        public PictureVM Add(PictureVM entity)
        {
            try
            {
                var picture = _mapper.Map <Picture>(entity);
                _unitOfWork.Repository <Picture>().Add(picture);
                _unitOfWork.CommitSync();

                return(_mapper.Map <PictureVM>(picture));;
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <ConfigurationApplicationService>("Unexpected error fetching add picture", nameof(this.Add), ex);
            }
        }
Exemplo n.º 16
0
        public IActionResult CreateTrackingTypes(TrackingTypeVM trackingTypeVM, IFormFile FilePicture)
        {
            try
            {
                PictureVM imageEntity = GeneratePicture.CreatePicture(FilePicture, $"{trackingTypeVM.Description}");
                trackingTypeVM.Picture = imageEntity;

                _boxTrackingApplicationService.AddTraceType(trackingTypeVM);
                return(RedirectToAction("TrackingTypes"));
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 17
0
        public async Task <IActionResult> uploadPicture(PictureVM picture)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var Photo = picture.GetPhotoFromViewModel();
                await _PhotoService.Save(Photo);

                return(this.Ok(true));
            }
            catch (Exception xcp) {
                //log exception
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
Exemplo n.º 18
0
        public IActionResult CreateBoxType(BoxTypeVM boxTypeVM, IFormFile FilePicture)
        {
            try
            {
                PictureVM imageEntity = GeneratePicture.CreatePicture(FilePicture, $"{boxTypeVM.Name} - {boxTypeVM.Description}");
                boxTypeVM.Picture = imageEntity;

                _boxApplicationService.AddBoxType(boxTypeVM);

                return(RedirectToAction("BoxesType"));
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 19
0
        // GET: Pictures/Edit/5
        public ActionResult PictureEdit(int?id)
        {
            //if (id == null)
            //{
            //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            //}
            Pictures pictures = db.Pictures.Where(x => x.ID == id).SingleOrDefault();

            PictureVM model = new PictureVM()
            {
                PictureSitePath = pictures.PictureSitePath,
                TsarID          = Convert.ToInt32(pictures.TsarID)
            };

            if (pictures == null)
            {
                return(HttpNotFound());
            }
            ViewBag.TsarID = new SelectList(db.Tsars, "ID", "FullName", pictures.TsarID);
            return(View(model));
        }
Exemplo n.º 20
0
        //protected override async Task OnInitializedAsync()
        //{

        //}

        protected override async Task OnParametersSetAsync()
        {
            Id      = Id ?? "1";
            Article = await ArticleService.GetAsync(int.Parse(Id));

            foreach (var picture in Article.Pictures)
            {
                var pic = new PictureVM
                {
                    Id      = picture.Id,
                    MSource = PictureExtensions.ImagePath(picture.Id + picture.Extension, "m", picture.Created),
                    NSource = PictureExtensions.ImagePath(picture.Id + picture.Extension, "n", picture.Created),
                    Active  = ""
                };
                Pics.Add(pic);
            }
            if (Pics.Count > 0)
            {
                Pics.First().Active = "active";
            }
        }
Exemplo n.º 21
0
        public static PictureVM CreatePicture(IFormFile FilePicture, string name)
        {
            if (FilePicture == null || FilePicture.ContentType.ToLower().StartsWith("image/"))
            {
                MemoryStream ms = new MemoryStream();
                FilePicture.OpenReadStream().CopyTo(ms);

                Image image = Image.FromStream(ms);

                PictureVM imageEntity = new PictureVM()
                {
                    Name        = name,
                    Data        = ms.ToArray(),
                    Width       = image.Width,
                    Height      = image.Height,
                    ContentType = FilePicture.ContentType
                };

                return(imageEntity);
            }
            return(null);
        }
Exemplo n.º 22
0
 public PictureVM Update(PictureVM updated)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 23
0
        public ActionResult PictureCreate(/*[Bind(Include = "ID,PictureSitePath,TsarID")]*/ PictureVM model, HttpPostedFileBase PictureSitePath)
        {
            if (ModelState.IsValid)
            {
                Pictures pictures = new Pictures();

                if (PictureSitePath != null)
                {
                    WebImage img     = new WebImage(PictureSitePath.InputStream);
                    FileInfo imginfo = new FileInfo(PictureSitePath.FileName);

                    string imgname = Guid.NewGuid().ToString() + imginfo.Extension;

                    img.Resize(225, 255);

                    img.Save("~/Uploads/carResimler/" + imgname);

                    model.PictureSitePath = "/Uploads/carResimler/" + imgname;
                }

                pictures.PictureSitePath = model.PictureSitePath;
                pictures.TsarID          = model.TsarID;


                db.Pictures.Add(pictures);
                db.SaveChanges();
                return(RedirectToAction("PictureList"));
            }

            ViewBag.TsarID = new SelectList(db.Tsars, "ID", "FullName", model.TsarID);
            return(View(model));
        }
Exemplo n.º 24
0
  public PictureVM GetPicture()
  {
      
       var pvm = new PictureVM();
      pvm.mimetype = "image/jpeg";
      pvm.buffer = User.picture;
      return pvm;
 
  }
Exemplo n.º 25
0
 public Task <PictureVM> UpdateAsync(PictureVM updated)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 26
0
 public Task <PictureVM> AddAsync(PictureVM entity)
 {
     throw new NotImplementedException();
 }