public async Task <IActionResult> AddPictures(GalleryPicturesViewModel model)
        {
            var noPicturesSelected = model.Pictures == null || !model.Pictures.Any();

            if (noPicturesSelected)
            {
                ModelState.AddModelError(nameof(model.Pictures), "You have to select at least one picture.");
            }

            if (!noPicturesSelected && model.Pictures.ToList().Any(f => !AllowedFileExtensions.Contains(f.ContentType)))
            {
                ModelState.AddModelError(nameof(model.Pictures), "Only jpg and jpeg image files allowed.");
            }

            if (!noPicturesSelected && model.Pictures.ToList().Any(f => f.Length == 0 || f.Length > ImageFileMaxLength))
            {
                ModelState.AddModelError(nameof(model.Pictures), $"Image cannot be bigger than {(ImageFileMaxLength / 1024) / 1000:D} MB.");
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var skippedPictures = await StorePictures(model.Pictures, model.GalleryId);

            return(View(model));
        }
예제 #2
0
 private void EnumerateDirectory(string path, bool addToHistory = true)
 {
     if (FileService != null)
     {
         if (addToHistory)
         {
             previousFolders.Push(CurrentFolder);
         }
         CurrentFolder = new FolderItem(path);
         var items = FileService.GetStorageItems(path);
         StorageItems.Clear();
         StorageItems.AddRange(items.OfType <FolderItem>());
         var files = items.OfType <FileItem>()
                     .Where(x => AllowedFileExtensions.Count == 0 || AllowedFileExtensions.Contains(x.Extension));
         StorageItems.AddRange(files);
     }
 }
        /// <summary>
        /// Called when a document is getting closed
        /// </summary>
        /// <param name="document">The document that is getting closed</param>
        private void OnDocumentClosing(Document document)
        {
            if (document == null)
            {
                return;
            }

            Log.WriteLine(LogLevel.Debug, $"{nameof(OnDocumentClosing)}(Document: {document.Name})");

            string extension = Path.GetExtension(document.FullName);

            if (!AllowedFileExtensions.Contains(extension))
            {
                return;
            }

            _documentsToReformat.Remove(document);
        }
        /// <summary>
        /// Called when a document is saved
        /// </summary>
        /// <param name="document">The document that is saved</param>
        private void OnDocumentSaved(Document document)
        {
            Log.WriteLine(LogLevel.Debug, $"{nameof(OnDocumentSaved)}(Document: {document.Name})");

            if (IsReformatting || BuildingSolution > 0)
            {
                return;
            }

            string extension = Path.GetExtension(document.FullName);

            if (!AllowedFileExtensions.Contains(extension))
            {
                return;
            }

            _documentsToReformat[document] = DateTime.Now;
        }