Exemplo n.º 1
0
 /// <summary>
 /// Compute the thumbnail url for a particular log entry
 /// </summary>
 /// <param name="logEntry">The log entry whose thumbnail you want to compute
 /// Note: The collection navigation property "Images" needs to be set on this LogEntry instance
 /// </param>
 /// <returns>A string which is the thumbnail as a URL</returns>
 public string ComputeThumbnail(LogEntry logEntry)
 {
     if (logEntry.Images.Count() == 0)
     {
         // if this gallery entry has no images defined, return a random stock photo
         return("/images/no-image.png");
         // return "https://unsplash.it/g/200/300/?random";
     }
     else
     {
         // get first related entry in the associative many2many table
         LogEntry_Image firstImage = logEntry.Images.First();
         return(firstImage.Image.Url);
     }
 }
Exemplo n.º 2
0
        public async Task <IActionResult> ProcessEntry(List <IFormFile> files, LogEntry logEntry)
        {
            ApplicationUser currentUser = await _userManager.GetUserAsync(User);

            if (currentUser == null)
            {
                return(Redirect(ANON_REDIRECT_URL));
            }

            long size = files.Sum(f => f.Length);

            logEntry.ApplicationUser = await _userManager.GetUserAsync(User);

            if (logEntry.DateTimeCreated.Year == 1)
            {
                logEntry.DateTimeCreated = DateTime.Now;
            }

            _sparkClipsContext.LogEntries.Add(logEntry);
            _sparkClipsContext.SaveChanges();

            foreach (FormFile formFile in files)
            {
                if (formFile.Length > 0)
                {
                    Image image = await _fileStorage.UploadImage(ContainerName.Log, formFile);

                    _sparkClipsContext.Images.Add(image);
                    _sparkClipsContext.SaveChanges();

                    LogEntry_Image associative_entity = new LogEntry_Image {
                        LogEntryID = logEntry.LogEntryID,
                        ImageID    = image.ImageID
                    };
                    _sparkClipsContext.LogEntry_Image.Add(associative_entity);
                    _sparkClipsContext.SaveChanges();
                }
            }

            // process uploaded files
            // Don't rely on or trust the FileName property without validation.

            return(RedirectToAction("Index"));
        }