コード例 #1
0
        /// <summary>
        /// Resets user's photo to default one
        /// </summary>
        public ResetPhotoResponse ResetPhoto(ISession session, ResetPhotoRequest request)
        {
            var response = request.CreateResponse <ResetPhotoResponse>();

            try
            {
                using (var uow = UnitOfWorkFactory.Create())
                {
                    var target = uow.UsersRepository.FirstMatching(UserSpecification.Id(request.TargetId));
                    if (target != null)
                    {
                        response.NewPhotoId = target.ResetPhoto(session.User);
                        uow.Commit();
                        response.Success = true;
                    }
                }
            }
            catch (ModeratorsRightsRequiredException)
            {
                response.Success = false;
            }
            if (response.Success)
            {
                _profileChangesNotificator.NotifyEverybodyInChatAboutProfileChanges(request.TargetId, new Dictionary <string, object> {
                    { "PhotoId", response.NewPhotoId }
                });
            }
            return(response);
        }
コード例 #2
0
        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);
        }