Beispiel #1
0
        public SendImageResponse SendImage(ISession session, SendImageRequest request)
        {
            var response = request.CreateResponse <SendImageResponse>();

            response.ImageId = -1;

            if (session.User.IsDevoiced)
            {
                session.Send(new YouAreDevoicedNotification());
                return(response);
            }

            PublicMessage message = null;

            using (var uow = UnitOfWorkFactory.Create())
            {
                int fileId;
                try
                {
                    fileId           = _fileStorage.AppendFile(request.Image);
                    response.ImageId = fileId;
                }
                catch (System.Exception)
                {
                    //Invalid image
                    return(response);
                }
                uow.Attach(session.User);
                message = new PublicMessage(session.User, fileId, "Your client doesn't support IMAGE messages");
                uow.PublicMessageRepository.Add(message);
                uow.Commit();
            }

            var dto = message.ProjectedAs <PublicMessageDto>();

            dto.Role = (UserRoleEnum)(int)session.User.Role;
            _sessionManager.SendToEachChatSessions(dto);
            return(response);
        }
        public ChangePhotoResponse ChangePhoto(ISession session, ChangePhotoRequest request)
        {
            var response = request.CreateResponse <ChangePhotoResponse>();

            response.Success = true;
            int photoId = request.BuiltinPhotoId;

            if (!request.PhotoData.IsNullOrEmpty() && request.PhotoData.Length > 10)
            {
                try
                {
                    photoId = _fileStorage.AppendFile(request.PhotoData);
                }
                catch (Exception exc)
                {
                    photoId          = 0;
                    response.Success = false;
                }
            }
            response.PhotoId = photoId;

            if (response.Success)
            {
                using (var uow = UnitOfWorkFactory.Create())
                {
                    uow.Attach(session.User);
                    session.User.ChangePhoto(photoId);

                    uow.Commit();
                }
                _profileChangesNotificator.NotifyEverybodyInChatAboutProfileChanges(session.User.Id, new Dictionary <string, object> {
                    { "PhotoId", photoId }
                });
            }

            return(response);
        }