Esempio n. 1
0
        /// <summary>
        /// Creates an image.
        /// </summary>
        /// <param name="model">The upload to create.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        /// <returns>Image populated with newly allocated upload identifier.</returns>
        private Image CreateImage(CreateUploadModel model, IUnitOfWork unitOfWork)
        {
            // Validate create upload model
            Drawing.Size?size = _uploadValidator.ValidateCreateImage(model);

            // Construct image object
            DateTime now   = DateTime.UtcNow;
            Image    image = new Image
            {
                TenantId    = model.TenantId,
                Created     = now,
                Updated     = now,
                Name        = model.Name.Trim(),
                Content     = model.Content,
                ContentType = model.ContentType.Trim().ToLower(),
                Size        = model.Content.Length,
                UploadType  = UploadType.Image,
                Committed   = false,
                Width       = size.Value.Width,
                Height      = size.Value.Height
            };

            // Create image and record newly allocated upload identifier
            image.UploadId = _uploadRepository.CreateImage(image, unitOfWork);

            // Return image object
            return(image);
        }