Exemplo n.º 1
0
        public ImageUploadView(ImageUploadViewModel context, TemplateGeneratorView templateGeneratorView)
        {
            this.InitializeComponent();
            this.DataContext = context;

            this.Owner = templateGeneratorView;
        }
Exemplo n.º 2
0
 public async Task <ActionResult> DetailAllbum(HttpPostedFileBase[] files, int _abid)
 {
     try
     {
         foreach (HttpPostedFileBase file in files)
         {
             ImageUploadViewModel item = new ImageUploadViewModel();
             item = cms_db.UploadHttpPostedFileBase(file);
             MediaContentViewModels _Media = new MediaContentViewModels();
             _Media.Filename         = item.ImageName;
             _Media.FullURL          = item.ImageUrl;
             _Media.ContentObjId     = _abid;
             _Media.ObjTypeId        = (int)EnumCore.ObjTypeId.album;
             _Media.ViewCount        = 0;
             _Media.CrtdDT           = DateTime.UtcNow;
             _Media.MediaContentSize = file.ContentLength;
             _Media.ThumbURL         = item.ImageThumbUrl;
             _Media.CrtdUID          = long.Parse(User.Identity.GetUserId());
             _Media.MediaTypeId      = (int)EnumCore.mediatype.hinh_anh;
             long _ImgId = await cms_db.AddNewMediaContent(_Media);
         }
         DetailAlbumViewModel model = new DetailAlbumViewModel();
         model.Album    = cms_db.GetObjClasscifiById(_abid);
         model.lstImage = cms_db.GetLstMediaContentByAlbumId(_abid);
         return(View(model));
     }
     catch (Exception e)
     {
         cms_db.AddToExceptionLog("DetailAllbum", "MediaManager", e.ToString());
         return(RedirectToAction("ErrorExeption", "Extension"));
     }
 }
Exemplo n.º 3
0
        public ActionResult Upload(ImageUploadViewModel formData)
        {
            var    theseGuys    = User.Identity.GetUserName();
            var    thisCouple   = User.Identity.GetUserId();
            var    uploadedFile = Request.Files[0];
            string filename     = $"{DateTime.Now.Ticks}{uploadedFile.FileName}";
            var    serverPath   = Server.MapPath(@"~\Uploads");
            var    fullPath     = Path.Combine(serverPath, filename);
            //uploadedFile.SaveAs(fullPath);
            //resizing to 640x640
            ResizeSettings resizeSetting = new ResizeSettings
            {
                Width  = 640,
                Height = 640,
                Format = "png"
            };

            ImageBuilder.Current.Build(uploadedFile, fullPath, resizeSetting);

            var uploadModel = new ImageUpload
            {
                Caption = theseGuys,
                File    = filename
            };
            var currentUser = db.Couples.Where(c => c.CurrentUser == thisCouple).FirstOrDefault();

            currentUser.ProfilePic = uploadModel.Id;
            db.ImageUploads.Add(uploadModel);
            db.SaveChanges();
            return(RedirectToAction("Browse", "Home"));
        }
Exemplo n.º 4
0
        public int UploadImages(ImageUploadViewModel model)
        {
            string uploadDirectory = ConfigurationManager.AppSettings["UploadDirectoryImages"].ToString();

            using (camphorizonEntities db = new camphorizonEntities())
            {
                var order     = db.ImagesCatalogues.Where(x => x.ImageFor == model.ImageType).Max(x => x.SlideOrder);
                int lastOrder = order.HasValue ? order.Value : 0;
                foreach (var img in model.Images)
                {
                    string uploadFileLink = UploadFile(img, uploadDirectory);
                    lastOrder++;
                    db.ImagesCatalogues.Add(new ImagesCatalogue()
                    {
                        Active       = model.Active,
                        ImageFor     = model.ImageType,
                        ImageLink    = uploadFileLink,
                        Name         = model.Name,
                        OfferDetails = model.OfferDetails,
                        OfferHeading = model.OfferHeading,
                        SlideOrder   = (short)lastOrder
                    });
                }

                return(db.SaveChanges());
            }
        }
Exemplo n.º 5
0
        public ImageUploadViewModel UploadHttpPostedFileBaseFrond(HttpPostedFileBase Request)
        {
            HttpPostedFileBase   desimg    = Request;
            ImageUploadViewModel imgUpload = new ImageUploadViewModel();
            long   _ImgId     = 0;
            string coderandom = DateTime.UtcNow.Ticks.ToString();

            coderandom = "botogiasi" + coderandom;
            var    _Filename   = Path.GetFileName(desimg.FileName);
            string _ServerPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConstantSystem.FolderFrontEnd);
            string _NameRandom = coderandom + _Filename;
            var    path        = Path.Combine(_ServerPath, _NameRandom);

            if (!System.IO.Directory.Exists(_ServerPath))
            {
                System.IO.Directory.CreateDirectory(_ServerPath);
            }
            desimg.SaveAs(path);
            FileHelper.SaveResizedImage(_ServerPath, _NameRandom, "thumb" + _NameRandom, ConstantSystem.ResizeWidth, ConstantSystem.ResizeHeight);
            imgUpload.ImageName      = _NameRandom;
            imgUpload.ImageThumbUrl  = ConstantSystem.FolderFrontEnd + "/thumb" + _NameRandom;
            imgUpload.ImageUrl       = ConstantSystem.FolderFrontEnd + "/" + _NameRandom;
            imgUpload.MediaContentId = _ImgId;
            return(imgUpload);
        }
Exemplo n.º 6
0
        private string BuildXmlFile(ImageUploadViewModel model, string imagePath)
        {
            var entryTime = (DateTime.Now).ToShortDateString() + ":" + (DateTime.Now).ToShortTimeString();

            StringBuilder sb = new StringBuilder();

            sb.Append(@"<ImageInfo>");

            sb.Append(BuildString("CustomerName", model.CustomerName));
            sb.Append(BuildString("CustomerPhone", model.Telephone));
            sb.Append(BuildString("CustomerEmail", model.EmailAddress));
            sb.Append(BuildString("TimeEntered", entryTime));

            sb.Append(BuildString("ArtistName", model.ArtistName));
            //   sb.Append(BuildString("CountryofOrigin", model.CountryofOrigin));
            sb.Append(BuildString("ArtTitle", model.ArtTitle));
            sb.Append(BuildString("Dimensions", model.Dimensions));
            sb.Append(BuildString("Medium", model.Medium));
            sb.Append(BuildString("Price", model.Price));
            sb.Append(BuildString("ImagePath", imagePath));

            sb.Append(@"</ImageInfo>");

            return(sb.ToString());
        }
Exemplo n.º 7
0
        public async Task <IActionResult> UploadImage(ImageUploadViewModel image, IFormFile file)
        {
            if (ModelState.IsValid)
            {
                if (image.VenueId == null)
                {
                    throw new Exception("Venue id cannot be null");
                }

                try {
                    if (file != null)
                    {
                        var imageDb = new Image();
                        imageDb.Id    = Guid.NewGuid();
                        imageDb.Name  = image.Title;
                        imageDb.Venue = this._venueService.GetVenueById(image.VenueId);

                        bool successImageStored = await this._venueService.AddImageAsync(imageDb, file, image.IsLogoImage);
                    }
                    return(new RedirectToActionResult("Images", "Venue", new { id = image.VenueId }));
                }
                catch (Exception ex) {
                    this._logger.LogError(ex.StackTrace);
                    ModelState.AddModelError("Error", ex.Message);
                }
            }

            return(View(image));
        }
        public IActionResult Upload()
        {
            var model = new ImageUploadViewModel();

            model.UploadStage = UploadStage.Upload;
            return(View(model));
        }
Exemplo n.º 9
0
        public ActionResult UploadProfilePic(string userId)
        {
            var ImageUploadViewModel = new ImageUploadViewModel();

            ViewBag.UserId = userId;
            return(View(ImageUploadViewModel));
        }
Exemplo n.º 10
0
        public ActionResult Upload(ImageUploadViewModel formData)
        {
            //Get File and Create Path
            var    uploadedFile = Request.Files[0];
            string filename     = $"{DateTime.Now.Ticks}{uploadedFile.FileName}";
            var    serverPath   = Server.MapPath(@"~\Uploads");
            var    fullPath     = Path.Combine(serverPath, filename);

            //Resize Image
            //WebImage img = new WebImage(uploadedFile.InputStream);
            //if (img.Width > 1000)
            //    img.Resize(1000, 1000);

            //Save Image
            uploadedFile.SaveAs(fullPath);

            //Create ImgUpload Entry
            var uploadModel = new ImgUpload
            {
                Caption = formData.Caption,
                File    = filename,
                OwnerId = User.Identity.GetUserId(),
                TypeRef = "ProfilePic",
            };

            db.ImgUploads.Add(uploadModel);
            db.SaveChanges();

            return(Redirect("Index"));
        }
        private async Task <MediaContentViewModels> SaveDefaultImageForTicker(HttpPostedFileBase file, long TickerId)
        {
            MediaContent CurrentMediaId = cms_db.GetObjMedia().Where(s => s.ObjTypeId == (int)EnumCore.ObjTypeId.ticker &&
                                                                     s.MediaTypeId == (int)EnumCore.mediatype.hinh_anh_dai_dien && s.ContentObjId == TickerId).FirstOrDefault();

            if (CurrentMediaId != null)
            {
                int rs = await cms_db.DeleteMediaContent(CurrentMediaId.MediaContentId);
            }
            ImageUploadViewModel item = new ImageUploadViewModel();

            item = cms_db.UploadHttpPostedFileBase(file);
            MediaContentViewModels _Media = new MediaContentViewModels();

            _Media.Filename         = item.ImageName;
            _Media.FullURL          = item.ImageUrl;
            _Media.ContentObjId     = TickerId;
            _Media.ObjTypeId        = (int)EnumCore.ObjTypeId.ticker;
            _Media.ViewCount        = 0;
            _Media.MediaTypeId      = (int)EnumCore.mediatype.hinh_anh_dai_dien;
            _Media.CrtdDT           = DateTime.UtcNow;
            _Media.MediaContentSize = file.ContentLength;
            _Media.ThumbURL         = item.ImageThumbUrl;
            _Media.CrtdUID          = long.Parse(User.Identity.GetUserId());
            await cms_db.AddNewMediaContent(_Media);

            return(_Media);
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Create(ElectricCarInputViewModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.RedirectToAction(nameof(this.Create)));
            }

            var userId = this.userManager.GetUserId(this.User);
            var carId  = await this.carsService.CreateCarAsync(input, userId);

            if (input.Images != null)
            {
                var imagePath = $"{this.environment.WebRootPath}/img";

                var imageUploadModel = new ImageUploadViewModel();
                imageUploadModel.Images        = input.Images;
                imageUploadModel.Path          = imagePath;
                imageUploadModel.UserId        = userId;
                imageUploadModel.ImageTypeName = GlobalConstants.CarExternalImage;
                imageUploadModel.CarId         = carId;

                await this.imagesService.UploadImages(imageUploadModel);
            }

            this.TempData["Message"] = "You can drive now. Your car is created successufully";

            return(this.RedirectToAction(nameof(this.Index)));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> UploadFile(ImageUploadViewModel model)
        {
            if (model.File is null)
            {
                return(BadRequest(error: $"File cannot be empty"));
            }
            else
            {
                bool isDirectoryExistent = Directory.Exists(_hostingEnvironment.WebRootPath + "/uploads");

                if (!isDirectoryExistent)
                {
                    Directory.CreateDirectory(_hostingEnvironment.WebRootPath + "/uploads");
                }

                string uploadPath    = Path.Combine(_hostingEnvironment.WebRootPath, "uploads");
                string fileExtension = Path.GetExtension(model.File.FileName);
                string fileName      = Guid.NewGuid().ToString("N") + fileExtension;

                using (var fileStream = new FileStream(Path.Combine(uploadPath, fileName), FileMode.Create))
                {
                    await model.File.CopyToAsync(fileStream);

                    return(CreatedAtRoute("Create", value: "File is successfully uploaded"));
                }
            }
        }
Exemplo n.º 14
0
        public IActionResult UploadImage(ImageUploadViewModel model)
        {
            if (ModelState.IsValid)
            {
                var img = model.Image;

                Byte[] imageBytes;
                using (Stream _stream = img.OpenReadStream())
                {
                    imageBytes = ReadFully(_stream, (int)_stream.Length);
                }

                ImageModel image = new ImageModel
                {
                    Title      = model.Title,
                    ImageBytes = imageBytes,
                    ImageType  = img.ContentType
                };
                using (_appDbContext)
                {
                    _appDbContext.Images.Add(image);
                    _appDbContext.SaveChanges();
                }
                return(RedirectToAction("Gallery"));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Error uploading image.");
                return(View(model));
            }
        }
Exemplo n.º 15
0
        public ActionResult Upload(ImageUploadViewModel formData)
        {
            var    uploadedFile = Request.Files[0];
            string filename     = $"{DateTime.Now.Ticks}{uploadedFile.FileName}";
            var    serverPath   = Server.MapPath(@"~\Uploads");
            var    fullPath     = Path.Combine(serverPath, filename);
            //uploadedFile.SaveAs(fullPath);
            ResizeSettings resizeSetting = new ResizeSettings
            {
                Width  = 640,
                Height = 640,
                Format = "png"
            };

            ImageBuilder.Current.Build(uploadedFile, fullPath, resizeSetting);

            var uploadModel = new ImageUpload
            {
                Caption = User.Identity.GetUserName(),
                File    = filename
            };

            db.ImageUploads.Add(uploadModel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 16
0
        public async Task <IActionResult> Create(ImageUploadViewModel vm)
        {
            if (ModelState.IsValid)
            {
                // check to see if image file exists
                if (vm.ImageFile != null)
                {
                    // convert image into byte array
                    using (var memoryStream = new MemoryStream())
                    {
                        await vm.ImageFile.CopyToAsync(memoryStream);

                        vm.vendorCategory.CategoryImage = memoryStream.ToArray();
                    }
                }
                ;
                _context.Add(vm.vendorCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
            }
            return(View(vm));
        }
Exemplo n.º 17
0
        public async Task <IActionResult> UploadImage(ImageUploadViewModel model)
        {
            try
            {
                if (model.CategoryId == null && string.IsNullOrEmpty(model.CategoryName))
                {
                    return(BadRequest());
                }

                if (model.CategoryId == null)
                {
                    model.CategoryId = Guid.NewGuid();
                }

                if (!model.Image.ContentType.Contains("image"))
                {
                    return(BadRequest("file is not a image!"));
                }

                await _images.UploadImage(model);

                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.ToString()));
            }
        }
Exemplo n.º 18
0
        // GET: VendorCategories/Create
        public IActionResult Create()
        {
            //instantiate view model for image uploader
            ImageUploadViewModel vm = new ImageUploadViewModel();

            return(View(vm));
        }
Exemplo n.º 19
0
        public ActionResult UploadAPic(int AId)
        {
            var ImageUploadViewModel = new ImageUploadViewModel();

            ViewBag.UserId      = User.Identity.GetUserId();
            ViewBag.ImageUpload = db.ImageUploads.Where(i => i.AId == AId).FirstOrDefault();
            return(View(ImageUploadViewModel));
        }
Exemplo n.º 20
0
        public IActionResult ImageUploadPost(ImageUploadViewModel viewModel, IFormFile file)
        {
            var fileName = Path.GetFileName(file.FileName);
            var userId   = AuthorizationUtilities.Instance.GetUserId(User);

            var localFolderPath = Path.Combine(_settings.ImageRepositoryPath, userId);

            if (!Directory.Exists(localFolderPath))
            {
                Directory.CreateDirectory(localFolderPath);
            }

            var localImagePath = Path.Combine(localFolderPath, fileName);

            if (System.IO.File.Exists(localImagePath))
            {
                ViewBag.Error = "An image with the same name has already been uploaded.";
                return(View("ImageUpload", viewModel));
            }

            var imageBuilder = _imageBuilderFactory.CreateImageBuilder();

            imageBuilder.SetBaseImageInfo(fileName, localImagePath, file.OpenReadStream());
            imageBuilder.AssignUser(userId);
            if (!string.IsNullOrEmpty(viewModel.Tags))
            {
                imageBuilder.AddTags(viewModel.Tags);
            }
            if (!string.IsNullOrEmpty(viewModel.Description))
            {
                imageBuilder.AddDescription(viewModel.Description);
            }
            if (viewModel.ResizePercentage < 1)
            {
                imageBuilder.Resize(viewModel.ResizePercentage);
            }

            if (viewModel.ClearExifData)
            {
                imageBuilder.RemoveExifData();
            }

            using (var imageModel = imageBuilder.Build())
            {
                if (_authService.IsImageSizeOverUserLimit(imageModel.ImageSize, User))
                {
                    ViewBag.Error =
                        "There is not enough room left in your personal repository to fit an image of this size.";
                    return(View("ImageUpload", viewModel));
                }


                imageModel.WriteToLocalFilePath();
                var imageId = _imageRepository.CreateNewImage(imageModel);
                return(RedirectToAction("Details", new { id = imageId }));
            }
        }
Exemplo n.º 21
0
        public ActionResult Upload()
        {
            var model = new ImageUploadViewModel();

            _commonHelper    = new Helpers.CommonHelper();
            model.ImageTypes = _commonHelper.GetImageTypes();
            _commonHelper    = null;
            return(View(model));
        }
Exemplo n.º 22
0
        public IActionResult CreateCategory(ImageUploadViewModel vm)
        {
            var NewCategory = new Category();

            NewCategory.Name = vm.CategoryName;

            ctx.Categories.Add(NewCategory);
            ctx.SaveChangesAsync();
            return(RedirectToAction("upload", "Home"));
        }
        public async Task <IActionResult> Upload(ImageUploadViewModel viewModel)
        {
            if (viewModel.Image?.Length > 0)
            {
                await _channel.Write(viewModel.Image);

                viewModel.Image       = null;
                viewModel.UploadStage = UploadStage.Completed;
            }

            return(View(viewModel));
        }
Exemplo n.º 24
0
        public ActionResult UploadFile(string name, string phone, string email, string member)
        {
            ImageUploadViewModel model = new ImageUploadViewModel
            {
                CustomerName    = name,
                Telephone       = phone,
                EmailAddress    = email,
                RemainingImages = 0,
                Member          = int.Parse(member) == 2
            };

            return(PartialView("_FormDesign", model));
        }
Exemplo n.º 25
0
        public async Task <IActionResult> Upload(ImageUploadViewModel viewModel)
        {
            if (viewModel.Image.Length > 0)
            {
                //_client.UploadImage(viewModel.Image);
                await _processingChannel.Set(viewModel.Image);

                viewModel.UploadStage = UploadStage.Completed;
                viewModel.Image       = null;
            }

            return(View(viewModel));
        }
Exemplo n.º 26
0
        public ActionResult UploadQPic(int QId)
        {
            var ImageUploadViewModel = new ImageUploadViewModel();

            ViewBag.UserId = User.Identity.GetUserId();
            var ImageUploads = db.ImageUploads.Where(i => i.QId == QId).ToList().OrderByDescending(c => c.Created);

            ImageUploads.ToList();
            //ViewBag.LastUpload = ImageUploads[0];



            return(View(ImageUploadViewModel));
        }
Exemplo n.º 27
0
        public ActionResult UploadTemp(string id)
        {
            string fileName = null;
            ImageUploadViewModel imageUploadViewModel = null;

            try
            {
                foreach (string file in Request.Files)
                {
                    var fileContent = Request.Files[file];
                    if (fileContent != null && fileContent.ContentLength > 0)
                    {
                        // get a stream
                        using (var stream = fileContent.InputStream)
                        {
                            // and optionally write the file to disk
                            fileName = fileContent.FileName;//Path.GetExtension(file);
                            string filePath = Server.MapPath("~/temp/");
                            if ((System.IO.File.Exists(filePath + fileName)))
                            {
                                System.IO.File.Delete(filePath + fileName);
                            }
                            ViewBag.fileName = fileName;
                            var path = Path.Combine(Server.MapPath("~/temp/"), fileName);
                            using (var fileStream = System.IO.File.Create(path))
                            {
                                stream.CopyTo(fileStream);
                            }
                            imageUploadViewModel = new ImageUploadViewModel
                            {
                                Id   = Convert.ToInt32(id),
                                Name = fileName
                            };

                            deleteTempImg(fileName);
                        }
                    }
                }
            }
            catch (Exception)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
            }
            //if (id == "0")
            //    return PartialView("_UploadMainImageTemp", imageUploadViewModel);
            //else
            //    return PartialView("_UploadImageTemp", imageUploadViewModel);
            return(Content(fileName));
        }
Exemplo n.º 28
0
        public ImageUploadViewModel UpFileBaseForCKFrondEnd(HttpPostedFileBase Request)
        {
            HttpPostedFileBase   desimg    = Request;
            ImageUploadViewModel imgUpload = new ImageUploadViewModel();
            string coderandom  = "botogiasi";
            var    _Filename   = Path.GetFileName(desimg.FileName);
            string _ServerPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConstantSystem.FolderFrontEnd);
            string _NameRandom = coderandom + _Filename;
            var    path        = Path.Combine(_ServerPath, _NameRandom);

            desimg.SaveAs(path);
            imgUpload.ImageName = _NameRandom;
            imgUpload.ImageUrl  = ConstantSystem.FolderFrontEnd + "/" + _NameRandom;
            return(imgUpload);
        }
Exemplo n.º 29
0
        public ActionResult Upload(ImageUploadViewModel formData, int?id)
        {
            //Get File and Create Path
            var    uploadedFile = Request.Files[0];
            string filename     = $"{DateTime.Now.Ticks}{uploadedFile.FileName}";
            var    serverPath   = Server.MapPath(@"~\Uploads");
            var    fullPath     = Path.Combine(serverPath, filename);

            //Resize Image
            //WebImage img = new WebImage(uploadedFile.InputStream);
            //if (img.Width > 1000)
            //    img.Resize(1000, 1000);

            //Save Image
            uploadedFile.SaveAs(fullPath);

            var userId = User.Identity.GetUserId();
            int qId    = 0;

            //Get Question Id if not provided
            if (id == null)
            {
                qId = db.Questions
                      .Where(q => q.OwnerId == userId)
                      .OrderByDescending(q => q.Created)
                      .Select(q => q.Id)
                      .FirstOrDefault();
            }
            else
            {
                qId = (int)id;
            }

            //Create ImgUpload Entry
            var uploadModel = new ImgUpload
            {
                Caption = formData.Caption,
                File    = filename,
                OwnerId = User.Identity.GetUserId(),
                RefId   = qId,
                TypeRef = "QAttach",
            };

            db.ImgUploads.Add(uploadModel);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 30
0
        public ImageUploadViewModel UploadHttpPostedFileBaseForCK(HttpPostedFileBase Request)
        {
            HttpPostedFileBase   desimg    = Request;
            ImageUploadViewModel imgUpload = new ImageUploadViewModel();
            string coderandom = DateTime.UtcNow.Ticks.ToString();

            coderandom = ConstantSystem.PrefixImageName + coderandom;
            var    _Filename   = Path.GetFileName(desimg.FileName);
            string _ServerPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConstantSystem.FolderImage);
            string _NameRandom = coderandom + _Filename;
            var    path        = Path.Combine(_ServerPath, _NameRandom);

            desimg.SaveAs(path);
            imgUpload.ImageName = _NameRandom;
            imgUpload.ImageUrl  = ConstantSystem.FolderImage + "/" + _NameRandom;
            return(imgUpload);
        }