Example #1
0
        public static MemberAvatarView GetViewMemberIcon(this MemberAvatar memberAvatar, IMapper _mapper, int memberId)
        {
            var memberView = new MemberAvatarView();

            if (memberAvatar != null)
            {
                memberView            = _mapper.Map <MemberAvatar, MemberAvatarView>(memberAvatar);
                memberView.AvatarFile = memberAvatar.ThumbnailFile;
            }
            else
            {
                memberView = GetViewEmptyMemberAvatar(memberId);
            }

            return(memberView);
        }
        private byte[] GetImage(string memberUId)
        {
            if (String.IsNullOrEmpty(memberUId))
            {
                return(GetNullImage());
            }

            if (TeamService == null)
            {
                return(GetDefaultImage());
            }

            MemberProfile member = TeamService.GetMember(memberUId);

            if (member == null)
            {
                return(GetDefaultImage());
            }

            if (member.IsContactMember)
            {
                return(GetContactImage());
            }

            MemberAvatar avatar = TeamService.GetMemberAvatar(memberUId);

            if (avatar != null)
            {
                return(avatar.AvatarImage);
            }

            byte[] gravatar = GetGravatarImage(member.EmailAccount);
            if (gravatar.Length != 0)
            {
                return(gravatar);
            }

            return(GetDefaultImage(member));
        }
Example #3
0
 private void SaveAvatarToFileSystem(MemberAvatar avatar)
 {
     SaveAvatarToFileSystem(avatar.AvatarFileName, iconFile: avatar.ThumbnailFile, avatarFile: avatar.AvatarFile);
 }
Example #4
0
        public MemberAvatarView SetUpdateMemberAvatar(IFormFile uploadedFile)
        {
            var user = Uow.UserRepository.LinkedCacheGetByName(InpersonatedUserName);

            if (user == null || !user.IsActive)
            {
                throw new CoralTimeEntityNotFoundException($"The user with userName {InpersonatedUserName} not found or is not active");
            }

            var member = Uow.MemberRepository.LinkedCacheGetByName(InpersonatedUserName);

            if (member == null)
            {
                throw new CoralTimeEntityNotFoundException($"The member for user with userName {InpersonatedUserName} not found");
            }

            if (!CheckFile(uploadedFile.FileName, uploadedFile.Length, out var errors))
            {
                throw new CoralTimeForbiddenException(errors ?? "File size is greater than 1 Mb");
            }

            byte[] imageData;

            using (var binaryReader = new BinaryReader(uploadedFile.OpenReadStream()))
            {
                imageData = binaryReader.ReadBytes((int)uploadedFile.Length);
            }

            var image = Image.FromStream(new MemoryStream(imageData));

            image = image.GetThumbnailImage(40, 40, () => false, IntPtr.Zero);

            byte[] thumbnaiImage;

            using (var memoryStream = new MemoryStream())
            {
                image.Save(memoryStream, ImageFormat.Jpeg);
                thumbnaiImage = memoryStream.ToArray();
            }

            var isInsertCurrentAvatar = false;

            var memberAvatar = Uow.MemberAvatarRepository.GetQueryWithoutIncludes().FirstOrDefault(p => p.MemberId == member.Id);

            if (memberAvatar == null)
            {
                memberAvatar          = new MemberAvatar();
                isInsertCurrentAvatar = true;
            }
            var newAvatarFileName = $"{(Guid.NewGuid().ToString().Replace("-", string.Empty))}{Path.GetExtension(uploadedFile.FileName)}";

            memberAvatar.MemberId       = member.Id;
            memberAvatar.AvatarFile     = imageData;
            memberAvatar.AvatarFileName = newAvatarFileName;
            memberAvatar.ThumbnailFile  = thumbnaiImage;

            try
            {
                if (isInsertCurrentAvatar)
                {
                    Uow.MemberAvatarRepository.Insert(memberAvatar);
                }
                else
                {
                    Uow.MemberAvatarRepository.Update(memberAvatar);
                }

                Uow.Save();
                Uow.MemberAvatarRepository.LinkedCacheClear();

                SaveAvatarToFileSystem(memberAvatar);
            }
            catch (Exception e)
            {
                throw new CoralTimeDangerException("An error occurred while updating member avatar", e);
            }

            return(CreateAvaterMemberAvatarView(memberAvatar.AvatarFileName, member.Id));
        }
Example #5
0
        public MemberAvatarView SetUpdateMemberAvatar(IFormFile uploadedFile, string userName)
        {
            var user = Uow.UserRepository.LinkedCacheGetByName(userName);

            if (user == null || !user.IsActive)
            {
                throw new CoralTimeEntityNotFoundException($"The user with userName {userName} not found or is not active");
            }

            var member = Uow.MemberRepository.LinkedCacheGetByName(userName);

            if (member == null)
            {
                throw new CoralTimeEntityNotFoundException($"The member for user with userName {userName} not found");
            }

            if (!CheckFile(uploadedFile.FileName, uploadedFile.Length, out var errors))
            {
                throw new CoralTimeForbiddenException(errors ?? "File size is greater than 1 Mb");
            }

            byte[] imageData;

            using (var binaryReader = new BinaryReader(uploadedFile.OpenReadStream()))
            {
                imageData = binaryReader.ReadBytes((int)uploadedFile.Length);
            }

            var image = Image.FromStream(new MemoryStream(imageData));

            image = image.GetThumbnailImage(40, 40, () => false, IntPtr.Zero);

            byte[] thumbnaiImage;

            using (var memoryStream = new MemoryStream())
            {
                image.Save(memoryStream, ImageFormat.Jpeg);
                thumbnaiImage = memoryStream.ToArray();
            }

            var isInsertCurrentAvatar = false;

            var memberAvatar = Uow.MemberAvatarRepository.LinkedCacheGetList().FirstOrDefault(p => p.MemberId == member.Id);

            if (memberAvatar == null)
            {
                memberAvatar          = new MemberAvatar();
                isInsertCurrentAvatar = true;
            }

            memberAvatar.MemberId       = member.Id;
            memberAvatar.AvatarFile     = imageData;
            memberAvatar.AvatarFileName = uploadedFile.FileName;
            memberAvatar.ThumbnailFile  = thumbnaiImage;

            try
            {
                if (isInsertCurrentAvatar)
                {
                    Uow.MemberAvatarRepository.Insert(memberAvatar);
                }
                else
                {
                    Uow.MemberAvatarRepository.Update(memberAvatar);
                }

                Uow.Save();
                Uow.MemberAvatarRepository.LinkedCacheClear();
            }
            catch (Exception e)
            {
                throw new CoralTimeDangerException("An error occurred while updating member avatar", e);
            }

            var memberAvatarByIdResult = Uow.MemberAvatarRepository.LinkedCacheGetList()
                                         .FirstOrDefault(p => p.Id == memberAvatar.Id);

            return(memberAvatarByIdResult.GetViewMemberIcon(Mapper, member.Id));
        }
        private void ChangeMemberImage()
        {
            Byte[] imageBytes = GetMemberImageAsBytes();
            if (imageBytes == null)
                return;

            MemberAvatar avatar = new MemberAvatar();
            avatar.MemberUId = MemberProfile.MemberUId;
            avatar.AvatarImage = imageBytes;

            executor.StartBackgroundTask(
                () => { teamService.UpdateMemberAvatar(MemberProfile.MemberUId, avatar); },
                () => {
                    myProfileNocache = new Random().Next().ToString();
                    DefineMemberAvatarUrl();
                });
        }
 public void UpdateMemberAvatar(string memberUId, MemberAvatar avatar)
 {
     var client = ClientHelper.GetClient(authorizationService);
     HttpResponseMessage response = client.Put(Url("Members/" + SafeMemberUId(memberUId) + "/Avatar"), new ObjectContent<MemberAvatar>(avatar, JsonValueMediaTypeFormatter.DefaultMediaType));
     ClientHelper.HandleHTTPErrorCode(response);
 }
Example #8
0
 public void UpdateMemberAvatar(string memberUId, MemberAvatar avatar)
 {
     authorizationService.VerifyUser(SafeMemberUId(memberUId));
     teamRepository.SaveMemberAvatar(avatar);
 }
Example #9
0
 public void UpdateMemberAvatar(string memberUId, MemberAvatar avatar)
 {
     authorizationService.VerifyUser(SafeMemberUId(memberUId));
     teamRepository.SaveMemberAvatar(avatar);
 }
        public void SaveMemberAvatar(MemberAvatar avatar)
        {
            using (var context = new ScrumFactoryEntities(this.connectionString)) {
                MemberProfile oldMember = GetMember(avatar.MemberUId);

                MemberAvatar oldAvatar = GetMemberAvatar(avatar.MemberUId);

                if (oldMember == null)
                    throw new System.Exception("member not found");

                if (oldAvatar == null) {
                    context.MembersAvatar.AddObject(avatar);
                } else {
                    context.AttachTo("MembersAvatar", oldAvatar);
                    context.ApplyCurrentValues<MemberAvatar>("MembersAvatar", avatar);
                }

                context.SaveChanges();

            }
        }