/// <summary>
        /// Add photos to employee
        /// </summary>
        /// <param name="employeeId">Employee identifier</param>
        /// <param name="photos">Employee photo</param>
        public Model.EmployeePhotoExecutionResults EmployeePhotosAdd(long employeeId, Model.EmployeePhoto[] photos)
        {
            UpdateSessionCulture();
            using (var logSession = Helpers.Log.Session($"{GetType()}.{System.Reflection.MethodBase.GetCurrentMethod().Name}()", VerboseLog, RaiseLog))
                try
                {
                    var emp = EmployeeGet(employeeId);
                    if (emp.Exception != null)
                        throw emp.Exception;

                    using (var rep = GetNewRepository(logSession))
                    {
                        var empphs = photos.Select(p => new Repository.Model.EmployeePhoto()
                        {
                            EmployeeId = employeeId,
                            FileId = p.FileId,
                        });
                        rep.AddRange(empphs);
                    }

                    return EmployeePhotosGet(employeeId);
                }
                catch (Exception ex)
                {
                    ex.Data.Add(nameof(employeeId), employeeId);
                    ex.Data.Add(nameof(photos), photos.Concat(p => p.ToString(),", "));
                    logSession.Enabled = true;
                    logSession.Add(ex);
                    return new EmployeePhotoExecutionResults(ex);
                }
        }
Example #2
0
        public static IEnumerable<Model.Picture> RersizeTo(Repository.Model.File fromFile,
            Repository.Logic.Repository repository,
            IFileStorage storage,
            Model.PictureType[] toType)
        {
            if (fromFile == null)
                throw new ArgumentNullException(nameof(fromFile));
            if (repository == null)
                throw new ArgumentNullException(nameof(repository));
            if (storage == null)
                throw new ArgumentNullException(nameof(storage));

            toType = toType
                ?? typeof(Model.PictureType)
                .GetEnumValues()
                .Cast<Model.PictureType>()
                .ToArray();

            var toSizes = toType
                .Select(i => new { PictureType = i, Size = GetSize(i) })
                .Where(i => i.Size != null)
                .ToArray();

            if (toSizes.Any())
                using (var fileStream = storage.FileGet(fromFile.FileId))
                using (var originalImage = Bitmap.FromStream(fileStream))
                {
                    var pictures = toSizes.Select(t =>
                    {
                        var newWidth = (t.Size.Width == 0) ? originalImage.Width : t.Size.Width;
                        var newHeight = (t.Size.Height == 0) ? originalImage.Height : t.Size.Height;

                        using (var resizedbitmap = ResizeBitmap(originalImage, newWidth, newHeight))
                        using (var newPictureStream = new MemoryStream())
                        {
                            resizedbitmap.Save(newPictureStream, originalImage.RawFormat);
                            newPictureStream.Seek(0, SeekOrigin.Begin);

                            var dbFile = repository.FilePut(storage, newPictureStream, t.PictureType.ToString() + fromFile.FileName);
                            var picture = repository.New<Repository.Model.Picture>();
                            picture.File = dbFile;
                            picture.FileId = dbFile.FileId;
                            picture.Height = newWidth;
                            picture.Width = newHeight;
                            picture.PictureType = (Repository.Model.PictureType)(int)t.PictureType;
                            repository.Add(picture);
                            return AutoMapper.Mapper.Map<Model.Picture>(picture);
                        }
                    }).ToArray();
                    return pictures;
                }
            return Enumerable.Empty<Model.Picture>();
        }
 public JobActivityGroupViewModel(JobContainerViewModel container, ActivityInfo activityInfo, Model.ImageDownloader[] imageDownloader)
 {
     NoticeText = activityInfo.PostUser.Name;
     NoticeIcon = new System.Windows.Media.Imaging.BitmapImage();
     NoticeIcon.BeginInit();
     NoticeIcon.DecodePixelWidth = 25;
     NoticeIcon.UriSource = activityInfo.PostUser.IconImageUrl;
     NoticeIcon.EndInit();
     ActivityUrl = activityInfo.PostUrl;
     DownloadImageJobs = imageDownloader.Select(
         downloader => (JobViewModelBase)new JobViewModel(container, downloader)).ToList();
 }