Beispiel #1
0
        public Operation <string> UpdateProfileImage(EncodedBinaryData image, string oldImageUrl)
        => _authorizer.AuthorizeAccess(UserContext.CurrentProcessPermissionProfile(), () =>
        {
            var user = UserContext.CurrentUser();

            var url = _blobStore.Delete(oldImageUrl) //shouldnt fail even if oldImageUrl is null
                      .Then(opr => _blobStore.Persist(image))
                      .Resolve();

            //create the ProfileImage UserData and store the url
            var userData = _query.GetUserData(user, Constants.UserData_ProfileImage) ?? new UserData
            {
                Name    = Constants.UserData_ProfileImage,
                OwnerId = user.UserId,
                Type    = CommonDataType.Url
            };

            //set the data
            userData.Data = url;

            if (userData.EntityId > 0)
            {
                return(_pcommand.Update(userData).Resolve().Data);
            }

            else
            {
                return(_pcommand.Add(userData).Resolve().Data);
            }
        });